add Vector.to_tuple deprecation warning

This commit is contained in:
gumyr 2025-05-25 18:46:46 -04:00
parent ff39e37052
commit e842b321f3
15 changed files with 111 additions and 137 deletions

View file

@ -274,6 +274,12 @@ class Vector:
def to_tuple(self) -> tuple[float, float, float]:
"""Return tuple equivalent"""
warnings.warn(
"to_tuple is deprecated and will be removed in a future version. "
"Use 'tuple(Vector)' instead.",
DeprecationWarning,
stacklevel=2,
)
return (self.X, self.Y, self.Z)
@property
@ -728,11 +734,13 @@ class Axis(metaclass=AxisMeta):
def __repr__(self) -> str:
"""Display self"""
return f"({self.position.to_tuple()},{self.direction.to_tuple()})"
return f"({tuple(self.position)},{tuple(self.direction)})"
def __str__(self) -> str:
"""Display self"""
return f"{type(self).__name__}: ({self.position.to_tuple()},{self.direction.to_tuple()})"
return (
f"{type(self).__name__}: ({tuple(self.position)},{tuple(self.direction)})"
)
def __eq__(self, other: object) -> bool:
if not isinstance(other, Axis):
@ -1028,7 +1036,7 @@ class BoundBox:
if isinstance(obj, tuple):
tmp.Update(*obj)
elif isinstance(obj, Vector):
tmp.Update(*obj.to_tuple())
tmp.Update(*obj)
elif isinstance(obj, BoundBox) and obj.wrapped is not None:
tmp.Add(obj.wrapped)
@ -1120,7 +1128,7 @@ class BoundBox:
def to_align_offset(self, align: Align2DType | Align3DType) -> Vector:
"""Amount to move object to achieve the desired alignment"""
return to_align_offset(self.min.to_tuple(), self.max.to_tuple(), align)
return to_align_offset(self.min, self.max, align)
class Color:
@ -2144,7 +2152,7 @@ class Rotation(Location):
if tuples:
angles = list(*tuples)
if vectors:
angles = vectors[0].to_tuple()
angles = tuple(vectors[0])
if len(angles) < 3:
angles.extend([0.0] * (3 - len(angles)))
rotations = list(filter(lambda item: isinstance(item, Rotation), args))
@ -2716,9 +2724,9 @@ class Plane(metaclass=PlaneMeta):
Returns:
Plane as String
"""
origin_str = ", ".join(f"{v:.2f}" for v in self._origin.to_tuple())
x_dir_str = ", ".join(f"{v:.2f}" for v in self.x_dir.to_tuple())
z_dir_str = ", ".join(f"{v:.2f}" for v in self.z_dir.to_tuple())
origin_str = ", ".join(f"{v:.2f}" for v in tuple(self._origin))
x_dir_str = ", ".join(f"{v:.2f}" for v in tuple(self.x_dir))
z_dir_str = ", ".join(f"{v:.2f}" for v in tuple(self.z_dir))
return f"Plane(o=({origin_str}), x=({x_dir_str}), z=({z_dir_str}))"
def reverse(self) -> Plane:
@ -2845,9 +2853,9 @@ class Plane(metaclass=PlaneMeta):
global_coord_system = gp_Ax3()
local_coord_system = gp_Ax3(
gp_Pnt(*self._origin.to_tuple()),
gp_Dir(*self.z_dir.to_tuple()),
gp_Dir(*self.x_dir.to_tuple()),
gp_Pnt(*self._origin),
gp_Dir(*self.z_dir),
gp_Dir(*self.x_dir),
)
forward_t.SetTransformation(global_coord_system, local_coord_system)
@ -2901,8 +2909,8 @@ class Plane(metaclass=PlaneMeta):
local_bottom_left = global_bottom_left.transform(transform_matrix)
local_top_right = global_top_right.transform(transform_matrix)
local_bbox = Bnd_Box(
gp_Pnt(*local_bottom_left.to_tuple()),
gp_Pnt(*local_top_right.to_tuple()),
gp_Pnt(*local_bottom_left),
gp_Pnt(*local_top_right),
)
return BoundBox(local_bbox)
if hasattr(obj, "wrapped") and obj.wrapped is None: # Empty shape

View file

@ -758,9 +758,7 @@ def project(
# The size of the object determines the size of the target projection screen
# as the screen is normal to the direction of parallel projection
shape_list = [
Vertex(*o.to_tuple()) if isinstance(o, Vector) else o for o in object_list
]
shape_list = [Vertex(o) if isinstance(o, Vector) else o for o in object_list]
object_size = Compound(children=shape_list).bounding_box(optimal=False).diagonal
vct_vrt_list = [o for o in object_list if isinstance(o, (Vector, Vertex))]

View file

@ -2635,7 +2635,7 @@ class Wire(Mixin1D, Shape[TopoDS_Wire]):
for edge_index, edge in enumerate(edges):
for i in range(fragments_per_edge):
param = i / (fragments_per_edge - 1)
points.append(edge.position_at(param).to_tuple()[:2])
points.append(tuple(edge.position_at(param))[:2])
points_lookup[edge_index * fragments_per_edge + i] = (edge_index, param)
convex_hull = ConvexHull(points)
@ -3029,13 +3029,13 @@ class Wire(Mixin1D, Shape[TopoDS_Wire]):
projection_object = BRepProj_Projection(
self.wrapped,
target_object.wrapped,
gp_Dir(*direction_vector.to_tuple()),
gp_Dir(*direction_vector),
)
else:
projection_object = BRepProj_Projection(
self.wrapped,
target_object.wrapped,
gp_Pnt(*center_point.to_tuple()),
gp_Pnt(*center_point),
)
# Generate a list of the projected wires with aligned orientation

View file

@ -660,15 +660,15 @@ class Shape(NodeMixin, Generic[TOPODS]):
address = node.address
name = ""
loc = (
"Center" + str(node.position.to_tuple())
"Center" + str(tuple(node.position))
if show_center
else "Position" + str(node.position.to_tuple())
else "Position" + str(tuple(node.position))
)
else:
address = id(node)
name = node.__class__.__name__.ljust(9)
loc = (
"Center" + str(node.center().to_tuple())
"Center" + str(tuple(node.center()))
if show_center
else "Location" + repr(node.location)
)

View file

@ -994,7 +994,7 @@ class Face(Mixin2D, Shape[TopoDS_Face]):
) from err
if surface_point_vectors:
for point in surface_point_vectors:
surface.Add(gp_Pnt(*point.to_tuple()))
surface.Add(gp_Pnt(*point))
try:
surface.Build()
surface_face = Face(surface.Shape())
@ -1387,7 +1387,7 @@ class Face(Mixin2D, Shape[TopoDS_Face]):
"""
solid_classifier = BRepClass3d_SolidClassifier(self.wrapped)
solid_classifier.Perform(gp_Pnt(*Vector(point).to_tuple()), tolerance)
solid_classifier.Perform(gp_Pnt(*Vector(point)), tolerance)
return solid_classifier.IsOnAFace()
# surface = BRep_Tool.Surface_s(self.wrapped)

