fix axis equality

This commit is contained in:
Ruud Swinkels 2023-10-29 21:12:54 +01:00
parent 159ff7d9c2
commit ff80caf723
2 changed files with 17 additions and 30 deletions

View file

@ -460,24 +460,6 @@ class Axis(metaclass=Axis_meta):
_dim = 1
@classmethod
@property
def X(cls) -> Axis:
"""X Axis"""
return Axis((0, 0, 0), (1, 0, 0))
@classmethod
@property
def Y(cls) -> Axis:
"""Y Axis"""
return Axis((0, 0, 0), (0, 1, 0))
@classmethod
@property
def Z(cls) -> Axis:
"""Z Axis"""
return Axis((0, 0, 0), (0, 0, 1))
@property
def location(self) -> Location:
"""Return self as Location"""
@ -562,6 +544,11 @@ class Axis(metaclass=Axis_meta):
def __str__(self) -> str:
"""Display self"""
return f"Axis: ({self.position.to_tuple()},{self.direction.to_tuple()})"
def __eq__(self, other: object) -> bool:
if not isinstance(other, Axis):
return False
return self.position == other.position and self.direction == other.direction
def located(self, new_location: Location):
"""relocates self to a new location possibly changing position and direction"""

View file

@ -344,14 +344,14 @@ class TestShapeList(unittest.TestCase):
self.assertTrue(isinstance(edges, ShapeList))
self.assertEqual(len(edges), 4)
if axis == Axis.X:
self.assertLessEqual(faces[0].center().x, faces[1].center().x)
self.assertLessEqual(edges[0].center().x, edges[-1].center().x)
self.assertLessEqual(faces[0].center().X, faces[1].center().X)
self.assertLessEqual(edges[0].center().X, edges[-1].center().X)
elif axis == Axis.Y:
self.assertLessEqual(faces[0].center().y, faces[1].center().y)
self.assertLessEqual(edges[0].center().y, edges[-1].center().y)
self.assertLessEqual(faces[0].center().Y, faces[1].center().Y)
self.assertLessEqual(edges[0].center().Y, edges[-1].center().Y)
elif axis == Axis.Z:
self.assertLessEqual(faces[0].center().z, faces[1].center().z)
self.assertLessEqual(edges[0].center().z, edges[-1].center().z)
self.assertLessEqual(faces[0].center().Z, faces[1].center().Z)
self.assertLessEqual(edges[0].center().Z, edges[-1].center().Z)
# test filter by type
with BuildPart() as test:
@ -383,24 +383,24 @@ class TestShapeList(unittest.TestCase):
self.assertEqual(len(edges), 4 * sum(inclusive) + 4)
if axis == Axis.X:
self.assertLessEqual(
faces[0].center().x, faces[-1].center().x
faces[0].center().X, faces[-1].center().X
)
self.assertLessEqual(
edges[0].center().x, edges[-1].center().x
edges[0].center().X, edges[-1].center().X
)
elif axis == Axis.Y:
self.assertLessEqual(
faces[0].center().y, faces[-1].center().y
faces[0].center().Y, faces[-1].center().Y
)
self.assertLessEqual(
edges[0].center().y, edges[-1].center().y
edges[0].center().Y, edges[-1].center().Y
)
elif axis == Axis.Z:
self.assertLessEqual(
faces[0].center().z, faces[-1].center().z
faces[0].center().Z, faces[-1].center().Z
)
self.assertLessEqual(
edges[0].center().z, edges[-1].center().z
edges[0].center().Z, edges[-1].center().Z
)
def test_sort_by_type(self):