diff --git a/src/build123d/topology/helpers.py b/src/build123d/topology/helpers.py index a20c393..15e6358 100644 --- a/src/build123d/topology/helpers.py +++ b/src/build123d/topology/helpers.py @@ -103,13 +103,20 @@ def geom_equal( return True case GeomType.CIRCLE: - return abs(ga1.Circle().Radius() - ga2.Circle().Radius()) < tol + c1, c2 = ga1.Circle(), ga2.Circle() + return ( + abs(c1.Radius() - c2.Radius()) < tol + and Vector(c1.Location()) == Vector(c2.Location()) + and Vector(c1.Axis().Direction()) == Vector(c2.Axis().Direction()) + ) case GeomType.ELLIPSE: e1, e2 = ga1.Ellipse(), ga2.Ellipse() return ( abs(e1.MajorRadius() - e2.MajorRadius()) < tol and abs(e1.MinorRadius() - e2.MinorRadius()) < tol + and Vector(e1.Location()) == Vector(e2.Location()) + and Vector(e1.Axis().Direction()) == Vector(e2.Axis().Direction()) ) case GeomType.HYPERBOLA: @@ -117,10 +124,17 @@ def geom_equal( return ( abs(h1.MajorRadius() - h2.MajorRadius()) < tol and abs(h1.MinorRadius() - h2.MinorRadius()) < tol + and Vector(h1.Location()) == Vector(h2.Location()) + and Vector(h1.Axis().Direction()) == Vector(h2.Axis().Direction()) ) case GeomType.PARABOLA: - return abs(ga1.Parabola().Focal() - ga2.Parabola().Focal()) < tol + p1, p2 = ga1.Parabola(), ga2.Parabola() + return ( + abs(p1.Focal() - p2.Focal()) < tol + and Vector(p1.Location()) == Vector(p2.Location()) + and Vector(p1.Axis().Direction()) == Vector(p2.Axis().Direction()) + ) case GeomType.BEZIER: b1, b2 = ga1.Bezier(), ga2.Bezier() diff --git a/tests/test_direct_api/test_geom_equal.py b/tests/test_direct_api/test_geom_equal.py index 1f1ae90..e003f0f 100644 --- a/tests/test_direct_api/test_geom_equal.py +++ b/tests/test_direct_api/test_geom_equal.py @@ -2,9 +2,7 @@ import pytest from build123d import ( - Vector, Vertex, - Location, Edge, Wire, Spline, @@ -17,30 +15,6 @@ from build123d import ( from build123d.topology.helpers import geom_equal -class TestGeomEqualVector: - """Tests for Vector comparison.""" - - def test_same_vector(self): - v1 = Vector(1, 2, 3) - v2 = Vector(1, 2, 3) - assert geom_equal(v1, v2) - - def test_different_vector(self): - v1 = Vector(1, 2, 3) - v2 = Vector(1, 2, 4) - assert not geom_equal(v1, v2) - - def test_vector_within_tolerance(self): - v1 = Vector(1, 2, 3) - v2 = Vector(1, 2, 3 + 1e-7) - assert geom_equal(v1, v2) - - def test_vector_outside_tolerance(self): - v1 = Vector(1, 2, 3) - v2 = Vector(1, 2, 3 + 1e-5) - assert not geom_equal(v1, v2) - - class TestGeomEqualVertex: """Tests for Vertex comparison.""" @@ -60,25 +34,6 @@ class TestGeomEqualVertex: assert geom_equal(v1, v2) -class TestGeomEqualLocation: - """Tests for Location comparison.""" - - def test_same_location(self): - loc1 = Location((1, 2, 3)) - loc2 = Location((1, 2, 3)) - assert geom_equal(loc1, loc2) - - def test_different_position(self): - loc1 = Location((1, 2, 3)) - loc2 = Location((1, 2, 4)) - assert not geom_equal(loc1, loc2) - - def test_different_orientation(self): - loc1 = Location((0, 0, 0), (0, 0, 0)) - loc2 = Location((0, 0, 0), (45, 0, 0)) - assert not geom_equal(loc1, loc2) - - class TestGeomEqualEdgeLine: """Tests for Edge LINE comparison.""" @@ -122,6 +77,17 @@ class TestGeomEqualEdgeCircle: e2 = Edge.make_circle(10, start_angle=0, end_angle=180) assert not geom_equal(e1, e2) + def test_different_circle_from_revolve(self): + """Two circles with same radius/endpoints but different center/axis.""" + from build123d import Axis, Line, RadiusArc, make_face, revolve + + f1 = make_face(RadiusArc((5, 0), (-5, 0), 15) + Line((5, 0), (-5, 0))) + p1 = revolve(f1, Axis.X, 90) + value1, value2 = p1.edges().filter_by(GeomType.CIRCLE) + value2 = value2.reversed() + # These circles have same endpoints after reversal but different center/axis + assert not geom_equal(value1, value2) + class TestGeomEqualEdgeEllipse: """Tests for Edge ELLIPSE comparison.""" @@ -283,11 +249,6 @@ class TestGeomEqualWire: class TestGeomEqualTypeMismatch: """Tests for type mismatch cases.""" - def test_vector_vs_vertex(self): - v1 = Vector(1, 2, 3) - v2 = Vertex(1, 2, 3) - assert not geom_equal(v1, v2) - def test_edge_vs_wire(self): e = Edge.make_line((0, 0), (1, 1)) w = Wire([e])