plane_to_rhino bug: add missing y-axis vector argument#1505
plane_to_rhino bug: add missing y-axis vector argument#1505jwwang0-0 wants to merge 1 commit intocompas-dev:mainfrom
Conversation
|
|
||
| """ | ||
| return Rhino.Geometry.Plane(point_to_rhino(plane[0]), vector_to_rhino(plane[1])) | ||
| return Rhino.Geometry.Plane(point_to_rhino(plane[0]), vector_to_rhino(plane[1]), vector_to_rhino(plane[2])) |
There was a problem hiding this comment.
a COMPAS plane only has a point and a normal (it is not a frame). index 0 will return the base point, and index 1, the normal.
accessing index 2 on a plane object will raise a KeyError.
There was a problem hiding this comment.
the redirection to the constructor that uses a point and a normal is correct. i think the functionality you are looking for is frame_to_rhino...
There was a problem hiding this comment.
Oh, thank you for the explanation! I'm wrong. That makes sense. I think it would be better to include a data type check in the code to verify whether the input is a compas_plane or a compas_frame. As it stands, it’s a bit confusing, especially since in Rhino plane is defined in a way that’s more similar to a compas_frame.
There was a problem hiding this comment.
Pull request overview
This PR attempts to fix a bug in the plane_to_rhino() function by adding a third argument (y-axis vector) to the Rhino.Geometry.Plane constructor. The PR author correctly identifies that the Rhino.Geometry.Plane constructor with 3 arguments requires (origin, xaxis, yaxis) rather than using the 2-argument constructor (origin, normal).
However, the proposed fix is critically flawed and will cause a runtime error. COMPAS Plane objects only contain 2 elements: a point and a normal vector. The fix attempts to access plane[2], which doesn't exist and will raise a KeyError. The correct approach requires converting the COMPAS Plane to a Frame first using Frame.from_plane(), which computes the xaxis and yaxis from the normal, then passing those to the Rhino constructor as demonstrated in the existing frame_to_rhino_plane() function.
Key Issues
- The code will crash with a KeyError when trying to access
plane[2] - COMPAS Plane has
__len__() = 2and__getitem__()only supports indices 0 (point) and 1 (normal) - The fix needs to compute xaxis/yaxis from the plane's normal using
Frame.from_plane()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Should we close this? Or is anyone planning to add the type check as a fix instead? |
|
I don't think there is anything to be fixed... it is true that the plane/frame thing in relation to rhino is confusing, but that is because rhino doesn't distinguish between the two. i think it can be closed... |
What type of change is this?
This PR fixes an issue where plane_to_rhino() constructed a Rhino.Geometry.Plane with only two arguments (origin point + x-axis). Rhino’s Plane constructor requires three arguments:
The current code will direct to another constructor :
public Plane(
[Point3d ] origin
[Vector3d ] normal
)
And will cause troubles like
Checklist
Put an
xin the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.CHANGELOG.mdfile in theUnreleasedsection under the most fitting heading (e.g.Added,Changed,Removed).invoke test).invoke lint).compas.datastructures.Mesh.