"""Unit tests exercising the new alphageometry modules (utils + visualizer). These tests are intentionally small and dependency-free so they run in CI and local developer environments without extra setup. """ from __future__ import annotations import tempfile from alphageometry.modules import utils, visualizer def test_polygon_area_and_triangulation(): # simple unit square square = [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)] area = utils.polygon_area(square) assert abs(area - 1.0) < 1e-12 tris = utils.earclip_triangulate(square) # triangulation of quad -> 2 triangles assert len(tris) == 2 # triangles should use indices from 0..3 for t in tris: assert all(0 <= i < 4 for i in t) def test_rdp_simplify(): # stair-step polyline: many points but simplifiable pts = [(float(i), 0.0) for i in range(20)] simplified = utils.rdp_simplify(pts, epsilon=0.5) assert len(simplified) < len(pts) assert simplified[0] == pts[0] assert simplified[-1] == pts[-1] def test_visualizer_svg_and_json_roundtrip(): tri_verts = [(0.0, 0.0), (1.0, 0.0), (0.5, 0.8)] triangles = [(0, 1, 2)] svg = visualizer.mesh_to_svg(tri_verts, triangles) assert svg.startswith("