test_into_poly.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from collisions import *
  2. def test_box_into_poly():
  3. box = CollisionBox((0, 0, 0), 2, 3, 4)
  4. poly = CollisionPolygon(Point3(0, 0, 0), Point3(0, 0, 1), Point3(0, 1, 1), Point3(0, 1, 0))
  5. entry = make_collision(box, poly)[0]
  6. assert entry is not None
  7. assert entry.get_from() == box
  8. assert entry.get_into() == poly
  9. # Colliding just on the edge
  10. entry, np_from, np_into = make_collision(CollisionBox((0, 3, 0), 1, 2, 1), poly)
  11. assert entry.get_surface_point(np_from) == Point3(0, 3, 0)
  12. assert entry.get_surface_normal(np_into) == Vec3(-1, 0, 0) # Testing surface normal
  13. # No collision
  14. entry = make_collision(CollisionBox((10, 10, 10), 8, 9, 10), poly)[0]
  15. assert entry is None
  16. def test_sphere_into_poly():
  17. sphere = CollisionSphere(0, 0, 0, 1)
  18. poly = CollisionPolygon(Point3(0, 0, 0), Point3(0, 0, 1), Point3(0, 1, 1), Point3(0, 1, 0))
  19. entry = make_collision(sphere, poly)[0]
  20. assert entry is not None
  21. assert entry.get_from() == sphere
  22. assert entry.get_into() == poly
  23. # Colliding just on the edge
  24. entry, np_from, np_into = make_collision(CollisionSphere(0, 0, 3, 2), poly)
  25. assert entry.get_surface_point(np_from) == Point3(0, 0, 3)
  26. assert entry.get_surface_normal(np_into) == Vec3(-1, 0, 0) # Testing surface normal
  27. # No collision
  28. entry = make_collision(CollisionSphere(100, 100, 100, 100), poly)[0]
  29. assert entry is None
  30. def test_plane_into_poly():
  31. # CollisionPlane is not a 'from' object
  32. plane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
  33. poly = CollisionPolygon(Point3(0, 0, 0), Point3(0, 0, 1), Point3(0, 1, 1), Point3(0, 1, 0))
  34. entry = make_collision(plane, poly)[0]
  35. assert entry is None