Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Box.get_minmax() #273

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading