Skip to content

Commit 9affb21

Browse files
authored
Merge pull request #781 from compas-dev/ne_in_ipy
add __ne__ to primitives and transformations
2 parents 29377ed + 6e9946f commit 9affb21

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
### Changed
1616

1717
* Fixed bug where mimic joints were considered configurable.
18+
* Fixed bug where `!=` gave incorrect results in Rhino for some compas objects.
1819

1920
### Removed
2021

src/compas/geometry/primitives/_primitive.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class Primitive(Base):
1818
def __init__(self):
1919
super(Primitive, self).__init__()
2020

21+
def __ne__(self, other):
22+
# this is not obvious to ironpython
23+
return not self.__eq__(other)
24+
2125
@classmethod
2226
def from_json(cls, filepath):
2327
"""Construct a primitive from structured data contained in a json file.

src/compas/geometry/transformations/transformation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ def __eq__(self, other, tol=1e-05):
9797
except BaseException:
9898
return False
9999

100+
def __ne__(self, other):
101+
# this is not obvious to ironpython
102+
return not self.__eq__(other)
103+
100104
def __repr__(self):
101105
return "Transformation({})".format(self.matrix)
102106

tests/compas/geometry/test_point.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ def test_point_operators():
1313
pass
1414

1515

16+
def test_point_equality():
17+
p1 = Point(1, 1, 1)
18+
p2 = Point(1, 1, 1)
19+
p3 = Point(0, 0, 0)
20+
assert p1 == p2
21+
assert not (p1 != p2)
22+
assert p1 != p3
23+
assert not (p1 == p3)
24+
25+
1626
def test_point_inplace_operators():
1727
pass
1828

tests/compas/geometry/test_transformations/test_transformation.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,13 @@ def test___str__():
135135
angle = 0.7854
136136
R = Rotation.from_axis_and_angle(axes, angle, point=trans)
137137
assert s == str(R)
138+
139+
140+
def test___eq__():
141+
i1 = Transformation()
142+
i2 = Transformation()
143+
t = Translation.from_vector([1, 0, 0])
144+
assert i1 == i2
145+
assert not (i1 != i2)
146+
assert i1 != t
147+
assert not (i1 == t)

0 commit comments

Comments
 (0)