Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion spatialmath/geom3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
37 changes: 37 additions & 0 deletions tests/test_line_equality_regression.py
Original file line number Diff line number Diff line change
@@ -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