Skip to content

Commit 0d3e653

Browse files
committed
tests: Add more coverage for box2d
Check that rectangles roundtrip between 2D boxes, and that the transformation works.
1 parent 3f3467c commit 0d3e653

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/box2d.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,30 @@ box2d_init_from_vectors (mutest_spec_t *spec)
165165
free (vectors);
166166
}
167167

168+
static void
169+
box2d_init_from_rect (mutest_spec_t *spec)
170+
{
171+
graphene_box2d_t a, b;
172+
graphene_rect_t r, check;
173+
174+
graphene_box2d_init_from_box (&a, graphene_box2d_one_minus_one ());
175+
graphene_box2d_to_rect (&a, &r);
176+
177+
graphene_rect_init (&check, -1.f, -1.f, 2.f, 2.f);
178+
179+
mutest_expect ("to_rect() to generate a valid rectangle",
180+
mutest_bool_value (graphene_rect_equal (&r, &check)),
181+
mutest_to_be_true,
182+
NULL);
183+
184+
graphene_box2d_init_from_rect (&b, &r);
185+
186+
mutest_expect ("init_from_rect() to generate a valid box",
187+
mutest_bool_value (graphene_box2d_equal (&b, &a)),
188+
mutest_to_be_true,
189+
NULL);
190+
}
191+
168192
static void
169193
box2d_size (mutest_spec_t *spec)
170194
{
@@ -517,12 +541,37 @@ box2d_contains_box (mutest_spec_t *spec)
517541
NULL);
518542
}
519543

544+
static void
545+
box2d_linear_transform (void)
546+
{
547+
graphene_box2d_t a, res;
548+
graphene_vec2_t tmp;
549+
550+
graphene_box2d_init_from_box (&a, graphene_box2d_one ());
551+
graphene_box2d_scale_offset (&a,
552+
graphene_vec2_init (&tmp, 2.f, 2.f),
553+
&GRAPHENE_POINT_INIT (1.f, 2.f),
554+
&res);
555+
556+
graphene_rect_t r, check;
557+
graphene_rect_init (&check, 0.f, 0.f, 1.f, 1.f);
558+
graphene_rect_scale (&check, 2.f, 2.f, &check);
559+
graphene_rect_offset_r (&check, 1.f, 2.f, &check);
560+
561+
graphene_box2d_to_rect (&res, &r);
562+
mutest_expect ("scaled and offset box to match equivalent rectangle",
563+
mutest_bool_value (graphene_rect_equal (&r, &check)),
564+
mutest_to_be_true,
565+
NULL);
566+
}
567+
520568
static void
521569
box2d_suite (mutest_suite_t *suite)
522570
{
523571
mutest_it ("initializes min/max points", box2d_init_min_max);
524572
mutest_it ("initializes from points", box2d_init_from_points);
525573
mutest_it ("initializes from vectors", box2d_init_from_vectors);
574+
mutest_it ("roundtrips between rect", box2d_init_from_rect);
526575
mutest_it ("has the correct sizes", box2d_size);
527576
mutest_it ("has the correct center point", box2d_center);
528577
mutest_it ("has equality", box2d_equal);
@@ -533,6 +582,7 @@ box2d_suite (mutest_suite_t *suite)
533582
mutest_it ("expands by scalar", box2d_expand_by_scalar);
534583
mutest_it ("contains point", box2d_contains_point);
535584
mutest_it ("contains box", box2d_contains_box);
585+
mutest_it ("transforms linearly", box2d_linear_transform);
536586
}
537587

538588
MUTEST_MAIN (

0 commit comments

Comments
 (0)