test_into_box.py 1.4 KB

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