test_coord_utils.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import sys
  2. import os
  3. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  4. import math
  5. from core.coord_utils import spherical_to_pan_tilt, pan_tilt_to_vector, compute_sample_grid
  6. def test_spherical_front():
  7. pan, tilt = spherical_to_pan_tilt(0.0, 0.0, 1.0)
  8. assert abs(pan - 0.0) < 1e-6
  9. assert abs(tilt - 0.0) < 1e-6
  10. def test_spherical_right():
  11. pan, tilt = spherical_to_pan_tilt(1.0, 0.0, 0.0)
  12. assert abs(pan - 90.0) < 1e-6
  13. assert abs(tilt - 0.0) < 1e-6
  14. def test_spherical_up():
  15. # pan is undefined at zenith (gimbal lock), so only tilt is asserted.
  16. pan, tilt = spherical_to_pan_tilt(0.0, 1.0, 0.0)
  17. assert abs(tilt - 90.0) < 1e-6
  18. def test_pan_tilt_to_vector_roundtrip():
  19. for pan in [0, 45, 90, 180, 270]:
  20. for tilt in [-20, 0, 20]:
  21. x, y, z = pan_tilt_to_vector(pan, tilt)
  22. pan2, tilt2 = spherical_to_pan_tilt(x, y, z)
  23. assert abs(pan - pan2) < 1e-6 or abs(abs(pan - pan2) - 360) < 1e-6
  24. assert abs(tilt - tilt2) < 1e-6
  25. def test_spherical_zero_vector():
  26. pan, tilt = spherical_to_pan_tilt(0.0, 0.0, 0.0)
  27. assert abs(pan - 0.0) < 1e-6
  28. assert abs(tilt - 0.0) < 1e-6
  29. def test_spherical_down():
  30. pan, tilt = spherical_to_pan_tilt(0.0, -1.0, 0.0)
  31. assert abs(tilt - (-90.0)) < 1e-6
  32. def test_spherical_pan_360_boundary():
  33. pan_in, tilt_in = 359.0, 0.0
  34. x, y, z = pan_tilt_to_vector(pan_in, tilt_in)
  35. pan_out, tilt_out = spherical_to_pan_tilt(x, y, z)
  36. assert abs(pan_out - pan_in) < 1e-6
  37. assert abs(tilt_out - tilt_in) < 1e-6
  38. def test_compute_sample_grid_default():
  39. points = compute_sample_grid()
  40. assert len(points) == 36
  41. for point in points:
  42. assert isinstance(point, tuple)
  43. assert len(point) == 2
  44. def test_compute_sample_grid_custom():
  45. points = compute_sample_grid(pan_range=(0.0, 90.0), tilt_layers=(-10.0, 0.0), pan_step=30.0)
  46. assert len(points) == 6
  47. for point in points:
  48. assert isinstance(point, tuple)
  49. assert len(point) == 2
  50. pan, tilt = point
  51. assert 0.0 <= pan < 90.0
  52. assert tilt in (-10.0, 0.0)