Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testCircleBB(self):
s = p.Space()
b = p.Body(10,10)
c = p.Circle(b,5)
c.cache_bb()
self.assertEqual(c.bb, p.BB(-5.0, -5.0, 5.0, 5.0))
def testCreation(self):
bb_empty = p.BB()
self.assertEqual(bb_empty.left, 0)
self.assertEqual(bb_empty.bottom, 0)
self.assertEqual(bb_empty.right, 0)
self.assertEqual(bb_empty.top , 0)
bb_defined = p.BB(-10,-5,15,20)
self.assertEqual(bb_defined.left, -10)
self.assertEqual(bb_defined.bottom, -5)
self.assertEqual(bb_defined.right, 15)
self.assertEqual(bb_defined.top, 20)
bb_circle = p.BB.newForCircle((3,3),3)
self.assertEqual(bb_circle.left, 0)
self.assertEqual(bb_circle.bottom, 0)
def testCreateBox(self):
c = p.Poly.create_box(None, (4,2), 3)
self.assertEqual(c.get_vertices(), [(2,-1), (2,1), (-2,1), (-2,-1)])
c = p.Poly.create_box_bb(None, p.BB(1,2,3,4), 3)
self.assertEqual(c.get_vertices(), [(3,2), (3,4), (1,4), (1,2)])
def testMerge(self):
bb1 = p.BB(0,0,10,10)
bb2 = p.BB(2,0,10,10)
bb3 = p.BB(10,10,15,15)
self.assertEqual(bb1.merge(bb2), p.BB(0,0,10,10))
self.assertEqual(bb2.merge(bb3).merge(bb1), p.BB(0,0,15,15))
def testBB(self):
c = p.Poly(None, [(2,2),(4,3),(3,5)])
bb = c.update(p.Transform.identity())
self.assertEqual(bb, c.bb)
self.assertEqual(c.bb, p.BB(2, 2, 4, 5))
b = p.Body(1,2)
c = p.Poly(b, [(2,2),(4,3),(3,5)])
c.cache_bb()
self.assertEqual(c.bb, p.BB(2, 2, 4, 5))
s = p.Space()
b = p.Body(1,2)
c = p.Poly(b, [(2,2),(4,3),(3,5)])
s.add(b,c)
self.assertEqual(c.bb, p.BB(2, 2, 4, 5))
def testCircleNoBody(self):
s = p.Space()
c = p.Circle(None,5)
bb = c.update(p.Transform(1, 2, 3, 4, 5, 6))
self.assertEqual(c.bb, bb)
self.assertEqual(c.bb, p.BB(0, 1, 10, 11))
v1 = Vec2d(1,1)
v2 = Vec2d(100,3)
self.assertTrue(bb1.intersects(bb2))
self.assertFalse(bb3.intersects(bb2))
self.assertTrue(bb1.intersects_segment(v1,v2))
self.assertFalse(bb3.intersects_segment(v1,v2))
self.assertTrue(bb1.contains(bb3))
self.assertFalse(bb1.contains(bb2))
self.assertTrue(bb1.contains_vect(v1))
self.assertFalse(bb1.contains_vect(v2))
self.assertEqual(bb1.expand(v1), bb1)
self.assertEqual(bb1.expand(-v2), p.BB(-100,-3,10,10))
self.assertEqual(bb1.center(), (5,5))
self.assertEqual(bb1.area(), 100)
self.assertEqual(bb1.merged_area(bb2), 400)
self.assertEqual(bb2.segment_query(v1, v2), p.inf)
self.assertEqual(bb1.segment_query((-1,1), (99,1)), 0.01)
self.assertEqual(bb1.clamp_vect(v2), Vec2d(10,3))
def testCreation(self):
bb_empty = p.BB()
self.assertEqual(bb_empty.left, 0)
self.assertEqual(bb_empty.bottom, 0)
self.assertEqual(bb_empty.right, 0)
self.assertEqual(bb_empty.top , 0)
bb_defined = p.BB(-10,-5,15,20)
self.assertEqual(bb_defined.left, -10)
self.assertEqual(bb_defined.bottom, -5)
self.assertEqual(bb_defined.right, 15)
self.assertEqual(bb_defined.top, 20)
def testMerge(self):
bb1 = p.BB(0,0,10,10)
bb2 = p.BB(2,0,10,10)
bb3 = p.BB(10,10,15,15)
self.assertEqual(bb1.merge(bb2), p.BB(0,0,10,10))
self.assertEqual(bb2.merge(bb3).merge(bb1), p.BB(0,0,15,15))
screen = pygame.display.set_mode((690, 300))
clock = pygame.time.Clock()
clock.tick(1/5.)
### Physics stuff
space = pymunk.Space()
space.gravity = 0, 900
space.sleep_time_threshold = 0.3
draw_options = pymunk.pygame_util.DrawOptions(screen)
pymunk.pygame_util.positive_y_is_up = False
### Generate geometry from pymunk logo image
logo_img = pygame.image.load("pymunk_logo_sphinx.png")
logo_bb = pymunk.BB(0,0,logo_img.get_width(), logo_img.get_height())
def sample_func(point):
try:
p = pymunk.pygame_util.to_pygame(point, logo_img)
color = logo_img.get_at(p)
return color.a
return color.hsla[2]
except:
return 0
line_set = pymunk.autogeometry.PolylineSet()
def segment_func(v0, v1):
line_set.collect_segment(v0, v1)
logo_img.lock()