-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Add Ray.plane_intersection_point to simplify example code #22381
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
Merged
+37
−14
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
077c129
Added plane_intersection_point
nicebenny23 869ac7b
Added plane_intersection_point
nicebenny23 c637493
Added plane_intersection_point
nicebenny23 40d2135
Added plane_intersection_point
nicebenny23 47d22e6
Delete .idea directory
nicebenny23 6e3e4b0
Added plane_intersection_point
nicebenny23 b317afd
improved documentation slightly
nicebenny23 4bcba84
fixed formating
nicebenny23 6ceaff0
forgot to add formatting fix
nicebenny23 9e0ff4b
improved comments
nicebenny23 4bae3fa
fixed comments
nicebenny23 a53345e
Whitespace cleanup
alice-i-cecile File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,19 +29,19 @@ pub struct Ray2d { | |
| } | ||
|
|
||
| impl Ray2d { | ||
| /// Create a new `Ray2d` from a given origin and direction | ||
| /// Creates a new `Ray2d` from a given origin and direction | ||
| #[inline] | ||
| pub const fn new(origin: Vec2, direction: Dir2) -> Self { | ||
| Self { origin, direction } | ||
| } | ||
|
|
||
| /// Get a point at a given distance along the ray | ||
| /// Returns the point at a given distance along the ray. | ||
| #[inline] | ||
| pub fn get_point(&self, distance: f32) -> Vec2 { | ||
| self.origin + *self.direction * distance | ||
| } | ||
|
|
||
| /// Get the distance to a plane if the ray intersects it | ||
| /// Returns the distance to a plane if the ray intersects it. | ||
| #[inline] | ||
| pub fn intersect_plane(&self, plane_origin: Vec2, plane: Plane2d) -> Option<f32> { | ||
| let denominator = plane.normal.dot(*self.direction); | ||
|
|
@@ -53,6 +53,13 @@ impl Ray2d { | |
| } | ||
| None | ||
| } | ||
|
|
||
| /// Returns the intersection point with a plane, if it exists. | ||
|
Member
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. These docs should call out that it's a combination of the other two methods. |
||
| #[inline] | ||
| pub fn plane_intersection_point(&self, plane_origin: Vec2, plane: Plane2d) -> Option<Vec2> { | ||
| self.intersect_plane(plane_origin, plane) | ||
| .map(|distance| self.get_point(distance)) | ||
| } | ||
| } | ||
|
|
||
| /// An infinite half-line starting at `origin` and going in `direction` in 3D space. | ||
|
|
@@ -75,19 +82,19 @@ pub struct Ray3d { | |
| } | ||
|
|
||
| impl Ray3d { | ||
| /// Create a new `Ray3d` from a given origin and direction | ||
| /// Creates a new `Ray3d` from a given origin and direction | ||
| #[inline] | ||
| pub const fn new(origin: Vec3, direction: Dir3) -> Self { | ||
| Self { origin, direction } | ||
| } | ||
|
|
||
| /// Get a point at a given distance along the ray | ||
| /// Returns the point at a given distance along the ray | ||
| #[inline] | ||
| pub fn get_point(&self, distance: f32) -> Vec3 { | ||
| self.origin + *self.direction * distance | ||
| } | ||
|
|
||
| /// Get the distance to a plane if the ray intersects it | ||
| /// Returns the distance to a plane if the ray intersects it | ||
| #[inline] | ||
| pub fn intersect_plane(&self, plane_origin: Vec3, plane: InfinitePlane3d) -> Option<f32> { | ||
| let denominator = plane.normal.dot(*self.direction); | ||
|
|
@@ -99,6 +106,17 @@ impl Ray3d { | |
| } | ||
| None | ||
| } | ||
|
|
||
| /// Returns the intersection point of the ray with a plane, if it exists. | ||
| #[inline] | ||
| pub fn plane_intersection_point( | ||
| &self, | ||
| plane_origin: Vec3, | ||
| plane: InfinitePlane3d, | ||
| ) -> Option<Vec3> { | ||
| self.intersect_plane(plane_origin, plane) | ||
| .map(|distance| self.get_point(distance)) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We should mention the new method here too :)