@@ -165,6 +165,30 @@ box2d_init_from_vectors (mutest_spec_t *spec)
165
165
free (vectors );
166
166
}
167
167
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
+
168
192
static void
169
193
box2d_size (mutest_spec_t * spec )
170
194
{
@@ -517,12 +541,37 @@ box2d_contains_box (mutest_spec_t *spec)
517
541
NULL );
518
542
}
519
543
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
+
520
568
static void
521
569
box2d_suite (mutest_suite_t * suite )
522
570
{
523
571
mutest_it ("initializes min/max points" , box2d_init_min_max );
524
572
mutest_it ("initializes from points" , box2d_init_from_points );
525
573
mutest_it ("initializes from vectors" , box2d_init_from_vectors );
574
+ mutest_it ("roundtrips between rect" , box2d_init_from_rect );
526
575
mutest_it ("has the correct sizes" , box2d_size );
527
576
mutest_it ("has the correct center point" , box2d_center );
528
577
mutest_it ("has equality" , box2d_equal );
@@ -533,6 +582,7 @@ box2d_suite (mutest_suite_t *suite)
533
582
mutest_it ("expands by scalar" , box2d_expand_by_scalar );
534
583
mutest_it ("contains point" , box2d_contains_point );
535
584
mutest_it ("contains box" , box2d_contains_box );
585
+ mutest_it ("transforms linearly" , box2d_linear_transform );
536
586
}
537
587
538
588
MUTEST_MAIN (
0 commit comments