Skip to content
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

Merged
merged 3 commits into from
Apr 30, 2024
Merged

Update/rhino point conversion #1346

merged 3 commits into from
Apr 30, 2024

Conversation

Licini
Copy link
Contributor

@Licini Licini commented Apr 29, 2024

Small fix for #1343

CHANGELOG.md Outdated
@@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Changed use of `compas.geometry.allclose` to `compas.tolerance.TOL.is_allclose`.
* Changed use of `compas.geometry.close` to `compas.tolerance.TOL.is_close`.
* Changed imports of itertools to `compas.itertools` instead of `compas.utilities`.
* Updated `compas_rhino.conversions.point_to_compas` to allow for `compas.geometry.Point` as input.
Copy link
Member

@gonzalocasas gonzalocasas Apr 29, 2024

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.?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

Comment on lines 113 to 118
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)))
Copy link
Member

Choose a reason for hiding this comment

The 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
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)))
if hasattr(point, "X"):
return Point(point.X, point.Y, point.Z)
elif hasattr(point, "Location"):
return Point(point.Location.X, point.Location.Y, point.Location.Z)
else:
raise TypeError("Unexpected point type, got: {}".format(type(point)))

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)))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! using try except now

Copy link
Member

@gonzalocasas gonzalocasas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates!
LGTM!

@Licini Licini merged commit a11d447 into main Apr 30, 2024
17 checks passed
@Licini Licini deleted the update/rhino-point-conversion branch April 30, 2024 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants