diff --git a/trigonometric/bounding-box.c b/trigonometric/bounding-box.c index f97b7c5..93c595e 100644 --- a/trigonometric/bounding-box.c +++ b/trigonometric/bounding-box.c @@ -56,3 +56,26 @@ void bounding_box_calculate_polygon(GList *vertices, conv_generic_to_vector_2d_t box->vectors.upper_right.x = xmax; box->vectors.upper_right.y = ymax; } + +void bounding_box_update_box(union bounding_box *destination, union bounding_box *update) +{ + if (!destination || !update) + return; + + destination->vectors.lower_left.x = MIN(destination->vectors.lower_left.x, + update->vectors.lower_left.x); + destination->vectors.lower_left.y = MIN(destination->vectors.lower_left.y, + update->vectors.lower_left.y); + destination->vectors.upper_right.x = MAX(destination->vectors.upper_right.x, + update->vectors.upper_right.x); + destination->vectors.upper_right.y = MAX(destination->vectors.upper_right.y, + update->vectors.upper_right.y); +} + +void bounding_box_prepare_empty(union bounding_box *box) +{ + box->vectors.lower_left.x = DBL_MAX; + box->vectors.lower_left.y = DBL_MAX; + box->vectors.upper_right.x = DBL_MIN; + box->vectors.upper_right.y = DBL_MIN; +} diff --git a/trigonometric/bounding-box.h b/trigonometric/bounding-box.h index 7712cd5..33e7d39 100644 --- a/trigonometric/bounding-box.h +++ b/trigonometric/bounding-box.h @@ -39,5 +39,7 @@ union bounding_box { typedef void (*conv_generic_to_vector_2d_t)(void *, struct vector_2d *); void bounding_box_calculate_polygon(GList *vertices, conv_generic_to_vector_2d_t conv_func, union bounding_box *box); +void bounding_box_update_box(union bounding_box *destination, union bounding_box *update); +void bounding_box_prepare_empty(union bounding_box *box); #endif /* _BOUNDING_BOX_H_ */