-
Notifications
You must be signed in to change notification settings - Fork 108
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
Update/rhino point conversion #1346
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -103,14 +103,19 @@ def point_to_compas(point): | |||||||||||||||||||||||||
|
||||||||||||||||||||||||||
Parameters | ||||||||||||||||||||||||||
---------- | ||||||||||||||||||||||||||
point : :rhino:`Rhino.Geometry.Point3d` | ||||||||||||||||||||||||||
point : :rhino:`Rhino.Geometry.Point3d` | :rhino:`Rhino.Geometry.Point` | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
Returns | ||||||||||||||||||||||||||
------- | ||||||||||||||||||||||||||
:class:`compas.geometry.Point` | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||
return Point(point.X, point.Y, point.Z) | ||||||||||||||||||||||||||
if isinstance(point, Rhino.Geometry.Point3d): | ||||||||||||||||||||||||||
return Point(point.X, point.Y, point.Z) | ||||||||||||||||||||||||||
elif isinstance(point, Rhino.Geometry.Point): | ||||||||||||||||||||||||||
return Point(point.Location.X, point.Location.Y, point.Location.Z) | ||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||
raise TypeError("Expected Rhino.Geometry.Point3d or Rhino.Geometry.Point., got: {}".format(type(point))) | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of relying on type checking, I would rely on "feature checking". Something like this maybe?
Suggested change
Or maybe not even that, maybe just try..except idiom: try:
return Point(point.X, point.Y, point.Z)
except MissingMemberException:
try:
return Point(point.Location.X, point.Location.Y, point.Location.Z)
except MissingMemberException:
raise TypeError("Unexpected point type, got: {}".format(type(point))) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good! using try except now |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
def vector_to_compas(vector): | ||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean
to allow for `Rhino.Geometry.Point` as input.
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!