-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Improve Segment2d
/Segment3d
API and docs
#18206
Conversation
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.
Suggested some small changes.
Co-authored-by: Greeble <[email protected]>
Co-authored-by: Greeble <[email protected]>
@alice-i-cecile Those only changed the 2D methods so 3D is now inconsistent. I can fix it in a sec though |
Head branch was pushed to by a user without write access
Thank you very much @Jondolf :) |
Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke! If it's expected, please add the M-Deliberate-Rendering-Change label. If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it. |
Also I would prefer if the reversing method memswapped like what I originally had, since that's what I personally need for my use cases (e.g. I have a segment clipping algo where I need to sort features, which includes swapping things around). We could have both |
@Jondolf let's add both here. |
Done! Also added |
Much appreciated: you always do such excellent work. |
Objective
#17404 reworked the
Segment2d
andSegment3d
types to be defined by two endpoints rather than a direction and half-length. However, the API is still very minimal and limited, and documentation is inconsistent and outdated.Solution
Add the following helper methods for
Segment2d
andSegment3d
:from_scaled_direction
from_ray_and_length
length_squared
direction
try_direction
scaled_direction
transformed
reversed
Segment2d
has a few 2D-specific methods:left_normal
try_left_normal
scaled_left_normal
right_normal
try_right_normal
scaled_right_normal
There are now also
From
implementations for converting[Vec2; 2]
and(Vec2, Vec2)
to aSegment2d
, and similarly for 3D.I have also updated documentation to be more accurate and consistent, and simplified a few methods.
Prior Art
Parry's
Segment
type has a lot of similar methods, though my implementation is a bit more comprehensive. A lot of these methods can be useful for various geometry algorithms.