View file

@ -237,18 +237,16 @@ class TestCommonOperations(unittest.TestCase):
def test_matmul(self):
self.assertTupleAlmostEquals(
(Edge.make_line((0, 0, 0), (1, 1, 1)) @ 0.5).to_tuple(), (0.5, 0.5, 0.5), 5
Edge.make_line((0, 0, 0), (1, 1, 1)) @ 0.5, (0.5, 0.5, 0.5), 5
)
def test_mod(self):
self.assertTupleAlmostEquals(
(Wire.make_circle(10) % 0.5).to_tuple(), (0, -1, 0), 5
)
self.assertTupleAlmostEquals(Wire.make_circle(10) % 0.5, (0, -1, 0), 5)
def test_xor(self):
helix_loc = Edge.make_helix(2 * pi, 1, 1) ^ 0
self.assertTupleAlmostEquals(helix_loc.position.to_tuple(), (1, 0, 0), 5)
self.assertTupleAlmostEquals(helix_loc.orientation.to_tuple(), (-45, 0, 180), 5)
self.assertTupleAlmostEquals(helix_loc.position, (1, 0, 0), 5)
self.assertTupleAlmostEquals(helix_loc.orientation, (-45, 0, 180), 5)
class TestLocations(unittest.TestCase):
@ -256,11 +254,11 @@ class TestLocations(unittest.TestCase):
locs = PolarLocations(1, 5, 45, 90, False).local_locations
for i, angle in enumerate(range(45, 135, 18)):
self.assertTupleAlmostEquals(
locs[i].position.to_tuple(),
Vector(1, 0).rotate(Axis.Z, angle).to_tuple(),
locs[i].position,
Vector(1, 0).rotate(Axis.Z, angle),
5,
)
self.assertTupleAlmostEquals(locs[i].orientation.to_tuple(), (0, 0, 0), 5)
self.assertTupleAlmostEquals(locs[i].orientation, (0, 0, 0), 5)
def test_polar_endpoint(self):
locs = PolarLocations(
@ -390,22 +388,18 @@ class TestLocations(unittest.TestCase):
square = Face.make_rect(1, 1, Plane.XZ)
with BuildPart():
loc = Locations(square).locations[0]
self.assertTupleAlmostEquals(
loc.position.to_tuple(), Location(Plane.XZ).position.to_tuple(), 5
)
self.assertTupleAlmostEquals(
loc.orientation.to_tuple(), Location(Plane.XZ).orientation.to_tuple(), 5
)
self.assertTupleAlmostEquals(loc.position, Location(Plane.XZ).position, 5)
self.assertTupleAlmostEquals(loc.orientation, Location(Plane.XZ).orientation, 5)
def test_from_plane(self):
with BuildPart():
loc = Locations(Plane.XY.offset(1)).locations[0]
self.assertTupleAlmostEquals(loc.position.to_tuple(), (0, 0, 1), 5)
self.assertTupleAlmostEquals(loc.position, (0, 0, 1), 5)
def test_from_axis(self):
with BuildPart():
loc = Locations(Axis((1, 1, 1), (0, 0, 1))).locations[0]
self.assertTupleAlmostEquals(loc.position.to_tuple(), (1, 1, 1), 5)
self.assertTupleAlmostEquals(loc.position, (1, 1, 1), 5)
def test_multiplication(self):
circles = GridLocations(2, 2, 2, 2) * Circle(1)
@ -416,25 +410,17 @@ class TestLocations(unittest.TestCase):
def test_grid_attributes(self):
grid = GridLocations(5, 10, 3, 4)
self.assertTupleAlmostEquals(grid.size.to_tuple(), (10, 30, 0), 5)
self.assertTupleAlmostEquals(grid.min.to_tuple(), (-5, -15, 0), 5)
self.assertTupleAlmostEquals(grid.max.to_tuple(), (5, 15, 0), 5)
self.assertTupleAlmostEquals(grid.size, (10, 30, 0), 5)
self.assertTupleAlmostEquals(grid.min, (-5, -15, 0), 5)
self.assertTupleAlmostEquals(grid.max, (5, 15, 0), 5)
def test_mixed_sequence_list(self):
locs = Locations((0, 1), [(2, 3), (4, 5)], (6, 7))
self.assertEqual(len(locs.locations), 4)
self.assertTupleAlmostEquals(
locs.locations[0].position.to_tuple(), (0, 1, 0), 5
)
self.assertTupleAlmostEquals(
locs.locations[1].position.to_tuple(), (2, 3, 0), 5
)
self.assertTupleAlmostEquals(
locs.locations[2].position.to_tuple(), (4, 5, 0), 5
)
self.assertTupleAlmostEquals(
locs.locations[3].position.to_tuple(), (6, 7, 0), 5
)
self.assertTupleAlmostEquals(locs.locations[0].position, (0, 1, 0), 5)
self.assertTupleAlmostEquals(locs.locations[1].position, (2, 3, 0), 5)
self.assertTupleAlmostEquals(locs.locations[2].position, (4, 5, 0), 5)
self.assertTupleAlmostEquals(locs.locations[3].position, (6, 7, 0), 5)
class TestProperties(unittest.TestCase):
@ -744,12 +730,12 @@ class TestValidateInputs(unittest.TestCase):
class TestVectorExtensions(unittest.TestCase):
def test_vector_localization(self):
self.assertTupleAlmostEquals(
(Vector(1, 1, 1) + (1, 2)).to_tuple(),
(Vector(1, 1, 1) + (1, 2)),
(2, 3, 1),
5,
)
self.assertTupleAlmostEquals(
(Vector(3, 3, 3) - (1, 2)).to_tuple(),
(Vector(3, 3, 3) - (1, 2)),
(2, 1, 3),
5,
)
@ -759,16 +745,14 @@ class TestVectorExtensions(unittest.TestCase):
Vector(1, 2, 3) - "four"
with BuildLine(Plane.YZ):
self.assertTupleAlmostEquals(WorkplaneList.localize((1, 2)), (0, 1, 2), 5)
self.assertTupleAlmostEquals(
WorkplaneList.localize((1, 2)).to_tuple(), (0, 1, 2), 5
)
self.assertTupleAlmostEquals(
WorkplaneList.localize(Vector(1, 1, 1) + (1, 2)).to_tuple(),
WorkplaneList.localize(Vector(1, 1, 1) + (1, 2)),
(1, 2, 3),
5,
)
self.assertTupleAlmostEquals(
WorkplaneList.localize(Vector(3, 3, 3) - (1, 2)).to_tuple(),
WorkplaneList.localize(Vector(3, 3, 3) - (1, 2)),
(3, 2, 1),
5,
)
@ -780,7 +764,7 @@ class TestVectorExtensions(unittest.TestCase):
with BuildLine(pln):
n3 = Line((-50, -40), (0, 0))
n4 = Line(n3 @ 1, n3 @ 1 + (0, 10))
self.assertTupleAlmostEquals((n4 @ 1).to_tuple(), (0, 0, -25), 5)
self.assertTupleAlmostEquals((n4 @ 1), (0, 0, -25), 5)
class TestWorkplaneList(unittest.TestCase):
@ -794,8 +778,8 @@ class TestWorkplaneList(unittest.TestCase):
def test_localize(self):
with BuildLine(Plane.YZ):
pnts = WorkplaneList.localize((1, 2), (2, 3))
self.assertTupleAlmostEquals(pnts[0].to_tuple(), (0, 1, 2), 5)
self.assertTupleAlmostEquals(pnts[1].to_tuple(), (0, 2, 3), 5)
self.assertTupleAlmostEquals(pnts[0], (0, 1, 2), 5)
self.assertTupleAlmostEquals(pnts[1], (0, 2, 3), 5)
def test_invalid_workplane(self):
with self.assertRaises(ValueError):

View file

@ -72,7 +72,7 @@ class AddTests(unittest.TestCase):
# Add Edge
with BuildLine() as test:
add(Edge.make_line((0, 0, 0), (1, 1, 1)))
self.assertTupleAlmostEquals((test.wires()[0] @ 1).to_tuple(), (1, 1, 1), 5)
self.assertTupleAlmostEquals(test.wires()[0] @ 1, (1, 1, 1), 5)
# Add Wire
with BuildLine() as wire:
Polyline((0, 0, 0), (1, 1, 1), (2, 0, 0), (3, 1, 1))
@ -94,13 +94,11 @@ class AddTests(unittest.TestCase):
add(Solid.make_box(10, 10, 10), rotation=(0, 0, 45))
self.assertAlmostEqual(test.part.volume, 1000, 5)
self.assertTupleAlmostEquals(
(
test.part.edges()
.group_by(Axis.Z)[-1]
.group_by(Axis.X)[-1]
.sort_by(Axis.Y)[0]
% 1
).to_tuple(),
% 1,
(sqrt(2) / 2, sqrt(2) / 2, 0),
5,
)
@ -680,12 +678,12 @@ class ProjectionTests(unittest.TestCase):
def test_project_point(self):
pnt: Vector = project(Vector(1, 2, 3), Plane.XY)[0]
self.assertTupleAlmostEquals(pnt.to_tuple(), (1, 2, 0), 5)
self.assertTupleAlmostEquals(pnt, (1, 2, 0), 5)
pnt: Vector = project(Vertex(1, 2, 3), Plane.XZ)[0]
self.assertTupleAlmostEquals(pnt.to_tuple(), (1, 3, 0), 5)
self.assertTupleAlmostEquals(pnt, (1, 3, 0), 5)
with BuildSketch(Plane.YZ) as s1:
pnt = project(Vertex(1, 2, 3), mode=Mode.PRIVATE)[0]
self.assertTupleAlmostEquals(pnt.to_tuple(), (2, 3, 0), 5)
self.assertTupleAlmostEquals(pnt, (2, 3, 0), 5)
def test_multiple_results(self):
with BuildLine() as l1:

View file

@ -205,7 +205,7 @@ class BuildLineTests(unittest.TestCase):
l3 = Line((0, 0), (10, 10))
l4 = IntersectingLine((0, 10), (1, -1), l3)
self.assertTupleAlmostEquals((l4 @ 1).to_tuple(), (5, 5, 0), 5)
self.assertTupleAlmostEquals(l4 @ 1, (5, 5, 0), 5)
self.assertTrue(isinstance(l4, Edge))
with self.assertRaises(ValueError):
@ -214,22 +214,20 @@ class BuildLineTests(unittest.TestCase):
def test_jern_arc(self):
with BuildLine() as jern:
j1 = JernArc((1, 0), (0, 1), 1, 90)
self.assertTupleAlmostEquals((jern.line @ 1).to_tuple(), (0, 1, 0), 5)
self.assertTupleAlmostEquals(jern.line @ 1, (0, 1, 0), 5)
self.assertAlmostEqual(j1.radius, 1)
self.assertAlmostEqual(j1.length, pi / 2)
with BuildLine(Plane.XY.offset(1)) as offset_l:
off1 = JernArc((1, 0), (0, 1), 1, 90)
self.assertTupleAlmostEquals((offset_l.line @ 1).to_tuple(), (0, 1, 1), 5)
self.assertTupleAlmostEquals(offset_l.line @ 1, (0, 1, 1), 5)
self.assertAlmostEqual(off1.radius, 1)
self.assertAlmostEqual(off1.length, pi / 2)
plane_iso = Plane(origin=(0, 0, 0), x_dir=(1, 1, 0), z_dir=(1, -1, 1))
with BuildLine(plane_iso) as iso_l:
iso1 = JernArc((0, 0), (0, 1), 1, 180)
self.assertTupleAlmostEquals(
(iso_l.line @ 1).to_tuple(), (-sqrt(2), -sqrt(2), 0), 5
)
self.assertTupleAlmostEquals(iso_l.line @ 1, (-sqrt(2), -sqrt(2), 0), 5)
self.assertAlmostEqual(iso1.radius, 1)
self.assertAlmostEqual(iso1.length, pi)
@ -240,11 +238,11 @@ class BuildLineTests(unittest.TestCase):
self.assertFalse(l2.is_closed)
circle_face = Face(Wire([l1]))
self.assertAlmostEqual(circle_face.area, pi, 5)
self.assertTupleAlmostEquals(circle_face.center().to_tuple(), (0, 1, 0), 5)
self.assertTupleAlmostEquals(l1.vertex().to_tuple(), l2.start.to_tuple(), 5)
self.assertTupleAlmostEquals(circle_face.center(), (0, 1, 0), 5)
self.assertTupleAlmostEquals(l1.vertex(), l2.start, 5)
l1 = JernArc((0, 0), (1, 0), 1, 90)
self.assertTupleAlmostEquals((l1 @ 1).to_tuple(), (1, 1, 0), 5)
self.assertTupleAlmostEquals(l1 @ 1, (1, 1, 0), 5)
self.assertTrue(isinstance(l1, Edge))
def test_polar_line(self):
@ -252,38 +250,38 @@ class BuildLineTests(unittest.TestCase):
with BuildLine():
a1 = PolarLine((0, 0), sqrt(2), 45)
d1 = PolarLine((0, 0), sqrt(2), direction=(1, 1))
self.assertTupleAlmostEquals((a1 @ 1).to_tuple(), (1, 1, 0), 5)
self.assertTupleAlmostEquals((a1 @ 1).to_tuple(), (d1 @ 1).to_tuple(), 5)
self.assertTupleAlmostEquals(a1 @ 1, (1, 1, 0), 5)
self.assertTupleAlmostEquals(a1 @ 1, d1 @ 1, 5)
self.assertTrue(isinstance(a1, Edge))
self.assertTrue(isinstance(d1, Edge))
with BuildLine():
a2 = PolarLine((0, 0), 1, 30)
d2 = PolarLine((0, 0), 1, direction=(sqrt(3), 1))
self.assertTupleAlmostEquals((a2 @ 1).to_tuple(), (sqrt(3) / 2, 0.5, 0), 5)
self.assertTupleAlmostEquals((a2 @ 1).to_tuple(), (d2 @ 1).to_tuple(), 5)
self.assertTupleAlmostEquals(a2 @ 1, (sqrt(3) / 2, 0.5, 0), 5)
self.assertTupleAlmostEquals(a2 @ 1, d2 @ 1, 5)
with BuildLine():
a3 = PolarLine((0, 0), 1, 150)
d3 = PolarLine((0, 0), 1, direction=(-sqrt(3), 1))
self.assertTupleAlmostEquals((a3 @ 1).to_tuple(), (-sqrt(3) / 2, 0.5, 0), 5)
self.assertTupleAlmostEquals((a3 @ 1).to_tuple(), (d3 @ 1).to_tuple(), 5)
self.assertTupleAlmostEquals(a3 @ 1, (-sqrt(3) / 2, 0.5, 0), 5)
self.assertTupleAlmostEquals(a3 @ 1, d3 @ 1, 5)
with BuildLine():
a4 = PolarLine((0, 0), 1, angle=30, length_mode=LengthMode.HORIZONTAL)
d4 = PolarLine(
(0, 0), 1, direction=(sqrt(3), 1), length_mode=LengthMode.HORIZONTAL
)
self.assertTupleAlmostEquals((a4 @ 1).to_tuple(), (1, 1 / sqrt(3), 0), 5)
self.assertTupleAlmostEquals((a4 @ 1).to_tuple(), (d4 @ 1).to_tuple(), 5)
self.assertTupleAlmostEquals(a4 @ 1, (1, 1 / sqrt(3), 0), 5)
self.assertTupleAlmostEquals(a4 @ 1, d4 @ 1, 5)
with BuildLine(Plane.XZ):
a5 = PolarLine((0, 0), 1, angle=30, length_mode=LengthMode.VERTICAL)
d5 = PolarLine(
(0, 0), 1, direction=(sqrt(3), 1), length_mode=LengthMode.VERTICAL
)
self.assertTupleAlmostEquals((a5 @ 1).to_tuple(), (sqrt(3), 0, 1), 5)
self.assertTupleAlmostEquals((a5 @ 1).to_tuple(), (d5 @ 1).to_tuple(), 5)
self.assertTupleAlmostEquals(a5 @ 1, (sqrt(3), 0, 1), 5)
self.assertTupleAlmostEquals(a5 @ 1, d5 @ 1, 5)
with self.assertRaises(ValueError):
PolarLine((0, 0), 1)
@ -292,7 +290,7 @@ class BuildLineTests(unittest.TestCase):
"""Test spline with no tangents"""
with BuildLine() as test:
s1 = Spline((0, 0), (1, 1), (2, 0))
self.assertTupleAlmostEquals((test.edges()[0] @ 1).to_tuple(), (2, 0, 0), 5)
self.assertTupleAlmostEquals(test.edges()[0] @ 1, (2, 0, 0), 5)
self.assertTrue(isinstance(s1, Edge))
def test_radius_arc(self):
@ -333,19 +331,17 @@ class BuildLineTests(unittest.TestCase):
"""Test center arc as arc and circle"""
with BuildLine() as arc:
CenterArc((0, 0), 10, 0, 180)
self.assertTupleAlmostEquals((arc.edges()[0] @ 1).to_tuple(), (-10, 0, 0), 5)
self.assertTupleAlmostEquals(arc.edges()[0] @ 1, (-10, 0, 0), 5)
with BuildLine() as arc:
CenterArc((0, 0), 10, 0, 360)
self.assertTupleAlmostEquals(
(arc.edges()[0] @ 0).to_tuple(), (arc.edges()[0] @ 1).to_tuple(), 5
)
self.assertTupleAlmostEquals(arc.edges()[0] @ 0, arc.edges()[0] @ 1, 5)
with BuildLine(Plane.XZ) as arc:
CenterArc((0, 0), 10, 0, 360)
self.assertTrue(Face(arc.wires()[0]).is_coplanar(Plane.XZ))
with BuildLine(Plane.XZ) as arc:
CenterArc((-100, 0), 100, -45, 90)
self.assertTupleAlmostEquals((arc.edges()[0] @ 0.5).to_tuple(), (0, 0, 0), 5)
self.assertTupleAlmostEquals(arc.edges()[0] @ 0.5, (0, 0, 0), 5)
arc = CenterArc((-100, 0), 100, 0, 360)
self.assertTrue(Face(Wire([arc])).is_coplanar(Plane.XY))

View file

@ -92,9 +92,7 @@ class TestBuildSketch(unittest.TestCase):
with BuildLine():
l1 = Line((0, 0), (10, 0))
Line(l1 @ 1, (10, 10))
self.assertTupleAlmostEquals(
(test.consolidate_edges() @ 1).to_tuple(), (10, 10, 0), 5
)
self.assertTupleAlmostEquals(test.consolidate_edges() @ 1, (10, 10, 0), 5)
def test_mode_intersect(self):
with BuildSketch() as test:
@ -263,9 +261,7 @@ class TestBuildSketchObjects(unittest.TestCase):
self.assertEqual(r.align, (Align.CENTER, Align.CENTER))
self.assertEqual(r.mode, Mode.ADD)
self.assertAlmostEqual(test.sketch.area, (3 * sqrt(3) / 2) * 2**2, 5)
self.assertTupleAlmostEquals(
test.sketch.faces()[0].normal_at().to_tuple(), (0, 0, 1), 5
)
self.assertTupleAlmostEquals(test.sketch.faces()[0].normal_at(), (0, 0, 1), 5)
self.assertAlmostEqual(r.apothem, 2 * sqrt(3) / 2)
def test_regular_polygon_minor_radius(self):
@ -277,9 +273,7 @@ class TestBuildSketchObjects(unittest.TestCase):
self.assertEqual(r.align, (Align.CENTER, Align.CENTER))
self.assertEqual(r.mode, Mode.ADD)
self.assertAlmostEqual(test.sketch.area, (3 * sqrt(3) / 4) * (0.5 * 2) ** 2, 5)
self.assertTupleAlmostEquals(
test.sketch.faces()[0].normal_at().to_tuple(), (0, 0, 1), 5
)
self.assertTupleAlmostEquals(test.sketch.faces()[0].normal_at(), (0, 0, 1), 5)
def test_regular_polygon_align(self):
with BuildSketch() as align:
@ -303,7 +297,7 @@ class TestBuildSketchObjects(unittest.TestCase):
poly_pts = [Vector(v) for v in regular_poly.vertices()]
polar_pts = [p.position for p in PolarLocations(1, side_count)]
for poly_pt, polar_pt in zip(poly_pts, polar_pts):
self.assertTupleAlmostEquals(poly_pt.to_tuple(), polar_pt.to_tuple(), 5)
self.assertTupleAlmostEquals(poly_pt, polar_pt, 5)
def test_regular_polygon_min_sides(self):
with self.assertRaises(ValueError):
@ -325,8 +319,8 @@ class TestBuildSketchObjects(unittest.TestCase):
def test_slot_center_point(self):
with BuildSketch() as test:
s = SlotCenterPoint((0, 0), (2, 0), 2)
self.assertTupleAlmostEquals(s.slot_center.to_tuple(), (0, 0, 0), 5)
self.assertTupleAlmostEquals(s.point.to_tuple(), (2, 0, 0), 5)
self.assertTupleAlmostEquals(s.slot_center, (0, 0, 0), 5)
self.assertTupleAlmostEquals(s.point, (2, 0, 0), 5)
self.assertEqual(s.slot_height, 2)
self.assertEqual(s.rotation, 0)
self.assertEqual(s.mode, Mode.ADD)

View file

@ -192,7 +192,7 @@ class TestAxis(unittest.TestCase):
self.assertIsNone(Axis.X.intersect(Axis((0, 1, 1), (0, 0, 1))))
intersection = Axis((1, 2, 3), (0, 0, 1)) & Plane.XY
self.assertAlmostEqual(intersection.to_tuple(), (1, 2, 0), 5)
self.assertAlmostEqual(intersection, (1, 2, 0), 5)
arc = Edge.make_circle(20, start_angle=0, end_angle=180)
ax0 = Axis((-20, 30, 0), (4, -3, 0))
@ -226,10 +226,10 @@ class TestAxis(unittest.TestCase):
# self.assertTrue(len(intersections.vertices(), 2))
# np.testing.assert_allclose(
# intersection.vertices()[0].to_tuple(), (-1, 0, 5), 5
# intersection.vertices()[0], (-1, 0, 5), 5
# )
# np.testing.assert_allclose(
# intersection.vertices()[1].to_tuple(), (1, 0, 5), 5
# intersection.vertices()[1], (1, 0, 5), 5
# )
def test_axis_equal(self):

View file

@ -234,7 +234,7 @@ class TestEdge(unittest.TestCase):
for i, loc in enumerate(locs):
self.assertAlmostEqual(
loc.position,
Vector(1, 0, 0).rotate(Axis.Z, i * 90).to_tuple(),
Vector(1, 0, 0).rotate(Axis.Z, i * 90),
5,
)
self.assertAlmostEqual(loc.orientation, (0, 0, 0), 5)

View file

@ -265,10 +265,10 @@ class TestLocation(unittest.TestCase):
loc1 = Location((1, 2, 3), (90, 45, 22.5))
loc2 = copy.copy(loc1)
loc3 = copy.deepcopy(loc1)
self.assertAlmostEqual(loc1.position, loc2.position.to_tuple(), 6)
self.assertAlmostEqual(loc1.orientation, loc2.orientation.to_tuple(), 6)
self.assertAlmostEqual(loc1.position, loc3.position.to_tuple(), 6)
self.assertAlmostEqual(loc1.orientation, loc3.orientation.to_tuple(), 6)
self.assertAlmostEqual(loc1.position, loc2.position, 6)
self.assertAlmostEqual(loc1.orientation, loc2.orientation, 6)
self.assertAlmostEqual(loc1.position, loc3.position, 6)
self.assertAlmostEqual(loc1.orientation, loc3.orientation, 6)
# deprecated
# def test_to_axis(self):

View file

@ -53,10 +53,8 @@ class TestMixin1D(unittest.TestCase):
5,
)
# Not sure what PARAMETER mode returns - but it's in the ballpark
point = (
Edge.make_line((0, 0, 0), (1, 1, 1))
.position_at(0.5, position_mode=PositionMode.PARAMETER)
.to_tuple()
point = Edge.make_line((0, 0, 0), (1, 1, 1)).position_at(
0.5, position_mode=PositionMode.PARAMETER
)
self.assertTrue(all([0.0 < v < 1.0 for v in point]))
@ -119,10 +117,8 @@ class TestMixin1D(unittest.TestCase):
(-1, 0, 0),
5,
)
tangent = (
Edge.make_circle(1, start_angle=0, end_angle=90)
.tangent_at(0.0, position_mode=PositionMode.PARAMETER)
.to_tuple()
tangent = Edge.make_circle(1, start_angle=0, end_angle=90).tangent_at(
0.0, position_mode=PositionMode.PARAMETER
)
self.assertTrue(all([0.0 <= v <= 1.0 for v in tangent]))

View file

@ -275,8 +275,8 @@ class TestPlane(unittest.TestCase):
def test_localize_vertex(self):
vertex = Vertex(random.random(), random.random(), random.random())
np.testing.assert_allclose(
Plane.YZ.to_local_coords(vertex).to_tuple(),
Plane.YZ.to_local_coords(Vector(vertex)).to_tuple(),
tuple(Plane.YZ.to_local_coords(vertex)),
tuple(Plane.YZ.to_local_coords(Vector(vertex))),
5,
)

View file

@ -317,8 +317,8 @@ class TestShape(unittest.TestCase):
c0 = Edge.make_circle(1).locate(Location((0, 2.1, 0)))
c1 = Edge.make_circle(1)
closest = c0.closest_points(c1)
self.assertAlmostEqual(closest[0], c0.position_at(0.75).to_tuple(), 5)
self.assertAlmostEqual(closest[1], c1.position_at(0.25).to_tuple(), 5)
self.assertAlmostEqual(closest[0], c0.position_at(0.75), 5)
self.assertAlmostEqual(closest[1], c1.position_at(0.25), 5)
def test_distance_to(self):
c0 = Edge.make_circle(1).locate(Location((0, 2.1, 0)))