From 34d251ce8f9c01bfe6a24583dc9edacb5ce77eaf Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Feb 2023 16:05:28 +0100 Subject: [PATCH] Merge `Curve` into `HalfEdge` --- .../fj-kernel/src/algorithms/approx/edge.rs | 11 ++++------ .../src/algorithms/intersect/curve_edge.rs | 2 +- .../src/algorithms/intersect/ray_edge.rs | 2 +- crates/fj-kernel/src/algorithms/sweep/edge.rs | 3 +-- crates/fj-kernel/src/algorithms/sweep/face.rs | 2 +- crates/fj-kernel/src/objects/full/curve.rs | 19 ------------------ crates/fj-kernel/src/objects/full/cycle.rs | 2 +- crates/fj-kernel/src/objects/full/edge.rs | 9 +++++---- crates/fj-kernel/src/objects/full/mod.rs | 1 - crates/fj-kernel/src/objects/mod.rs | 1 - crates/fj-kernel/src/partial/objects/edge.rs | 20 +++++++------------ crates/fj-kernel/src/validate/cycle.rs | 6 ++---- 12 files changed, 23 insertions(+), 55 deletions(-) delete mode 100644 crates/fj-kernel/src/objects/full/curve.rs diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 7ed2ec6a3..906a059c3 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -41,7 +41,7 @@ impl Approx for (&Handle, &Surface) { Some(approx) => approx, None => { let approx = approx_edge( - &half_edge.curve().path(), + &half_edge.curve(), surface, range, tolerance, @@ -56,7 +56,6 @@ impl Approx for (&Handle, &Surface) { .map(|point| { let point_surface = half_edge .curve() - .path() .point_from_path_coords(point.local_form); ApproxPoint::new(point_surface, point.global_form) @@ -320,10 +319,8 @@ mod tests { .approx(tolerance) .into_iter() .map(|(point_local, _)| { - let point_surface = half_edge - .curve() - .path() - .point_from_path_coords(point_local); + let point_surface = + half_edge.curve().point_from_path_coords(point_local); let point_global = surface.geometry().point_from_surface_coords(point_surface); ApproxPoint::new(point_surface, point_global) @@ -352,7 +349,7 @@ mod tests { let approx = (&half_edge, surface.deref()).approx(tolerance); let expected_approx = - (&half_edge.curve().path(), RangeOnPath::from([[0.], [TAU]])) + (&half_edge.curve(), RangeOnPath::from([[0.], [TAU]])) .approx(tolerance) .into_iter() .map(|(_, point_surface)| { diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs index 337e08f13..495718be1 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs @@ -35,7 +35,7 @@ impl CurveEdgeIntersection { }; let edge_as_segment = { - let edge_curve_as_line = match half_edge.curve().path() { + let edge_curve_as_line = match half_edge.curve() { SurfacePath::Line(line) => line, _ => { todo!("Curve-edge intersection only supports line segments") diff --git a/crates/fj-kernel/src/algorithms/intersect/ray_edge.rs b/crates/fj-kernel/src/algorithms/intersect/ray_edge.rs index 15cfa6be7..faf7c4c47 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_edge.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_edge.rs @@ -17,7 +17,7 @@ impl Intersect for (&HorizontalRayToTheRight<2>, &Handle) { fn intersect(self) -> Option { let (ray, edge) = self; - let line = match edge.curve().path() { + let line = match edge.curve() { SurfacePath::Line(line) => line, SurfacePath::Circle(_) => { todo!("Casting rays against circles is not supported yet") diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index db656768f..a2c6ca704 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -35,8 +35,7 @@ impl Sweep for (Handle, &Surface, Color) { // we're sweeping. { let surface = Partial::from( - (edge.curve().path(), surface) - .sweep_with_cache(path, cache, objects), + (edge.curve(), surface).sweep_with_cache(path, cache, objects), ); face.surface = surface; } diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 3c3e3504d..b061ddb68 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -109,7 +109,7 @@ impl Sweep for Handle { .into_iter() .zip(top_cycle.write().half_edges.iter_mut()) { - top.write().curve = Some(bottom.curve().path().into()); + top.write().curve = Some(bottom.curve().into()); let boundary = bottom.boundary(); diff --git a/crates/fj-kernel/src/objects/full/curve.rs b/crates/fj-kernel/src/objects/full/curve.rs deleted file mode 100644 index e2c359a2a..000000000 --- a/crates/fj-kernel/src/objects/full/curve.rs +++ /dev/null @@ -1,19 +0,0 @@ -use crate::geometry::path::SurfacePath; - -/// A curve, defined in local surface coordinates -#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] -pub struct Curve { - path: SurfacePath, -} - -impl Curve { - /// Construct a new instance of `Curve` - pub fn new(path: SurfacePath) -> Self { - Self { path } - } - - /// Access the path that defines the curve - pub fn path(&self) -> SurfacePath { - self.path - } -} diff --git a/crates/fj-kernel/src/objects/full/cycle.rs b/crates/fj-kernel/src/objects/full/cycle.rs index a8f429553..99a83b67a 100644 --- a/crates/fj-kernel/src/objects/full/cycle.rs +++ b/crates/fj-kernel/src/objects/full/cycle.rs @@ -55,7 +55,7 @@ impl Cycle { let [a, b] = first.boundary(); let edge_direction_positive = a < b; - let circle = match first.curve().path() { + let circle = match first.curve() { SurfacePath::Circle(circle) => circle, SurfacePath::Line(_) => unreachable!( "Invalid cycle: less than 3 edges, but not all are circles" diff --git a/crates/fj-kernel/src/objects/full/edge.rs b/crates/fj-kernel/src/objects/full/edge.rs index 0d263dc3c..1245d702a 100644 --- a/crates/fj-kernel/src/objects/full/edge.rs +++ b/crates/fj-kernel/src/objects/full/edge.rs @@ -2,7 +2,8 @@ use fj_interop::ext::ArrayExt; use fj_math::Point; use crate::{ - objects::{Curve, GlobalVertex, SurfaceVertex}, + geometry::path::SurfacePath, + objects::{GlobalVertex, SurfaceVertex}, storage::Handle, }; @@ -44,7 +45,7 @@ use crate::{ /// #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct HalfEdge { - curve: Curve, + curve: SurfacePath, boundary: [(Point<1>, Handle); 2], global_form: Handle, } @@ -52,7 +53,7 @@ pub struct HalfEdge { impl HalfEdge { /// Create an instance of `HalfEdge` pub fn new( - curve: Curve, + curve: SurfacePath, boundary: [(Point<1>, Handle); 2], global_form: Handle, ) -> Self { @@ -64,7 +65,7 @@ impl HalfEdge { } /// Access the curve that defines the half-edge's geometry - pub fn curve(&self) -> Curve { + pub fn curve(&self) -> SurfacePath { self.curve } diff --git a/crates/fj-kernel/src/objects/full/mod.rs b/crates/fj-kernel/src/objects/full/mod.rs index 1c2e5d303..2261d4905 100644 --- a/crates/fj-kernel/src/objects/full/mod.rs +++ b/crates/fj-kernel/src/objects/full/mod.rs @@ -1,4 +1,3 @@ -pub mod curve; pub mod cycle; pub mod edge; pub mod face; diff --git a/crates/fj-kernel/src/objects/mod.rs b/crates/fj-kernel/src/objects/mod.rs index e957c10ab..0e7e590e2 100644 --- a/crates/fj-kernel/src/objects/mod.rs +++ b/crates/fj-kernel/src/objects/mod.rs @@ -79,7 +79,6 @@ mod stores; pub use self::{ full::{ - curve::Curve, cycle::{Cycle, HalfEdgesOfCycle}, edge::{GlobalEdge, HalfEdge, VerticesInNormalizedOrder}, face::{Face, FaceSet, Handedness}, diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 064f3c9e2..0940a2356 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -4,9 +4,7 @@ use fj_interop::ext::ArrayExt; use fj_math::Point; use crate::{ - objects::{ - Curve, GlobalEdge, GlobalVertex, HalfEdge, Objects, SurfaceVertex, - }, + objects::{GlobalEdge, GlobalVertex, HalfEdge, Objects, SurfaceVertex}, partial::{FullToPartialCache, MaybeSurfacePath, Partial, PartialObject}, services::Service, }; @@ -32,7 +30,7 @@ impl PartialObject for PartialHalfEdge { cache: &mut FullToPartialCache, ) -> Self { Self { - curve: Some(half_edge.curve().path().into()), + curve: Some(half_edge.curve().into()), vertices: half_edge .boundary() .zip_ext(half_edge.surface_vertices()) @@ -50,17 +48,13 @@ impl PartialObject for PartialHalfEdge { } fn build(self, objects: &mut Service) -> Self::Full { - let curve = { - let path = match self.curve.expect("Need path to build curve") { - MaybeSurfacePath::Defined(path) => path, - undefined => { - panic!( + let curve = match self.curve.expect("Need path to build curve") { + MaybeSurfacePath::Defined(path) => path, + undefined => { + panic!( "Trying to build curve with undefined path: {undefined:?}" ) - } - }; - - Curve::new(path) + } }; let vertices = self.vertices.map(|vertex| { let position_curve = vertex diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index d8898820d..60d6c23c8 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -101,10 +101,8 @@ impl CycleValidationError { .boundary() .zip_ext([half_edge.start_vertex(), next.start_vertex()]); for (position_on_curve, surface_vertex) in boundary_and_vertices { - let curve_position_on_surface = half_edge - .curve() - .path() - .point_from_path_coords(position_on_curve); + let curve_position_on_surface = + half_edge.curve().point_from_path_coords(position_on_curve); let surface_position_from_vertex = surface_vertex.position(); let distance = curve_position_on_surface