@@ -400,6 +400,132 @@ def test_find_intersection_parallel_overlap_compeletely(self):
400
400
False , True , line2 .Line2 (vector2 .Vector2 (3 , 4 ), vector2 .Vector2 (5 , 6 )))
401
401
402
402
403
+ class TestAxisAlignedLine (unittest .TestCase ):
404
+ def setUp (self ):
405
+ self .vec_1_1 = vector2 .Vector2 (1 , 1 )
406
+
407
+ def test_constructor (self ):
408
+ _aal = axisall .AxisAlignedLine (self .vec_1_1 , 0 , 1 )
409
+
410
+ self .assertIsNotNone (_aal .axis )
411
+ self .assertIsNotNone (_aal .min )
412
+ self .assertIsNotNone (_aal .max )
413
+
414
+ self .assertEqual (1 , _aal .axis .start .x )
415
+ self .assertEqual (1 , _aal .axis .start .y )
416
+ self .assertEqual (0 , _aal .min )
417
+ self .assertEqual (1 , _aal .max )
418
+
419
+ _aal2 = axisall .AxisAlignedLine (self .vec_1_1 , 1 , 0 )
420
+
421
+ self .assertEqual (0 , _aal .min )
422
+ self .assertEqual (1 , _aal .max )
423
+
424
+ def test_intersects_false (self ):
425
+ _aal1 = axisall .AxisAlignedLine (self .vec_1_1 , 0 , 1 )
426
+ _aal2 = axisall .AxisAlignedLine (self .vec_1_1 , 2 , 3 )
427
+
428
+ touching , overlapping = axisall .AxisAlignedLine .intersects (_aal1 , _aal2 )
429
+ self .assertFalse (touching )
430
+ self .assertFalse (overlapping )
431
+
432
+ touching , overlapping = axisall .AxisAlignedLine .intersects (_aal2 , _aal1 )
433
+ self .assertFalse (touching )
434
+ self .assertFalse (overlapping )
435
+
436
+ def test_intersects_touching (self ):
437
+ _aal1 = axisall .AxisAlignedLine (self .vec_1_1 , 0 , 1 )
438
+ _aal2 = axisall .AxisAlignedLine (self .vec_1_1 , 1 , 2 )
439
+
440
+ touching , overlapping = axisall .AxisAlignedLine .intersects (_aal1 , _aal2 )
441
+ self .assertTrue (touching )
442
+ self .assertFalse (overlapping )
443
+
444
+ touching , overlapping = axisall .AxisAlignedLine .intersects (_aal2 , _aal1 )
445
+ self .assertTrue (touching )
446
+ self .assertFalse (overlapping )
447
+
448
+ def test_intersects_overlapping (self ):
449
+ _aal1 = axisall .AxisAlignedLine (self .vec_1_1 , - 1 , - 3 )
450
+ _aal2 = axisall .AxisAlignedLine (self .vec_1_1 , - 2 , 5 )
451
+
452
+ touching , overlapping = axisall .AxisAlignedLine .intersects (_aal1 , _aal2 )
453
+ self .assertFalse (touching )
454
+ self .assertTrue (overlapping )
455
+
456
+ touching , overlapping = axisall .AxisAlignedLine .intersects (_aal2 , _aal1 )
457
+ self .assertFalse (touching )
458
+ self .assertTrue (overlapping )
459
+
460
+
461
+ def test_find_intersection_false (self ):
462
+ _aal1 = axisall .AxisAlignedLine (self .vec_1_1 , 0 , 1 )
463
+ _aal2 = axisall .AxisAlignedLine (self .vec_1_1 , 2 , 3 )
464
+
465
+ touching , mtv = axisall .AxisAlignedLine .find_intersection (_aal1 , _aal2 )
466
+ self .assertFalse (touching )
467
+ self .assertIsNone (mtv )
468
+
469
+ touching , mtv = axisall .AxisAlignedLine .find_intersection (_aal2 , _aal1 )
470
+ self .assertFalse (touching )
471
+ self .assertIsNone (mtv )
472
+
473
+ def test_find_intersection_touching (self ):
474
+ _aal1 = axisall .AxisAlignedLine (self .vec_1_1 , 0 , 1 )
475
+ _aal2 = axisall .AxisAlignedLine (self .vec_1_1 , 1 , 2 )
476
+
477
+ touching , mtv = axisall .AxisAlignedLine .find_intersection (_aal1 , _aal2 )
478
+ self .assertTrue (touching )
479
+ self .assertIsNone (mtv )
480
+
481
+ touching , mtv = axisall .AxisAlignedLine .find_intersection (_aal2 , _aal1 )
482
+ self .assertTrue (touching )
483
+ self .assertIsNone (mtv )
484
+
485
+ def test_find_intersection_overlapping (self ):
486
+ _aal1 = axisall .AxisAlignedLine (self .vec_1_1 , - 3 , - 1 )
487
+ _aal2 = axisall .AxisAlignedLine (self .vec_1_1 , - 2 , 5 )
488
+
489
+ touching , mtv = axisall .AxisAlignedLine .find_intersection (_aal1 , _aal2 )
490
+ self .assertFalse (touching )
491
+ self .assertEquals (- 1 , mtv )
492
+
493
+ touching , mtv = axisall .AxisAlignedLine .find_intersection (_aal2 , _aal1 )
494
+ self .assertFalse (touching )
495
+ self .assertEquals (1 , mtv )
496
+
497
+ def test_contains_point_false (self ):
498
+ _aal1 = axisall .AxisAlignedLine (self .vec_1_1 , 0 , 1 )
499
+
500
+ outer , inner = axisall .AxisAlignedLine .contains_point (_aal1 , - 1 )
501
+ self .assertFalse (outer )
502
+ self .assertFalse (inner )
503
+
504
+ outer , inner = axisall .AxisAlignedLine .contains_point (_aal1 , 1.5 )
505
+ self .assertFalse (outer )
506
+ self .assertFalse (inner )
507
+
508
+ def test_contains_point_outer (self ):
509
+ _aal1 = axisall .AxisAlignedLine (self .vec_1_1 , 0 , 1 )
510
+
511
+ outer , inner = axisall .AxisAlignedLine .contains_point (_aal1 , 0 )
512
+ self .assertTrue (outer )
513
+ self .assertFalse (inner )
514
+
515
+ outer , inner = axisall .AxisAlignedLine .contains_point (_aal1 , 1 )
516
+ self .assertTrue (outer )
517
+ self .assertFalse (inner )
518
+
519
+ def test_contains_point_inner (self ):
520
+ _aal1 = axisall .AxisAlignedLine (self .vec_1_1 , 0 , 1 )
521
+
522
+ outer , inner = axisall .AxisAlignedLine .contains_point (_aal1 , 0.25 )
523
+ self .assertFalse (outer )
524
+ self .assertTrue (inner )
525
+
526
+ outer , inner = axisall .AxisAlignedLine .contains_point (_aal1 , 0.75 )
527
+ self .assertFalse (outer )
528
+ self .assertTrue (inner )
403
529
404
530
405
531
if __name__ == '__main__' :
0 commit comments