feat(lib): add private _coord.py with numpy transforms
Copy of coord.py (which is already pure numpy) into the private underscored module to be consumed by upcoming mouse.py rewrite. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
30
tests/unit/test__coord.py
Normal file
30
tests/unit/test__coord.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""Test the private numpy coordinate transforms."""
|
||||
from __future__ import annotations
|
||||
|
||||
import numpy as np
|
||||
|
||||
from ai_mouse._coord import decode_trajectory, encode_trajectory
|
||||
|
||||
|
||||
def test_encode_decode_roundtrip() -> None:
|
||||
points = np.array([[100.0, 200.0], [300.0, 250.0], [500.0, 300.0]])
|
||||
start = (100, 200)
|
||||
end = (500, 300)
|
||||
encoded = encode_trajectory(points, start, end)
|
||||
decoded = decode_trajectory(encoded, start, end)
|
||||
assert np.allclose(decoded, points, atol=1e-6)
|
||||
|
||||
|
||||
def test_encode_endpoints() -> None:
|
||||
"""Start should encode to (0,0); end should encode to (1,0)."""
|
||||
points = np.array([[100.0, 200.0], [500.0, 300.0]])
|
||||
encoded = encode_trajectory(points, (100, 200), (500, 300))
|
||||
assert np.allclose(encoded[0], [0.0, 0.0], atol=1e-6)
|
||||
assert np.allclose(encoded[1], [1.0, 0.0], atol=1e-6)
|
||||
|
||||
|
||||
def test_zero_distance_returns_zeros() -> None:
|
||||
points = np.array([[100.0, 200.0]])
|
||||
encoded = encode_trajectory(points, (100, 200), (100, 200))
|
||||
assert encoded.shape == (1, 2)
|
||||
assert np.all(encoded == 0)
|
||||
Reference in New Issue
Block a user