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