Skip to content

Commit

Permalink
Add Box.get_minmax()
Browse files Browse the repository at this point in the history
Similar to glibc's `sincos()`, it's easier to have a single call to
initialise both vertices at the same time.
  • Loading branch information
ebassi committed Aug 13, 2024
1 parent a4fa180 commit 74d9b6c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/graphene-sections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions include/graphene-box.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[]);
Expand Down
26 changes: 24 additions & 2 deletions src/graphene-box.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions tests/box.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 74d9b6c

Please sign in to comment.