From 885832d5b214d3ce16d532c6d35ceb30387a5589 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 23 Feb 2024 12:53:24 +0100 Subject: [PATCH] Remove unused surface/surface intersection code --- .../fj-core/src/algorithms/intersect/mod.rs | 2 - .../algorithms/intersect/surface_surface.rs | 113 ------------------ 2 files changed, 115 deletions(-) delete mode 100644 crates/fj-core/src/algorithms/intersect/surface_surface.rs diff --git a/crates/fj-core/src/algorithms/intersect/mod.rs b/crates/fj-core/src/algorithms/intersect/mod.rs index 58acf0d8e..8a841efaa 100644 --- a/crates/fj-core/src/algorithms/intersect/mod.rs +++ b/crates/fj-core/src/algorithms/intersect/mod.rs @@ -7,7 +7,6 @@ pub mod ray_segment; mod curve_edge; mod curve_face; mod line_segment; -mod surface_surface; use fj_math::{Point, Vector}; @@ -15,7 +14,6 @@ pub use self::{ curve_edge::CurveEdgeIntersection, curve_face::{CurveFaceIntersection, CurveFaceIntersectionInterval}, line_segment::LineSegmentIntersection, - surface_surface::SurfaceSurfaceIntersection, }; /// Compute the intersection between a tuple of objects diff --git a/crates/fj-core/src/algorithms/intersect/surface_surface.rs b/crates/fj-core/src/algorithms/intersect/surface_surface.rs deleted file mode 100644 index a5be37894..000000000 --- a/crates/fj-core/src/algorithms/intersect/surface_surface.rs +++ /dev/null @@ -1,113 +0,0 @@ -use fj_math::{Line, Plane, Point, Scalar}; - -use crate::{ - geometry::{GlobalPath, SurfacePath}, - objects::Surface, - storage::Handle, -}; - -/// The intersection between two surfaces -#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] -pub struct SurfaceSurfaceIntersection { - /// The intersection curves - pub intersection_curves: [SurfacePath; 2], -} - -impl SurfaceSurfaceIntersection { - /// Compute the intersection between two surfaces - pub fn compute(surfaces: [Handle; 2]) -> Option { - // Algorithm from Real-Time Collision Detection by Christer Ericson. See - // section 5.4.4, Intersection of Two Planes. - // - // Adaptations were made to get the intersection curves in local - // coordinates for each surface. - - let planes = surfaces.map(|surface| plane_from_surface(&surface)); - - let [(a_distance, a_normal), (b_distance, b_normal)] = - planes.map(|plane| plane.constant_normal_form()); - - let direction = a_normal.cross(&b_normal); - - let denom = direction.dot(&direction); - if denom == Scalar::ZERO { - // Comparing `denom` against zero looks fishy. It's probably better - // to compare it against an epsilon value, but I don't know how - // large that epsilon should be. - // - // I'll just leave it like that, until we had the opportunity to - // collect some experience with this code. - // - @hannobraun - return None; - } - - let origin = (b_normal * a_distance - a_normal * b_distance) - .cross(&direction) - / denom; - let origin = Point { coords: origin }; - - let line = Line::from_origin_and_direction(origin, direction); - - let curves = - planes.map(|plane| SurfacePath::Line(plane.project_line(&line))); - - Some(Self { - intersection_curves: curves, - }) - } -} - -fn plane_from_surface(surface: &Surface) -> Plane { - let (line, path) = { - let line = match surface.geometry().u { - GlobalPath::Line(line) => line, - _ => todo!("Only plane-plane intersection is currently supported."), - }; - - (line, surface.geometry().v) - }; - - Plane::from_parametric(line.origin(), line.direction(), path) -} - -#[cfg(test)] -mod tests { - use fj_math::Transform; - use pretty_assertions::assert_eq; - - use crate::{ - geometry::SurfacePath, operations::transform::TransformObject, Core, - }; - - use super::SurfaceSurfaceIntersection; - - #[test] - fn plane_plane() { - let mut core = Core::new(); - - let xy = core.layers.objects.surfaces.xy_plane(); - let xz = core.layers.objects.surfaces.xz_plane(); - - // Coincident and parallel planes don't have an intersection curve. - assert_eq!( - SurfaceSurfaceIntersection::compute([ - xy.clone(), - xy.clone().transform( - &Transform::translation([0., 0., 1.],), - &mut core - ) - ],), - None, - ); - - let expected_xy = SurfacePath::u_axis(); - let expected_xz = SurfacePath::u_axis(); - - assert_eq!( - SurfaceSurfaceIntersection::compute([xy, xz],), - Some(SurfaceSurfaceIntersection { - intersection_curves: [expected_xy, expected_xz], - }) - ); - } -}