Skip to content

Commit bb67f2c

Browse files
extend _findFromPoint to support Vertex (#1853)
* extend _findFromPoint to support Vertex * Add one test * Black fix * Improve coverage * Switch to ValueError
1 parent e28eae4 commit bb67f2c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

cadquery/cq.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1413,8 +1413,10 @@ def _findFromPoint(self, useLocalCoords: bool = False) -> Vector:
14131413
p = obj.endPoint()
14141414
elif isinstance(obj, Vector):
14151415
p = obj
1416+
elif isinstance(obj, Vertex):
1417+
p = obj.Center()
14161418
else:
1417-
raise RuntimeError("Cannot convert object type '%s' to vector " % type(obj))
1419+
raise ValueError(f"Cannot convert object type {type(obj)} to vector.")
14181420

14191421
if useLocalCoords:
14201422
return self.plane.toLocalCoords(p)

tests/test_cadquery.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5917,3 +5917,15 @@ def test_compound_faces_center(self):
59175917
), "Incorrect center of mass of the compound, expected {}, got {}".format(
59185918
expected_center, compound.Center()
59195919
)
5920+
5921+
def test_line_from_vertex(self):
5922+
5923+
# select one vertex and create an Edge
5924+
res = Workplane().rect(1, 1).vertices(">(1,1,0)").line(1, 0)
5925+
5926+
# check if an Edge was created
5927+
assert isinstance(res.val(), Edge)
5928+
5929+
# check that errors are handled
5930+
with raises(ValueError):
5931+
Workplane().box(1, 1, 1).line(1, 0)

0 commit comments

Comments
 (0)