Axiovora-X / tests /test_alphageometry_utils.py
ZAIDX11's picture
Add files using upload-large-folder tool
19faf57 verified
import math
from alphageometry.modules import utils
def test_polygon_area_and_centroid():
square = [(0, 0), (1, 0), (1, 1), (0, 1)]
assert math.isclose(utils.polygon_area(square), 1.0, rel_tol=1e-9)
cx, cy = utils.polygon_centroid(square)
assert math.isclose(cx, 0.5)
assert math.isclose(cy, 0.5)
def test_convex_hull_simple():
pts = [(0, 0), (1, 0), (0.5, 0.5), (0, 1), (1, 1)]
hull = utils.convex_hull(pts)
# hull should be the rectangle corners in CCW order
assert set(hull) == {(0, 0), (1, 0), (1, 1), (0, 1)}
def test_point_in_polygon_and_on_edge():
tri = [(0, 0), (2, 0), (1, 2)]
assert utils.point_in_polygon((1, 1), tri)
# point on edge
assert utils.point_in_polygon((1, 0), tri)
def test_rdp_closed_and_safe_earclip():
poly = [(0, 0), (2, 0), (2, 2), (1, 1.5), (0, 2), (0, 0)]
simplified = utils.rdp_simplify_closed(poly, 0.5)
assert len(simplified) >= 3
tris = utils.safe_earclip_triangulate(poly[:-1])
# triangulation should produce at least one triangle
assert len(tris) >= 1