From 82d5809a988a5f1d47e69e763c8b95db42e153e1 Mon Sep 17 00:00:00 2001 From: Kaushik Gunasekaren Date: Mon, 16 Nov 2026 10:40:31 -0700 Subject: [PATCH 1/2] Make geometric line equality sign invariant --- spatialmath/geom3d.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spatialmath/geom3d.py b/spatialmath/geom3d.py index c1efbbb2..c4932013 100644 --- a/spatialmath/geom3d.py +++ b/spatialmath/geom3d.py @@ -670,8 +670,10 @@ def isequal( :seealso: :meth:`__eq__` """ + # A common sign reversal of both Plucker components is the same line. return bool( - abs(1 - np.dot(base.unitvec(l1.vec), base.unitvec(l2.vec))) < tol * _eps + abs(1 - abs(np.dot(base.unitvec(l1.vec), base.unitvec(l2.vec)))) + < tol * _eps ) def isparallel( From 8023c55b49f904cf20b437fc2341ec4bdbaa1b8c Mon Sep 17 00:00:00 2001 From: Kaushik Gunasekaren Date: Mon, 16 Nov 2026 10:41:06 -0700 Subject: [PATCH 2/2] Test geometric equality under signed homogeneous scales --- tests/test_line_equality_regression.py | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/test_line_equality_regression.py diff --git a/tests/test_line_equality_regression.py b/tests/test_line_equality_regression.py new file mode 100644 index 00000000..d4fcedba --- /dev/null +++ b/tests/test_line_equality_regression.py @@ -0,0 +1,37 @@ +import numpy as np +import pytest +from spatialmath import Line3 + + +@pytest.mark.parametrize("scale", [1, 3, -1, -3, 1e-10, -1e-10, 1e10, -1e10]) +@pytest.mark.parametrize( + "point,direction", + [([0, 0, 0], [1, 0, 0]), ([1, 2, 3], [2, -1, 1]), ([-2, 4, 1], [0, 1, 2])], +) +def test_line_equality_homogeneous_sign(point, direction, scale): + line = Line3.PointDir(point, direction) + equivalent = Line3(scale * line.vec) + for first, second in [(line, equivalent), (equivalent, line)]: + assert first.isequal(second) + assert first == second + assert not first != second + + +def test_line_equality_reversed_endpoints(): + first, second = [1, 2, 3], [4, -1, 5] + assert Line3.Join(first, second) == Line3.Join(second, first) + + +@pytest.mark.parametrize("scale", [1, -1, 3, -3]) +@pytest.mark.parametrize("kind", ["parallel", "intersecting", "skew"]) +def test_line_equality_distinct_lines(kind, scale): + line = Line3.PointDir([0, 0, 0], [1, 0, 0]) + point, direction = { + "parallel": ([0, 1, 0], [1, 0, 0]), + "intersecting": ([0, 0, 0], [0, 1, 0]), + "skew": ([0, 0, 1], [0, 1, 0]), + }[kind] + other = Line3.PointDir(point, np.array(direction) * scale) + assert not line.isequal(other) + assert not line == other + assert line != other