Skip to content

extend _findFromPoint to support Vertex #1853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cadquery/cq.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,8 @@ def _findFromPoint(self, useLocalCoords: bool = False) -> Vector:
p = obj.endPoint()
elif isinstance(obj, Vector):
p = obj
elif isinstance(obj, Vertex):
p = obj.Center()
else:
raise RuntimeError("Cannot convert object type '%s' to vector " % type(obj))

Expand Down
8 changes: 8 additions & 0 deletions tests/test_cadquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5917,3 +5917,11 @@ def test_compound_faces_center(self):
), "Incorrect center of mass of the compound, expected {}, got {}".format(
expected_center, compound.Center()
)

def test_line_from_vertex(self):

# select one vertex and create an Edge
res = Workplane().rect(1, 1).vertices(">(1,1,0)").line(1, 0)

# check if an Edge was created
assert isinstance(res.val(), Edge)