Repository: bevyengine/bevy
File: crates/bevy_math/src/ray.rs (Rust)

Code before:
    }

    /// Returns the point at a given distance along the ray
    #[inline]
    pub fn get_point(&self, distance: f32) -> Vec3 {
        self.origin + *self.direction * distance
    }

    /// Returns the distance to a plane if the ray intersects it
    ///
    /// Use [`Ray3d::plane_intersection_point`] to get the intersection point directly.
    #[inline]
    pub fn intersect_plane(&self, plane_origin: Vec3, plane: InfinitePlane3d) -> Option<f32> {
        let denominator = plane.normal.dot(*self.direction);
        if ops::abs(denominator) > f32::EPSILON {
            let distance = (plane_origin - self.origin).dot(*plane.normal) / denominator;
            if distance > f32::EPSILON {
                return Some(distance);
            }
        }
        None
    }

    /// Returns the intersection point of the ray with a plane, if it exists.
    ///
    ///  Calls [`Ray3d::get_point`] on the result of [`Ray3d::intersect_plane`].
    #[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)]
mod tests {
    use super::*;

    #[test]
    fn intersect_plane_2d() {
        let ray = Ray2d::new(Vec2::ZERO, Dir2::Y);

        // Orthogonal, and test that an inverse plane_normal has the same result
        assert_eq!(
            ray.intersect_plane(Vec2::Y, Plane2d::new(Vec2::Y)),
            Some(1.0)
        );
        assert_eq!(

Review comment (suggestion):
```suggestion
    /// Calls [`Ray3d::get_point`] on the result of [`Ray3d::intersect_plane`].
```

Code after:
    }

    /// Returns the point at a given distance along the ray
    #[inline]
    pub fn get_point(&self, distance: f32) -> Vec3 {
        self.origin + *self.direction * distance
    }

    /// Returns the distance to a plane if the ray intersects it
    ///
    /// Use [`Ray3d::plane_intersection_point`] to get the intersection point directly.
    #[inline]
    pub fn intersect_plane(&self, plane_origin: Vec3, plane: InfinitePlane3d) -> Option<f32> {
        let denominator = plane.normal.dot(*self.direction);
        if ops::abs(denominator) > f32::EPSILON {
            let distance = (plane_origin - self.origin).dot(*plane.normal) / denominator;
            if distance > f32::EPSILON {
                return Some(distance);
            }
        }
        None
    }

    /// Returns the intersection point of the ray with a plane, if it exists.
    ///
    /// Calls [`Ray3d::get_point`] on the result of [`Ray3d::intersect_plane`].
    #[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)]
mod tests {
    use super::*;

    #[test]
    fn intersect_plane_2d() {
        let ray = Ray2d::new(Vec2::ZERO, Dir2::Y);

        // Orthogonal, and test that an inverse plane_normal has the same result
        assert_eq!(
            ray.intersect_plane(Vec2::Y, Plane2d::new(Vec2::Y)),
            Some(1.0)
        );
        assert_eq!(