@@ -601,23 +601,6 @@ def separate(arb: p.Arbiter, space: p.Space, data: Any) -> None:
601
601
602
602
self .assertTrue (self .separated )
603
603
604
- def testCollisionHandlerRemoveSeparateAdd (self ) -> None :
605
- s = p .Space ()
606
- b1 = p .Body (1 , 10 )
607
- c1 = p .Circle (b1 , 10 )
608
- c2 = p .Circle (s .static_body , 5 )
609
-
610
- s .add (b1 , c1 , c2 )
611
-
612
- def separate (* _ : Any ) -> None :
613
- s .add (p .Circle (s .static_body , 2 ))
614
- s .remove (c1 )
615
-
616
- s .on_collision (separate = separate )
617
-
618
- s .step (1 )
619
- s .remove (c1 )
620
-
621
604
def testCollisionHandlerDefaultCallbacks (self ) -> None :
622
605
s = p .Space ()
623
606
@@ -644,79 +627,66 @@ def testCollisionHandlerDefaultCallbacks(self) -> None:
644
627
for _ in range (10 ):
645
628
s .step (0.1 )
646
629
647
- @unittest .skip ("Existing bug in Pymunk. TODO: Fix bug and enable test" )
648
- def testRemoveInSeparate (self ) -> None :
630
+ def testRemoveInSeparateWithinStep (self ) -> None :
649
631
s = p .Space ()
650
- print ("\n XXX start" )
651
632
652
633
shape1 = p .Circle (s .static_body , 1 )
653
634
shape1 .collision_type = 1
654
635
655
- body2 = p .Body ()
636
+ body2 = p .Body (1 , 1 )
656
637
shape2 = p .Circle (body2 , 1 )
657
- shape2 .density = 1
658
- # shape1.collision_type = 2
659
638
660
- body3 = p .Body ()
639
+ body3 = p .Body (1 , 1 )
661
640
shape3 = p .Circle (body3 , 1 )
662
- shape3 .density = 1
663
- # shape1.collision_type = 3
664
641
665
642
s .add (shape1 , shape2 , body2 , shape3 , body3 )
666
643
667
644
def remove1 (* _ : Any ) -> None :
668
- print ("remove1" )
669
645
s .remove (shape1 )
670
646
671
647
def remove2 (* _ : Any ) -> None :
672
- print ("remove2" )
673
648
s .remove (shape2 )
674
649
675
- # s.on_collision(1, 0).separate = remove2
676
- s .on_collision (1 , 0 , separate = remove1 )
677
-
678
- s .step (0.001 )
650
+ def remove3 (* _ : Any ) -> None :
651
+ s .remove (shape3 )
679
652
680
- # trigger separate with shape2 and shape3, shape1 will be removed 2x
681
- s .remove (shape1 )
682
-
683
- s .on_collision (1 , 0 , separate = remove2 )
684
- s .add (shape1 )
653
+ s .on_collision (separate = remove1 )
654
+ s .on_collision (1 , separate = remove2 )
655
+ s .on_collision (0 , 1 , separate = remove3 )
685
656
657
+ for _ in range (10 ):
686
658
s .step (1 )
687
- # trigger separate with shape2 and shape3, shape1 is removed, and shape2 will be removed
688
- s .remove (shape1 )
689
-
690
- # self.assertNotIn(shape1, s.shapes)
691
- # s.remove(shape1)
692
- # s.step(1)
693
-
694
- print (" XXX end" )
659
+ self .assertEqual (len (s .shapes ), 0 )
695
660
696
- @unittest .skip ("Existing bug in Pymunk. TODO: Fix bug and enable test" )
697
661
def testRemoveInSeparateWithoutStep (self ) -> None :
698
662
s = p .Space ()
699
- print ("\n XXX start" )
700
663
701
664
shape1 = p .Circle (s .static_body , 1 )
665
+ shape1 .collision_type = 1
702
666
703
- body2 = p .Body ()
667
+ body2 = p .Body (1 , 1 )
704
668
shape2 = p .Circle (body2 , 1 )
705
- shape2 .density = 1
706
669
707
- s .add (shape1 , shape2 , body2 )
670
+ body3 = p .Body (1 , 1 )
671
+ shape3 = p .Circle (body3 , 1 )
672
+
673
+ s .add (shape1 , shape2 , body2 , shape3 , body3 )
708
674
709
- def separate (* _ : Any ) -> None :
710
- pass
675
+ def remove2 (* _ : Any ) -> None :
676
+ s . remove ( shape2 , body2 )
711
677
712
- s . step ( 1 )
713
- s . on_collision ( 0 , separate = separate )
678
+ def remove3 ( * _ : Any ) -> None :
679
+ s . remove ( shape3 , body3 )
714
680
715
- s .remove (shape1 )
681
+ s .on_collision (0 , separate = remove2 )
682
+ s .on_collision (1 , separate = remove3 )
716
683
717
- print (" XXX end" )
684
+ s .step (0.1 )
685
+
686
+ self .assertEqual (len (s .shapes ), 3 )
687
+ s .remove (shape1 )
688
+ self .assertEqual (len (s .shapes ), 0 )
718
689
719
- @unittest .skip ("Existing bug in Pymunk. TODO: Fix bug and enable test" )
720
690
def testCollisionHandlerRemoveAfterSeparate (self ) -> None :
721
691
# In this test the separate must happen before post_solve in the same step()
722
692
print ()
@@ -735,35 +705,24 @@ def testCollisionHandlerRemoveAfterSeparate(self) -> None:
735
705
shape3 .collision_type = 3
736
706
737
707
space .add (shape1 , body2 , shape2 , shape3 , body3 )
738
- print ("START" , shape1 , shape2 , shape3 )
739
708
740
709
def separate (arbiter : p .Arbiter , space : p .Space , data : Any ) -> None :
741
- print ("SEP" , arbiter .shapes )
742
710
self .separate_occurred = True
743
711
744
712
def post_solve (arbiter : p .Arbiter , space : p .Space , data : Any ) -> None :
745
- print ("POST" , arbiter .shapes )
746
713
if self .separate_occurred :
747
- print ("POST REMOVE" , arbiter .shapes )
748
714
space .remove (* arbiter .shapes )
749
715
750
716
space .on_collision (1 , 2 , post_solve = post_solve )
751
717
space .on_collision (3 , 2 , separate = separate )
752
718
753
- print (1 )
754
719
self .separate_occurred = False
755
720
space .step (1 )
756
- print (2 )
757
721
body3 .position = 10 , 0
758
- # self.assertEqual(len(space.shapes), 3)
759
722
760
723
self .separate_occurred = False
761
724
space .step (1 )
762
- print (3 )
763
725
space .remove (shape3 )
764
- # self.assertEqual(len(space.shapes), 1)
765
- print (4 )
766
- # space.remove(shape3)
767
726
768
727
def testCollisionHandlerAddRemoveInStep (self ) -> None :
769
728
s = p .Space ()
@@ -791,14 +750,13 @@ def pre_solve_remove(arb: p.Arbiter, space: p.Space, data: Any) -> None:
791
750
self .assertTrue (b in s .bodies )
792
751
self .assertTrue (c in s .shapes )
793
752
794
- s .on_collision (0 , 0 , pre_solve = pre_solve_add )
753
+ s .on_collision (pre_solve = pre_solve_add )
795
754
796
755
s .step (0.1 )
797
- return
798
756
self .assertTrue (b in s .bodies )
799
757
self .assertTrue (c in s .shapes )
800
758
801
- s .on_collision (0 , 0 ). pre_solve = pre_solve_remove
759
+ s .on_collision (pre_solve = pre_solve_remove )
802
760
803
761
s .step (0.1 )
804
762
0 commit comments