From 74d9b6c1233c94a4369fca5626526ba940ff8dcc Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 13 Aug 2024 17:22:44 +0100 Subject: [PATCH] Add Box.get_minmax() Similar to glibc's `sincos()`, it's easier to have a single call to initialise both vertices at the same time. --- doc/graphene-sections.txt | 1 + include/graphene-box.h | 4 ++++ src/graphene-box.c | 26 ++++++++++++++++++++++++-- tests/box.c | 3 +-- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/doc/graphene-sections.txt b/doc/graphene-sections.txt index bb85ba62..253f6c05 100644 --- a/doc/graphene-sections.txt +++ b/doc/graphene-sections.txt @@ -14,6 +14,7 @@ graphene_box_expand_scalar graphene_box_expand_vec3 graphene_box_get_min graphene_box_get_max +graphene_box_get_minmax graphene_box_get_center graphene_box_get_depth graphene_box_get_height diff --git a/include/graphene-box.h b/include/graphene-box.h index d8605bd9..eebee064 100644 --- a/include/graphene-box.h +++ b/include/graphene-box.h @@ -113,6 +113,10 @@ void graphene_box_get_min (const graphene_ GRAPHENE_AVAILABLE_IN_1_2 void graphene_box_get_max (const graphene_box_t *box, graphene_point3d_t *max); +GRAPHENE_AVAILABLE_IN_1_12 +void graphene_box_get_minmax (const graphene_box_t *box, + graphene_point3d_t *min, + graphene_point3d_t *max); GRAPHENE_AVAILABLE_IN_1_2 void graphene_box_get_vertices (const graphene_box_t *box, graphene_vec3_t vertices[]); diff --git a/src/graphene-box.c b/src/graphene-box.c index 4fd4f12e..d9c6a98f 100644 --- a/src/graphene-box.c +++ b/src/graphene-box.c @@ -528,6 +528,28 @@ graphene_box_get_center (const graphene_box_t *box, graphene_point3d_init_from_vec3 (center, &res); } +/** + * graphene_box_get_minmax: + * @box: a #graphene_box_t + * @min: (out caller-allocates) (optional): return location for the minimum point + * @max: (out caller-allocates) (optional): return location for the maximum point + * + * Retrieves the coordinates of the minimum and maximum points of the + * given #graphene_box_t + * + * Since: 1.12 + */ +void +graphene_box_get_minmax (const graphene_box_t *box, + graphene_point3d_t *min, + graphene_point3d_t *max) +{ + if (min != NULL) + graphene_point3d_init_from_vec3 (min, &box->min); + if (max != NULL) + graphene_point3d_init_from_vec3 (max, &box->max); +} + /** * graphene_box_get_min: * @box: a #graphene_box_t @@ -542,7 +564,7 @@ void graphene_box_get_min (const graphene_box_t *box, graphene_point3d_t *min) { - graphene_point3d_init_from_vec3 (min, &box->min); + graphene_box_get_minmax (box, min, NULL); } /** @@ -559,7 +581,7 @@ void graphene_box_get_max (const graphene_box_t *box, graphene_point3d_t *max) { - graphene_point3d_init_from_vec3 (max, &box->max); + graphene_box_get_minmax (box, NULL, max); } /** diff --git a/tests/box.c b/tests/box.c index c104bafe..3ebf9d50 100644 --- a/tests/box.c +++ b/tests/box.c @@ -42,8 +42,7 @@ box_init_min_max (mutest_spec_t *spec) NULL); graphene_box_init_from_vec3 (b, graphene_vec3_zero (), graphene_vec3_one ()); - graphene_box_get_min (b, &min); - graphene_box_get_max (b, &max); + graphene_box_get_minmax (b, &min, &max); mutest_expect ("init_from_vec3(zero, one).min() maps to point3d(zero)", mutest_bool_value (graphene_point3d_equal (&min, &zero)), mutest_to_be_true,