From 74783f312a73c0c9e4218529df9bc5a92d34705b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Fri, 27 Jul 2018 21:08:45 +0200 Subject: [PATCH] bounding box functions added --- trigonometric/bounding-box.c | 23 +++++++++++++++++++++++ trigonometric/bounding-box.h | 2 ++ 2 files changed, 25 insertions(+) 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_ */