Skip to content

Commit

Permalink
Merge pull request #1159 from hannobraun/intersection
Browse files Browse the repository at this point in the history
Add `HorizontalRayToTheRight::direction`
  • Loading branch information
hannobraun authored Sep 30, 2022
2 parents ccd97c3 + bbe501f commit 37c3382
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
11 changes: 10 additions & 1 deletion crates/fj-kernel/src/algorithms/intersect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod face_face;
mod line_segment;
mod surface_surface;

use fj_math::Point;
use fj_math::{Point, Vector};

pub use self::{
curve_edge::CurveEdgeIntersection,
Expand Down Expand Up @@ -45,6 +45,15 @@ pub struct HorizontalRayToTheRight<const D: usize> {
pub origin: Point<D>,
}

impl<const D: usize> HorizontalRayToTheRight<D> {
/// Access the direction of this ray
pub fn direction(&self) -> Vector<D> {
let mut components = [0.; D];
components[0] = 1.;
components.into()
}
}

impl<P, const D: usize> From<P> for HorizontalRayToTheRight<D>
where
P: Into<Point<D>>,
Expand Down
6 changes: 2 additions & 4 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Intersection between a ray and a face, in 3D
use fj_math::{Point, Scalar, Vector};
use fj_math::{Point, Scalar};

use crate::{
algorithms::intersect::face_point::FacePointIntersection,
Expand Down Expand Up @@ -28,9 +28,7 @@ impl Intersect for (&HorizontalRayToTheRight<3>, &Face) {

let plane_and_ray_are_parallel = {
let plane_normal = plane_direction_1.cross(&plane_direction_2);
let ray_direction = Vector::from([1., 0., 0.]);

plane_normal.dot(&ray_direction) == Scalar::ZERO
plane_normal.dot(&ray.direction()) == Scalar::ZERO
};

if plane_and_ray_are_parallel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ fn plane_from_surface(surface: &Surface) -> Plane {
#[cfg(test)]
mod tests {
use fj_math::Transform;
use pretty_assertions::assert_eq;

use crate::{
algorithms::transform::TransformObject,
Expand Down

0 comments on commit 37c3382

Please sign in to comment.