Files
ai_mouse/tests/unit/test__coord.py
Huang Qi 17b406c28b 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>
2026-05-12 01:02:25 +08:00

31 lines
1.0 KiB
Python

"""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)