test_into_invsphere.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from collisions import *
  2. from pytest import approx
  3. def test_parabola_into_invsphere():
  4. invsphere = CollisionInvSphere(1, 1, 1, 5)
  5. parabola = CollisionParabola()
  6. parabola.set_t1(0)
  7. parabola.set_t2(2)
  8. # parabola starts from outside the sphere
  9. parabola.set_parabola(
  10. LParabola((1, 1, 1), (0, 0, 0), (7, 7, 7)))
  11. entry, np_from, np_into = make_collision(parabola, invsphere)
  12. assert (entry.get_surface_point(np_from) -
  13. invsphere.get_center()).length() == approx(invsphere.get_radius())
  14. # parabola starts on the sphere
  15. parabola.set_parabola(
  16. LParabola((1, 0, 1), (1, 0, 0), (1, 1, 6)))
  17. entry, np_from, np_into = make_collision(parabola, invsphere)
  18. assert entry.get_surface_point(np_from) == (1, 1, 6)
  19. # parabola starts from inside the sphere but doesn't collide
  20. parabola.set_parabola(
  21. LParabola((-1, -1, -1), (1, 1, 1), (1, 1, 1)))
  22. entry = make_collision(parabola, invsphere)[0]
  23. assert entry is None
  24. # parabola is inside the sphere and collides on an endpoint
  25. parabola.set_parabola(
  26. LParabola((1, 0, 0), (0, 0, 0), (2, 1, 1)))
  27. entry, np_from, np_into = make_collision(parabola, invsphere)
  28. assert entry.get_surface_point(np_from) == (6, 1, 1)
  29. # parabola starts from inside the sphere and collides on its projectile
  30. parabola.set_t2(3)
  31. assert parabola.get_parabola().calc_point(2) == (6, 1, 1)
  32. entry, np_from, np_into = make_collision(parabola, invsphere)
  33. assert entry.get_surface_point(np_from) == (6, 1, 1)
  34. parabola.set_parabola(
  35. LParabola((-1, 0, 0), (-1, 0, 0), (2, 1, 1)))
  36. assert parabola.get_parabola().calc_point(2) == (-4, 1, 1)
  37. entry, np_from, np_into = make_collision(parabola, invsphere)
  38. assert entry.get_surface_point(np_from) == (-4, 1, 1)