Deprecating Vertex.to_tuple - Issue #155
Some checks are pending
benchmarks / benchmarks (macos-13, 3.12) (push) Waiting to run
benchmarks / benchmarks (macos-14, 3.12) (push) Waiting to run
benchmarks / benchmarks (ubuntu-latest, 3.12) (push) Waiting to run
benchmarks / benchmarks (windows-latest, 3.12) (push) Waiting to run
Upload coverage reports to Codecov / run (push) Waiting to run
pylint / lint (3.10) (push) Waiting to run
Run type checker / typecheck (3.10) (push) Waiting to run
Run type checker / typecheck (3.13) (push) Waiting to run
Wheel building and publishing / Build wheel on ubuntu-latest (push) Waiting to run
Wheel building and publishing / upload_pypi (push) Blocked by required conditions
tests / tests (macos-13, 3.10) (push) Waiting to run
tests / tests (macos-13, 3.13) (push) Waiting to run
tests / tests (macos-14, 3.10) (push) Waiting to run
tests / tests (macos-14, 3.13) (push) Waiting to run
tests / tests (ubuntu-latest, 3.10) (push) Waiting to run
tests / tests (ubuntu-latest, 3.13) (push) Waiting to run
tests / tests (windows-latest, 3.10) (push) Waiting to run
tests / tests (windows-latest, 3.13) (push) Waiting to run

This commit is contained in:
gumyr 2025-05-26 21:02:01 -04:00
parent 2e0c193aa8
commit ce3e6ba3a4
8 changed files with 32 additions and 45 deletions

View file

@ -1111,7 +1111,7 @@ class Locations(LocationList):
elif isinstance(point, Vector):
local_locations.append(Location(point))
elif isinstance(point, Vertex):
local_locations.append(Location(Vector(point.to_tuple())))
local_locations.append(Location(Vector(point)))
elif isinstance(point, tuple):
local_locations.append(Location(Vector(point)))
elif isinstance(point, Plane):

View file

@ -277,10 +277,7 @@ class Draft:
if isinstance(path, (Edge, Wire)):
processed_path = path
elif isinstance(path, Iterable):
pnts = [
Vector(p.to_tuple()) if isinstance(p, Vertex) else Vector(p)
for p in path
]
pnts = [Vector(p) for p in path]
if len(pnts) == 2:
processed_path = Edge.make_line(*pnts)
else:

View file

