import math import pytest from naramotion.path import Path from naramotion.motion import trim_path, PathFollower, PathMorph def test_trim_path_line(): p = Path() p.move_to(0, 0) p.line_to(100, 0) # Trim 0.0 -> 0.5 (halfway line) trimmed = trim_path(p, 0.0, 0.5) assert not trimmed.is_empty() verts = trimmed.get_vertices() assert len(verts) >= 2 assert math.isclose(verts[-1][1], 50.0, abs_tol=1.0) def test_trim_path_circle_reveal(): p = Path() p.add_circle(100, 100, 50) # 3/4 circle reveal trimmed = trim_path(p, 0.0, 0.75) assert not trimmed.is_empty() assert trimmed.size > 5 def test_path_follower(): p = Path() p.move_to(0, 0) p.line_to(100, 0) p.line_to(100, 100) follower = PathFollower(p) # Start (0, 0) p0 = follower.get_position(0.0) assert math.isclose(p0[0], 0.0, abs_tol=1e-3) assert math.isclose(p0[1], 0.0, abs_tol=1e-3) # Midpoint (100, 0) at t=0.5 p_mid = follower.get_position(0.5) assert math.isclose(p_mid[0], 100.0, abs_tol=1.0) assert math.isclose(p_mid[1], 0.0, abs_tol=1.0) # End (100, 100) at t=1.0 p_end = follower.get_position(1.0) assert math.isclose(p_end[0], 100.0, abs_tol=1.0) assert math.isclose(p_end[1], 100.0, abs_tol=1.0) # Heading angle angle_start = follower.get_tangent_angle(0.1) assert math.isclose(angle_start, 0.0, abs_tol=0.1) # Heading East def test_path_morph(): # Square p1 = Path() p1.add_rect(0, 0, 100, 100) # Circle p2 = Path() p2.add_circle(50, 50, 50) morph = PathMorph(p1, p2, num_samples=50) # Midpoint shape p_mid = morph(0.5) assert isinstance(p_mid, Path) assert not p_mid.is_empty() assert p_mid.size >= 50