@ -32,7 +32,7 @@ import copy as copy_module
from collections.abc import Iterable
from math import copysign, cos, radians, sin, sqrt
from scipy.optimize import minimize
import sympy # type: ignore
import sympy # type: ignore
from build123d.build_common import WorkplaneList, flatten_sequence, validate_inputs
from build123d.build_enums import (
@ -564,7 +564,7 @@ class FilletPolyline(BaseLineObject):
if len(edges) != 2:
continue
other_vertices = {ve for e in edges for ve in e.vertices() if ve != vertex}
third_edge = Edge.make_line(*[v.to_tuple() for v in other_vertices])
third_edge = Edge.make_line(*[v for v in other_vertices])
fillet_face = Face(Wire(edges + [third_edge])).fillet_2d(radius, [vertex])
fillets.append(fillet_face.edges().filter_by(GeomType.CIRCLE)[0])
@ -1095,9 +1095,7 @@ class PointArcTangentLine(BaseEdgeObject):
tangent_point = WorkplaneList.localize(point)
if context is None:
# Making the plane validates points and arc are coplanar
coplane = Edge.make_line(tangent_point, arc.arc_center).common_plane(
arc
)
coplane = Edge.make_line(tangent_point, arc.arc_center).common_plane(arc)
if coplane is None:
raise ValueError("PointArcTangentLine only works on a single plane.")

View file

@ -376,14 +376,8 @@ def chamfer(
object_list = ShapeList(
filter(
lambda v: not (
isclose_b(
(Vector(*v.to_tuple()) - target.position_at(0)).length,
0.0,
)
or isclose_b(
(Vector(*v.to_tuple()) - target.position_at(1)).length,
0.0,
)
isclose_b((Vector(v) - target.position_at(0)).length, 0.0)
or isclose_b((Vector(v) - target.position_at(1)).length, 0.0)
),
object_list,
)
@ -479,14 +473,8 @@ def fillet(
object_list = ShapeList(
filter(
lambda v: not (
isclose_b(
(Vector(*v.to_tuple()) - target.position_at(0)).length,
0.0,
)
or isclose_b(
(Vector(*v.to_tuple()) - target.position_at(1)).length,
0.0,
)
isclose_b((Vector(v) - target.position_at(0)).length, 0.0)
or isclose_b((Vector(v) - target.position_at(1)).length, 0.0)
),
object_list,
)

View file

@ -392,12 +392,10 @@ def make_brake_formed(
raise TypeError("station_widths must be either a single number or an iterable")
for vertex in line_vertices:
others = offset_vertices.sort_by_distance(Vector(vertex.X, vertex.Y, vertex.Z))
others = offset_vertices.sort_by_distance(Vector(vertex))
for other in others[1:]:
if abs(Vector(*(vertex - other).to_tuple()).length - thickness) < 1e-2:
station_edges.append(
Edge.make_line(vertex.to_tuple(), other.to_tuple())
)
if abs(Vector((vertex - other)).length - thickness) < 1e-2:
station_edges.append(Edge.make_line(vertex, other))
break
station_edges = station_edges.sort_by(line)

View file

@ -54,6 +54,8 @@ license:
from __future__ import annotations
import itertools
import warnings
from typing import overload, TYPE_CHECKING
from collections.abc import Iterable
@ -132,7 +134,8 @@ class Vertex(Shape[TopoDS_Vertex]):
)
super().__init__(ocp_vx)
self.X, self.Y, self.Z = self.to_tuple()
pnt = BRep_Tool.Pnt_s(self.wrapped)
self.X, self.Y, self.Z = pnt.X(), pnt.Y(), pnt.Z()
# ---- Properties ----
@ -272,6 +275,12 @@ class Vertex(Shape[TopoDS_Vertex]):
def to_tuple(self) -> tuple[float, float, float]:
"""Return vertex as three tuple of floats"""
warnings.warn(
"to_tuple is deprecated and will be removed in a future version. "
"Use 'tuple(Vertex)' instead.",
DeprecationWarning,
stacklevel=2,
)
geom_point = BRep_Tool.Pnt_s(self.wrapped)
return (geom_point.X(), geom_point.Y(), geom_point.Z())

View file

@ -435,27 +435,25 @@ class TestRotation(unittest.TestCase):
def test_init(self):
thirty_by_three = Rotation(30, 30, 30)
box_vertices = Solid.make_box(1, 1, 1).moved(thirty_by_three).vertices()
self.assertTupleAlmostEquals(tuple(box_vertices[0]), (0.5, -0.4330127, 0.75), 5)
self.assertTupleAlmostEquals(tuple(box_vertices[1]), (0.0, 0.0, 0.0), 7)
self.assertTupleAlmostEquals(
box_vertices[0].to_tuple(), (0.5, -0.4330127, 0.75), 5
)
self.assertTupleAlmostEquals(box_vertices[1].to_tuple(), (0.0, 0.0, 0.0), 7)
self.assertTupleAlmostEquals(
box_vertices[2].to_tuple(), (0.0669872, 0.191987, 1.399519), 5
tuple(box_vertices[2]), (0.0669872, 0.191987, 1.399519), 5
)
self.assertTupleAlmostEquals(
box_vertices[3].to_tuple(), (-0.4330127, 0.625, 0.6495190), 5
tuple(box_vertices[3]), (-0.4330127, 0.625, 0.6495190), 5
)
self.assertTupleAlmostEquals(
box_vertices[4].to_tuple(), (1.25, 0.2165063, 0.625), 5
tuple(box_vertices[4]), (1.25, 0.2165063, 0.625), 5
)
self.assertTupleAlmostEquals(
box_vertices[5].to_tuple(), (0.75, 0.649519, -0.125), 5
tuple(box_vertices[5]), (0.75, 0.649519, -0.125), 5
)
self.assertTupleAlmostEquals(
box_vertices[6].to_tuple(), (0.816987, 0.841506, 1.274519), 5
tuple(box_vertices[6]), (0.816987, 0.841506, 1.274519), 5
)
self.assertTupleAlmostEquals(
box_vertices[7].to_tuple(), (0.3169872, 1.2745190, 0.52451905), 5
tuple(box_vertices[7]), (0.3169872, 1.2745190, 0.52451905), 5
)

View file

@ -32,7 +32,6 @@ import math
import re
import unittest
import numpy as np
from IPython.lib import pretty
from build123d.build_common import GridLocations, PolarLocations
from build123d.build_enums import GeomType, SortBy
@ -304,7 +303,7 @@ class TestShapeList(unittest.TestCase):
def test_vertex(self):
sl = ShapeList([Edge.make_circle(1)])
np.testing.assert_allclose(sl.vertex().to_tuple(), (1, 0, 0), 1e-5)
self.assertAlmostEqual(tuple(sl.vertex()), (1, 0, 0), 5)
sl = ShapeList([Face.make_rect(1, 1), Face.make_rect(1, 1, Plane((4, 4)))])
with self.assertWarns(UserWarning):
sl.vertex()