From f61afcbdd61be2aeac12b1d303f47271399d354a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 15:47:45 +0100 Subject: [PATCH 01/22] Use same surface for edge vertices Not sure why this even works as it was (and even as it is now; the surface is still not shared with the curve), but I'm in the process of cleaning up this redundancy anyway, so whatever. --- crates/fj-kernel/src/partial/objects/edge.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 6eda1fe16..2f40e0c85 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -98,12 +98,12 @@ impl PartialObject for PartialHalfEdge { impl Default for PartialHalfEdge { fn default() -> Self { + let surface = Partial::new(); + let curve = Partial::::new(); let vertices = array::from_fn(|_| { - let surface = Partial::new(); - let surface_form = Partial::from_partial(PartialSurfaceVertex { - surface, + surface: surface.clone(), ..Default::default() }); From 357ed59b90edf65ed10a27ba3ee65f9150c47757 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 15:49:22 +0100 Subject: [PATCH 02/22] Reference surface in `PartialHalfEdge` --- crates/fj-kernel/src/partial/objects/edge.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 2f40e0c85..370192ab6 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -6,7 +6,7 @@ use fj_math::Point; use crate::{ objects::{ Curve, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Objects, - SurfaceVertex, + Surface, SurfaceVertex, }, partial::{ FullToPartialCache, Partial, PartialObject, PartialSurfaceVertex, @@ -17,6 +17,9 @@ use crate::{ /// A partial [`HalfEdge`] #[derive(Clone, Debug)] pub struct PartialHalfEdge { + /// The surface that the half-edge is defined in + pub surface: Partial, + /// The curve that the half-edge is defined in pub curve: Partial, @@ -35,6 +38,10 @@ impl PartialObject for PartialHalfEdge { cache: &mut FullToPartialCache, ) -> Self { Self { + surface: Partial::from_full( + half_edge.curve().surface().clone(), + cache, + ), curve: Partial::from_full(half_edge.curve().clone(), cache), vertices: half_edge .boundary() @@ -125,6 +132,7 @@ impl Default for PartialHalfEdge { }); Self { + surface, curve, vertices, global_form, From 74a1b44ab5c924d7a5ded68cae1183b7e81e029f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 15:54:33 +0100 Subject: [PATCH 03/22] Reference `Surface` in `HalfEdge` --- crates/fj-kernel/src/algorithms/reverse/edge.rs | 1 + .../fj-kernel/src/algorithms/transform/edge.rs | 6 +++++- crates/fj-kernel/src/objects/full/edge.rs | 10 +++++++++- crates/fj-kernel/src/partial/objects/edge.rs | 2 +- crates/fj-kernel/src/validate/edge.rs | 16 ++++++++++++++-- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/reverse/edge.rs b/crates/fj-kernel/src/algorithms/reverse/edge.rs index 1a9023356..721f77dc8 100644 --- a/crates/fj-kernel/src/algorithms/reverse/edge.rs +++ b/crates/fj-kernel/src/algorithms/reverse/edge.rs @@ -19,6 +19,7 @@ impl Reverse for Handle { }; HalfEdge::new( + self.surface().clone(), self.curve().clone(), vertices, self.global_form().clone(), diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index 4c5b7b242..796769f5e 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -15,6 +15,10 @@ impl TransformObject for HalfEdge { objects: &mut Service, cache: &mut TransformCache, ) -> Self { + let surface = self + .surface() + .clone() + .transform_with_cache(transform, objects, cache); let curve = self .curve() .clone() @@ -32,7 +36,7 @@ impl TransformObject for HalfEdge { .clone() .transform_with_cache(transform, objects, cache); - Self::new(curve, boundary, global_form) + Self::new(surface, curve, boundary, global_form) } } diff --git a/crates/fj-kernel/src/objects/full/edge.rs b/crates/fj-kernel/src/objects/full/edge.rs index 390ec41e3..f7a77b378 100644 --- a/crates/fj-kernel/src/objects/full/edge.rs +++ b/crates/fj-kernel/src/objects/full/edge.rs @@ -4,13 +4,14 @@ use fj_interop::ext::ArrayExt; use fj_math::Point; use crate::{ - objects::{Curve, GlobalCurve, GlobalVertex, SurfaceVertex}, + objects::{Curve, GlobalCurve, GlobalVertex, Surface, SurfaceVertex}, storage::{Handle, HandleWrapper}, }; /// A half-edge #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct HalfEdge { + surface: Handle, curve: Handle, boundary: [(Point<1>, Handle); 2], global_form: Handle, @@ -19,17 +20,24 @@ pub struct HalfEdge { impl HalfEdge { /// Create an instance of `HalfEdge` pub fn new( + surface: Handle, curve: Handle, boundary: [(Point<1>, Handle); 2], global_form: Handle, ) -> Self { Self { + surface, curve, boundary, global_form, } } + /// Access the surface that the half-edge is defined in + pub fn surface(&self) -> &Handle { + &self.surface + } + /// Access the curve that defines the half-edge's geometry pub fn curve(&self) -> &Handle { &self.curve diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 370192ab6..0cd2a53de 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -99,7 +99,7 @@ impl PartialObject for PartialHalfEdge { }); let global_form = self.global_form.build(objects); - HalfEdge::new(curve, vertices, global_form) + HalfEdge::new(curve.surface().clone(), curve, vertices, global_form) } } diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 75445fefd..8b5fd9c4c 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -240,7 +240,12 @@ mod tests { .boundary() .zip_ext(valid.surface_vertices().map(Clone::clone)); - HalfEdge::new(valid.curve().clone(), vertices, global_form) + HalfEdge::new( + valid.surface().clone(), + valid.curve().clone(), + vertices, + global_form, + ) }; valid.validate_and_return_first_error()?; @@ -282,7 +287,12 @@ mod tests { .boundary() .zip_ext(valid.surface_vertices().map(Clone::clone)); - HalfEdge::new(valid.curve().clone(), vertices, global_form) + HalfEdge::new( + valid.surface().clone(), + valid.curve().clone(), + vertices, + global_form, + ) }; valid.validate_and_return_first_error()?; @@ -318,6 +328,7 @@ mod tests { }); HalfEdge::new( + valid.surface().clone(), valid.curve().clone(), vertices, valid.global_form().clone(), @@ -349,6 +360,7 @@ mod tests { }); HalfEdge::new( + valid.surface().clone(), valid.curve().clone(), vertices, valid.global_form().clone(), From 9652759633c1f068839878c25eca0e1be744ebb0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 15:56:44 +0100 Subject: [PATCH 04/22] Update `HalfEdgeBuilder::replace_surface` --- crates/fj-kernel/src/builder/edge.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 229bbaab6..a3cc42948 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -64,6 +64,8 @@ impl HalfEdgeBuilder for PartialHalfEdge { fn replace_surface(&mut self, surface: impl Into>) { let surface = surface.into(); + self.surface = surface.clone(); + self.curve.write().surface = surface.clone(); for vertex in &mut self.vertices { From ecf538c7ada193cce9310009fef4b5929b6f3306 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 16:00:58 +0100 Subject: [PATCH 05/22] Avoid use of `Curve::surface` --- .../fj-kernel/src/algorithms/approx/curve.rs | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index ae1c6b4d7..f131113c1 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -13,7 +13,7 @@ use std::collections::BTreeMap; use crate::{ geometry::path::{GlobalPath, SurfacePath}, - objects::{Curve, GlobalCurve}, + objects::{Curve, GlobalCurve, Surface}, storage::{Handle, ObjectId}, }; @@ -34,7 +34,12 @@ impl Approx for (&Handle, RangeOnPath) { let global_curve_approx = match cache.get(global_curve.clone(), range) { Some(approx) => approx, None => { - let approx = approx_global_curve(curve, range, tolerance); + let approx = approx_global_curve( + curve, + curve.surface(), + range, + tolerance, + ); cache.insert(global_curve, range, approx) } }; @@ -53,6 +58,7 @@ impl Approx for (&Handle, RangeOnPath) { fn approx_global_curve( curve: &Curve, + surface: &Surface, range: RangeOnPath, tolerance: impl Into, ) -> GlobalCurveApprox { @@ -62,7 +68,7 @@ fn approx_global_curve( // This will probably all be unified eventually, as `SurfacePath` and // `GlobalPath` grow APIs that are better suited to implementing this code // in a more abstract way. - let points = match (curve.path(), curve.surface().geometry().u) { + let points = match (curve.path(), surface.geometry().u) { (SurfacePath::Circle(_), GlobalPath::Circle(_)) => { todo!( "Approximating a circle on a curved surface not supported yet." @@ -88,8 +94,7 @@ fn approx_global_curve( // surface point available, so it needs to be computed // later anyway, in the general case. - let point_global = curve - .surface() + let point_global = surface .geometry() .point_from_surface_coords(point_surface); (point_curve, point_global) @@ -102,17 +107,15 @@ fn approx_global_curve( [curve.path().point_from_path_coords(point_curve).u] })); - let approx_u = (curve.surface().geometry().u, range_u) + let approx_u = (surface.geometry().u, range_u) .approx_with_cache(tolerance, &mut ()); let mut points = Vec::new(); for (u, _) in approx_u { let t = (u.t - line.origin().u) / line.direction().u; let point_surface = curve.path().point_from_path_coords([t]); - let point_global = curve - .surface() - .geometry() - .point_from_surface_coords(point_surface); + let point_global = + surface.geometry().point_from_surface_coords(point_surface); points.push((u, point_global)); } From 31fafa6fa1712aa80d1f97d49836f71137b51f8b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 16:02:50 +0100 Subject: [PATCH 06/22] Avoid use of `Curve::surface` --- .../fj-kernel/src/algorithms/approx/curve.rs | 34 ++++++++----------- .../fj-kernel/src/algorithms/approx/edge.rs | 6 ++-- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index f131113c1..c9fc12470 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -19,7 +19,7 @@ use crate::{ use super::{path::RangeOnPath, Approx, ApproxPoint, Tolerance}; -impl Approx for (&Handle, RangeOnPath) { +impl Approx for (&Handle, &Surface, RangeOnPath) { type Approximation = CurveApprox; type Cache = CurveCache; @@ -28,18 +28,14 @@ impl Approx for (&Handle, RangeOnPath) { tolerance: impl Into, cache: &mut Self::Cache, ) -> Self::Approximation { - let (curve, range) = self; + let (curve, surface, range) = self; let global_curve = curve.global_form().clone(); let global_curve_approx = match cache.get(global_curve.clone(), range) { Some(approx) => approx, None => { - let approx = approx_global_curve( - curve, - curve.surface(), - range, - tolerance, - ); + let approx = + approx_global_curve(curve, surface, range, tolerance); cache.insert(global_curve, range, approx) } }; @@ -214,7 +210,7 @@ impl GlobalCurveApprox { #[cfg(test)] mod tests { - use std::f64::consts::TAU; + use std::{f64::consts::TAU, ops::Deref}; use pretty_assertions::assert_eq; @@ -235,7 +231,7 @@ mod tests { let surface = services.objects.surfaces.xz_plane(); let mut curve = PartialCurve { - surface: Partial::from(surface), + surface: Partial::from(surface.clone()), ..Default::default() }; curve.update_as_line_from_points([[1., 1.], [2., 1.]]); @@ -244,7 +240,7 @@ mod tests { .insert(&mut services.objects); let range = RangeOnPath::from([[0.], [1.]]); - let approx = (&curve, range).approx(1.); + let approx = (&curve, surface.deref(), range).approx(1.); assert_eq!(approx, CurveApprox::empty()); } @@ -260,7 +256,7 @@ mod tests { .build(&mut services.objects) .insert(&mut services.objects); let mut curve = PartialCurve { - surface: Partial::from(surface), + surface: Partial::from(surface.clone()), ..Default::default() }; curve.update_as_line_from_points([[1., 1.], [1., 2.]]); @@ -269,7 +265,7 @@ mod tests { .insert(&mut services.objects); let range = RangeOnPath::from([[0.], [1.]]); - let approx = (&curve, range).approx(1.); + let approx = (&curve, surface.deref(), range).approx(1.); assert_eq!(approx, CurveApprox::empty()); } @@ -294,7 +290,7 @@ mod tests { let range = RangeOnPath::from([[0.], [TAU]]); let tolerance = 1.; - let approx = (&curve, range).approx(tolerance); + let approx = (&curve, surface.deref(), range).approx(tolerance); let expected_approx = (path, range) .approx(tolerance) @@ -316,7 +312,7 @@ mod tests { let surface = services.objects.surfaces.xz_plane(); let mut curve = PartialCurve { - surface: Partial::from(surface), + surface: Partial::from(surface.clone()), ..Default::default() }; curve.update_as_circle_from_radius(1.); @@ -326,16 +322,14 @@ mod tests { let range = RangeOnPath::from([[0.], [TAU]]); let tolerance = 1.; - let approx = (&curve, range).approx(tolerance); + let approx = (&curve, surface.deref(), range).approx(tolerance); let expected_approx = (curve.path(), range) .approx(tolerance) .into_iter() .map(|(_, point_surface)| { - let point_global = curve - .surface() - .geometry() - .point_from_surface_coords(point_surface); + let point_global = + surface.geometry().point_from_surface_coords(point_surface); ApproxPoint::new(point_surface, point_global) }) .collect::>(); diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 41376dac7..2d74e66d5 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -5,6 +5,8 @@ //! approximations are usually used to build cycle approximations, and this way, //! the caller doesn't have to call with duplicate vertices. +use std::ops::Deref; + use crate::{objects::HalfEdge, storage::Handle}; use super::{ @@ -30,8 +32,8 @@ impl Approx for &Handle { self.start_vertex().global_form().position(), ) .with_source((self.clone(), self.boundary()[0])); - let curve_approx = - (self.curve(), range).approx_with_cache(tolerance, cache); + let curve_approx = (self.curve(), self.surface().deref(), range) + .approx_with_cache(tolerance, cache); HalfEdgeApprox { first, From cba83e32d15616f6ff134661baa52144a344b25b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 16:11:21 +0100 Subject: [PATCH 07/22] Refactor --- crates/fj-kernel/src/algorithms/sweep/curve.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/curve.rs b/crates/fj-kernel/src/algorithms/sweep/curve.rs index 3a4ba6cba..baf1fd7c8 100644 --- a/crates/fj-kernel/src/algorithms/sweep/curve.rs +++ b/crates/fj-kernel/src/algorithms/sweep/curve.rs @@ -21,7 +21,9 @@ impl Sweep for Handle { _: &mut SweepCache, objects: &mut Service, ) -> Self::Swept { - match self.surface().geometry().u { + let curve = self; + + match curve.surface().geometry().u { GlobalPath::Circle(_) => { // Sweeping a `Curve` creates a `Surface`. The u-axis of that // `Surface` is a `GlobalPath`, which we are computing below. @@ -45,17 +47,17 @@ impl Sweep for Handle { } } - let u = match self.path() { + let u = match curve.path() { SurfacePath::Circle(circle) => { - let center = self + let center = curve .surface() .geometry() .point_from_surface_coords(circle.center()); - let a = self + let a = curve .surface() .geometry() .vector_from_surface_coords(circle.a()); - let b = self + let b = curve .surface() .geometry() .vector_from_surface_coords(circle.b()); @@ -65,11 +67,11 @@ impl Sweep for Handle { GlobalPath::Circle(circle) } SurfacePath::Line(line) => { - let origin = self + let origin = curve .surface() .geometry() .point_from_surface_coords(line.origin()); - let direction = self + let direction = curve .surface() .geometry() .vector_from_surface_coords(line.direction()); From e8817b118b42a85a7de7e529e8a2bc520d29caed Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 16:12:52 +0100 Subject: [PATCH 08/22] Avoid use of `Curve::surface` --- .../fj-kernel/src/algorithms/sweep/curve.rs | 30 +++++++------------ crates/fj-kernel/src/algorithms/sweep/edge.rs | 5 +++- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/curve.rs b/crates/fj-kernel/src/algorithms/sweep/curve.rs index baf1fd7c8..34d6a706b 100644 --- a/crates/fj-kernel/src/algorithms/sweep/curve.rs +++ b/crates/fj-kernel/src/algorithms/sweep/curve.rs @@ -12,7 +12,7 @@ use crate::{ use super::{Sweep, SweepCache}; -impl Sweep for Handle { +impl Sweep for (Handle, &Surface) { type Swept = Handle; fn sweep_with_cache( @@ -21,9 +21,9 @@ impl Sweep for Handle { _: &mut SweepCache, objects: &mut Service, ) -> Self::Swept { - let curve = self; + let (curve, surface) = self; - match curve.surface().geometry().u { + match surface.geometry().u { GlobalPath::Circle(_) => { // Sweeping a `Curve` creates a `Surface`. The u-axis of that // `Surface` is a `GlobalPath`, which we are computing below. @@ -49,30 +49,22 @@ impl Sweep for Handle { let u = match curve.path() { SurfacePath::Circle(circle) => { - let center = curve - .surface() + let center = surface .geometry() .point_from_surface_coords(circle.center()); - let a = curve - .surface() - .geometry() - .vector_from_surface_coords(circle.a()); - let b = curve - .surface() - .geometry() - .vector_from_surface_coords(circle.b()); + let a = + surface.geometry().vector_from_surface_coords(circle.a()); + let b = + surface.geometry().vector_from_surface_coords(circle.b()); let circle = Circle::new(center, a, b); GlobalPath::Circle(circle) } SurfacePath::Line(line) => { - let origin = curve - .surface() - .geometry() - .point_from_surface_coords(line.origin()); - let direction = curve - .surface() + let origin = + surface.geometry().point_from_surface_coords(line.origin()); + let direction = surface .geometry() .vector_from_surface_coords(line.direction()); diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index e4319de67..d4b4d2448 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -1,3 +1,5 @@ +use std::ops::Deref; + use fj_interop::{ext::ArrayExt, mesh::Color}; use fj_math::{Point, Scalar, Vector}; @@ -34,7 +36,8 @@ impl Sweep for (Handle, Color) { // be created by sweeping a curve, so let's sweep the curve of the edge // we're sweeping. face.exterior.write().surface = Partial::from( - edge.curve().clone().sweep_with_cache(path, cache, objects), + (edge.curve().clone(), edge.surface().deref()) + .sweep_with_cache(path, cache, objects), ); // Now we're ready to create the edges. From b9862a345422861dca92cdb7c2bea3e2f05ea2d0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 16:14:31 +0100 Subject: [PATCH 09/22] Simplify `Surface` access --- crates/fj-kernel/src/objects/full/cycle.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/objects/full/cycle.rs b/crates/fj-kernel/src/objects/full/cycle.rs index 2a829a8a5..66e56a200 100644 --- a/crates/fj-kernel/src/objects/full/cycle.rs +++ b/crates/fj-kernel/src/objects/full/cycle.rs @@ -39,7 +39,7 @@ impl Cycle { /// Access the surface that the cycle is in pub fn surface(&self) -> &Handle { if let Some(half_edge) = self.half_edges.first() { - return half_edge.curve().surface(); + return half_edge.surface(); } unreachable!( From 735d3e21dfee238cdec1fcd992dfd11990b48351 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 16:17:11 +0100 Subject: [PATCH 10/22] Simplify surface access --- crates/fj-kernel/src/builder/edge.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index a3cc42948..2c4cf3e1b 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -198,7 +198,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { self.curve.write().path = other.read().curve.read().path.as_ref().and_then(|path| { - match other.read().curve.read().surface.read().geometry { + match other.read().surface.read().geometry { Some(surface) => { // We have information about the other edge's surface // available. We need to use that to interpret what the From 7ccc923232b82fb19d5d8a6203ea172fe0869957 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 16:18:55 +0100 Subject: [PATCH 11/22] Simplify surface access --- crates/fj-kernel/src/partial/objects/edge.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 0cd2a53de..e33a437e3 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -38,10 +38,7 @@ impl PartialObject for PartialHalfEdge { cache: &mut FullToPartialCache, ) -> Self { Self { - surface: Partial::from_full( - half_edge.curve().surface().clone(), - cache, - ), + surface: Partial::from_full(half_edge.surface().clone(), cache), curve: Partial::from_full(half_edge.curve().clone(), cache), vertices: half_edge .boundary() From a7956b008c31c0243325b109ffaaddd80772463d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 16:20:39 +0100 Subject: [PATCH 12/22] Inline variable --- crates/fj-kernel/src/partial/objects/edge.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index e33a437e3..604b339fc 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -80,10 +80,10 @@ impl PartialObject for PartialHalfEdge { // Infer global position, if not available. let position_global = vertex.1.read().global_form.read().position; if position_global.is_none() { - let surface = curve.surface().geometry(); - - let position_global = - surface.point_from_surface_coords(position_surface); + let position_global = curve + .surface() + .geometry() + .point_from_surface_coords(position_surface); vertex.1.write().global_form.write().position = Some(position_global); } From fb13d3e46544f4ec35b6d02d958bdd019fa9d873 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 16:23:51 +0100 Subject: [PATCH 13/22] Update validation check --- crates/fj-kernel/src/validate/edge.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 8b5fd9c4c..2bad5c7e4 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -165,10 +165,14 @@ impl HalfEdgeValidationError { half_edge: &HalfEdge, errors: &mut Vec, ) { + let surface = half_edge.surface(); + let curve_surface = half_edge.curve().surface(); let surface_form_surface = half_edge.start_vertex().surface(); - if curve_surface.id() != surface_form_surface.id() { + if surface.id() != curve_surface.id() + || surface.id() != surface_form_surface.id() + { errors.push( Box::new(Self::SurfaceMismatch { curve_surface: curve_surface.clone(), From 7fddd0dd8bb245c95bb4ba54058b2cfe5165c536 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 16:30:14 +0100 Subject: [PATCH 14/22] Simplify surface update --- crates/fj-kernel/src/builder/edge.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 2c4cf3e1b..50d3762b7 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -136,14 +136,11 @@ impl HalfEdgeBuilder for PartialHalfEdge { surface: impl Into>, points: [impl Into>; 2], ) { - let surface = surface.into(); - - self.curve.write().surface = surface.clone(); + self.replace_surface(surface.into()); for (vertex, point) in self.vertices.each_mut_ext().zip_ext(points) { let mut surface_form = vertex.1.write(); surface_form.position = Some(point.into()); - surface_form.surface = surface.clone(); } self.update_as_line_segment() From ba00ef13ec2a63fa6419325da79d3129a06e0bd8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 16:35:03 +0100 Subject: [PATCH 15/22] Simplify surface replacement --- crates/fj-kernel/src/algorithms/sweep/edge.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index d4b4d2448..7086b20f7 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -197,7 +197,7 @@ mod tests { }; let side_up = { let mut side_up = PartialHalfEdge::default(); - side_up.curve.write().surface = surface.clone(); + side_up.replace_surface(surface.clone()); { let [back, front] = side_up @@ -209,7 +209,6 @@ mod tests { let mut front = front.write(); front.position = Some([1., 1.].into()); - front.surface = surface.clone(); } side_up.infer_global_form(); @@ -219,7 +218,7 @@ mod tests { }; let top = { let mut top = PartialHalfEdge::default(); - top.curve.write().surface = surface.clone(); + top.replace_surface(surface.clone()); { let [(back, back_surface), (front, front_surface)] = @@ -231,7 +230,6 @@ mod tests { *front = Some(Point::from([0.])); let mut front_surface = front_surface.write(); front_surface.position = Some([0., 1.].into()); - front_surface.surface = surface.clone(); } top.infer_global_form(); @@ -246,7 +244,7 @@ mod tests { }; let side_down = { let mut side_down = PartialHalfEdge::default(); - side_down.curve.write().surface = surface; + side_down.replace_surface(surface); let [(back, back_surface), (front, front_surface)] = side_down.vertices.each_mut_ext(); From a05aba0c7ea0aaac1931ad79663b99dc6d1258fa Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Feb 2023 11:56:44 +0100 Subject: [PATCH 16/22] Simplify surface replacement --- crates/fj-operations/src/sketch.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 03f89119e..54c736008 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -31,13 +31,7 @@ impl Shape for fj::Sketch { let surface = Partial::from(surface); let mut half_edge = PartialHalfEdge::default(); - - half_edge.curve.write().surface = surface.clone(); - - for vertex in &mut half_edge.vertices { - vertex.1.write().surface = surface.clone(); - } - + half_edge.replace_surface(surface); half_edge.update_as_circle_from_radius(circle.radius()); Partial::from_partial(half_edge) From 936c5208742b679a0fb578a88a7cd09b3fca2b99 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Feb 2023 11:57:21 +0100 Subject: [PATCH 17/22] Avoid use of `Curve::surface` --- crates/fj-kernel/src/partial/objects/edge.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 604b339fc..ff0addbbb 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -57,6 +57,7 @@ impl PartialObject for PartialHalfEdge { } fn build(self, objects: &mut Service) -> Self::Full { + let surface = self.surface.build(objects); let curve = self.curve.build(objects); let vertices = self.vertices.map(|mut vertex| { let position_surface = vertex.1.read().position; @@ -80,8 +81,7 @@ impl PartialObject for PartialHalfEdge { // Infer global position, if not available. let position_global = vertex.1.read().global_form.read().position; if position_global.is_none() { - let position_global = curve - .surface() + let position_global = surface .geometry() .point_from_surface_coords(position_surface); vertex.1.write().global_form.write().position = @@ -96,7 +96,7 @@ impl PartialObject for PartialHalfEdge { }); let global_form = self.global_form.build(objects); - HalfEdge::new(curve.surface().clone(), curve, vertices, global_form) + HalfEdge::new(surface, curve, vertices, global_form) } } From 252d43959209e3a8fd38bfbade6781901ea186d1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Feb 2023 12:10:30 +0100 Subject: [PATCH 18/22] Remove `Surface` ref from `Curve`/`PartialCurve` --- crates/fj-kernel/src/algorithms/approx/curve.rs | 6 +----- crates/fj-kernel/src/algorithms/intersect/curve_edge.rs | 4 ---- crates/fj-kernel/src/algorithms/intersect/curve_face.rs | 1 - crates/fj-kernel/src/algorithms/intersect/face_face.rs | 3 +-- .../src/algorithms/intersect/surface_surface.rs | 8 +++----- crates/fj-kernel/src/algorithms/transform/curve.rs | 6 +----- crates/fj-kernel/src/builder/edge.rs | 2 -- crates/fj-kernel/src/objects/full/curve.rs | 9 --------- crates/fj-kernel/src/partial/objects/curve.rs | 9 ++------- crates/fj-kernel/src/validate/edge.rs | 8 ++------ 10 files changed, 10 insertions(+), 46 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index c9fc12470..6c2a725e2 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -219,7 +219,7 @@ mod tests { builder::{CurveBuilder, SurfaceBuilder}, geometry::path::GlobalPath, insert::Insert, - partial::{Partial, PartialCurve, PartialObject, PartialSurface}, + partial::{PartialCurve, PartialObject, PartialSurface}, services::Services, }; @@ -231,7 +231,6 @@ mod tests { let surface = services.objects.surfaces.xz_plane(); let mut curve = PartialCurve { - surface: Partial::from(surface.clone()), ..Default::default() }; curve.update_as_line_from_points([[1., 1.], [2., 1.]]); @@ -256,7 +255,6 @@ mod tests { .build(&mut services.objects) .insert(&mut services.objects); let mut curve = PartialCurve { - surface: Partial::from(surface.clone()), ..Default::default() }; curve.update_as_line_from_points([[1., 1.], [1., 2.]]); @@ -279,7 +277,6 @@ mod tests { .build(&mut services.objects) .insert(&mut services.objects); let mut curve = PartialCurve { - surface: Partial::from(surface.clone()), ..Default::default() }; curve.update_as_line_from_points([[0., 1.], [1., 1.]]); @@ -312,7 +309,6 @@ mod tests { let surface = services.objects.surfaces.xz_plane(); let mut curve = PartialCurve { - surface: Partial::from(surface.clone()), ..Default::default() }; curve.update_as_circle_from_radius(1.); diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs index eaaca63b5..2f35ea124 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs @@ -88,7 +88,6 @@ mod tests { let surface = Partial::from(services.objects.surfaces.xy_plane()); let mut curve = PartialCurve { - surface: surface.clone(), ..Default::default() }; curve.update_as_u_axis(); @@ -119,7 +118,6 @@ mod tests { let surface = Partial::from(services.objects.surfaces.xy_plane()); let mut curve = PartialCurve { - surface: surface.clone(), ..Default::default() }; curve.update_as_u_axis(); @@ -150,7 +148,6 @@ mod tests { let surface = Partial::from(services.objects.surfaces.xy_plane()); let mut curve = PartialCurve { - surface: surface.clone(), ..Default::default() }; curve.update_as_u_axis(); @@ -176,7 +173,6 @@ mod tests { let surface = Partial::from(services.objects.surfaces.xy_plane()); let mut curve = PartialCurve { - surface: surface.clone(), ..Default::default() }; curve.update_as_u_axis(); diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index 3724fb123..50eaa4627 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -164,7 +164,6 @@ mod tests { let surface = Partial::from(services.objects.surfaces.xy_plane()); let mut curve = PartialCurve { - surface: surface.clone(), ..Default::default() }; curve.update_as_line_from_points([[-3., 0.], [-2., 0.]]); diff --git a/crates/fj-kernel/src/algorithms/intersect/face_face.rs b/crates/fj-kernel/src/algorithms/intersect/face_face.rs index 499aa0719..1c0407f03 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -132,9 +132,8 @@ mod tests { let intersection = FaceFaceIntersection::compute([&a, &b], &mut services.objects); - let expected_curves = surfaces.map(|surface| { + let expected_curves = surfaces.map(|_| { let mut curve = PartialCurve { - surface: Partial::from(surface), ..Default::default() }; curve.update_as_line_from_points([[0., 0.], [1., 0.]]); diff --git a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs index 53cb2d34f..9732f1f37 100644 --- a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs +++ b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs @@ -57,11 +57,11 @@ impl SurfaceSurfaceIntersection { let line = Line::from_origin_and_direction(origin, direction); - let curves = surfaces_and_planes.map(|(surface, plane)| { + let curves = surfaces_and_planes.map(|(_, plane)| { let path = SurfacePath::Line(plane.project_line(&line)); let global_form = GlobalCurve.insert(objects); - Curve::new(surface, path, global_form).insert(objects) + Curve::new(path, global_form).insert(objects) }); Some(Self { @@ -92,7 +92,7 @@ mod tests { algorithms::transform::TransformObject, builder::CurveBuilder, insert::Insert, - partial::{Partial, PartialCurve, PartialObject}, + partial::{PartialCurve, PartialObject}, services::Services, }; @@ -121,7 +121,6 @@ mod tests { ); let mut expected_xy = PartialCurve { - surface: Partial::from(xy.clone()), ..Default::default() }; expected_xy.update_as_u_axis(); @@ -129,7 +128,6 @@ mod tests { .build(&mut services.objects) .insert(&mut services.objects); let mut expected_xz = PartialCurve { - surface: Partial::from(xz.clone()), ..Default::default() }; expected_xz.update_as_u_axis(); diff --git a/crates/fj-kernel/src/algorithms/transform/curve.rs b/crates/fj-kernel/src/algorithms/transform/curve.rs index 9beb760c0..3b786abcd 100644 --- a/crates/fj-kernel/src/algorithms/transform/curve.rs +++ b/crates/fj-kernel/src/algorithms/transform/curve.rs @@ -18,16 +18,12 @@ impl TransformObject for Curve { // coordinates, and thus transforming `surface` takes care of it. let path = self.path(); - let surface = self - .surface() - .clone() - .transform_with_cache(transform, objects, cache); let global_form = self .global_form() .clone() .transform_with_cache(transform, objects, cache); - Self::new(surface, path, global_form) + Self::new(path, global_form) } } diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 50d3762b7..6a1e920a0 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -66,8 +66,6 @@ impl HalfEdgeBuilder for PartialHalfEdge { self.surface = surface.clone(); - self.curve.write().surface = surface.clone(); - for vertex in &mut self.vertices { vertex.1.write().surface = surface.clone(); } diff --git a/crates/fj-kernel/src/objects/full/curve.rs b/crates/fj-kernel/src/objects/full/curve.rs index 2db17d3fc..5515141ce 100644 --- a/crates/fj-kernel/src/objects/full/curve.rs +++ b/crates/fj-kernel/src/objects/full/curve.rs @@ -1,6 +1,5 @@ use crate::{ geometry::path::SurfacePath, - objects::Surface, storage::{Handle, HandleWrapper}, }; @@ -8,19 +7,16 @@ use crate::{ #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct Curve { path: SurfacePath, - surface: Handle, global_form: HandleWrapper, } impl Curve { /// Construct a new instance of `Curve` pub fn new( - surface: Handle, path: SurfacePath, global_form: impl Into>, ) -> Self { Self { - surface, path, global_form: global_form.into(), } @@ -31,11 +27,6 @@ impl Curve { self.path } - /// Access the surface that the curve is defined in - pub fn surface(&self) -> &Handle { - &self.surface - } - /// Access the global form of the curve pub fn global_form(&self) -> &Handle { &self.global_form diff --git a/crates/fj-kernel/src/partial/objects/curve.rs b/crates/fj-kernel/src/partial/objects/curve.rs index e1924b692..3826d4cb2 100644 --- a/crates/fj-kernel/src/partial/objects/curve.rs +++ b/crates/fj-kernel/src/partial/objects/curve.rs @@ -2,7 +2,7 @@ use fj_math::Scalar; use crate::{ geometry::path::SurfacePath, - objects::{Curve, GlobalCurve, Objects, Surface}, + objects::{Curve, GlobalCurve, Objects}, partial::{FullToPartialCache, Partial, PartialObject}, services::Service, }; @@ -13,9 +13,6 @@ pub struct PartialCurve { /// The path that defines the curve pub path: Option, - /// The surface the curve is defined in - pub surface: Partial, - /// The global form of the curve pub global_form: Partial, } @@ -26,7 +23,6 @@ impl PartialObject for PartialCurve { fn from_full(curve: &Self::Full, cache: &mut FullToPartialCache) -> Self { Self { path: Some(curve.path().into()), - surface: Partial::from_full(curve.surface().clone(), cache), global_form: Partial::from_full(curve.global_form().clone(), cache), } } @@ -40,10 +36,9 @@ impl PartialObject for PartialCurve { ) } }; - let surface = self.surface.build(objects); let global_form = self.global_form.build(objects); - Curve::new(surface, path, global_form) + Curve::new(path, global_form) } } diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 2bad5c7e4..ed434ea1a 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -166,16 +166,12 @@ impl HalfEdgeValidationError { errors: &mut Vec, ) { let surface = half_edge.surface(); - - let curve_surface = half_edge.curve().surface(); let surface_form_surface = half_edge.start_vertex().surface(); - if surface.id() != curve_surface.id() - || surface.id() != surface_form_surface.id() - { + if surface.id() != surface_form_surface.id() { errors.push( Box::new(Self::SurfaceMismatch { - curve_surface: curve_surface.clone(), + curve_surface: surface.clone(), surface_form_surface: surface_form_surface.clone(), }) .into(), From bc4d7b5055783d85c78ceefc8229120eed249a92 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Feb 2023 12:12:27 +0100 Subject: [PATCH 19/22] Simplify `PartialCurve` construction --- crates/fj-kernel/src/algorithms/approx/curve.rs | 16 ++++------------ .../src/algorithms/intersect/curve_edge.rs | 16 ++++------------ .../src/algorithms/intersect/curve_face.rs | 4 +--- .../src/algorithms/intersect/face_face.rs | 4 +--- .../src/algorithms/intersect/surface_surface.rs | 8 ++------ 5 files changed, 12 insertions(+), 36 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index 6c2a725e2..b8597a00c 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -230,9 +230,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xz_plane(); - let mut curve = PartialCurve { - ..Default::default() - }; + let mut curve = PartialCurve::default(); curve.update_as_line_from_points([[1., 1.], [2., 1.]]); let curve = curve .build(&mut services.objects) @@ -254,9 +252,7 @@ mod tests { ) .build(&mut services.objects) .insert(&mut services.objects); - let mut curve = PartialCurve { - ..Default::default() - }; + let mut curve = PartialCurve::default(); curve.update_as_line_from_points([[1., 1.], [1., 2.]]); let curve = curve .build(&mut services.objects) @@ -276,9 +272,7 @@ mod tests { let surface = PartialSurface::from_axes(path, [0., 0., 1.]) .build(&mut services.objects) .insert(&mut services.objects); - let mut curve = PartialCurve { - ..Default::default() - }; + let mut curve = PartialCurve::default(); curve.update_as_line_from_points([[0., 1.], [1., 1.]]); let curve = curve .build(&mut services.objects) @@ -308,9 +302,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xz_plane(); - let mut curve = PartialCurve { - ..Default::default() - }; + let mut curve = PartialCurve::default(); curve.update_as_circle_from_radius(1.); let curve = curve .build(&mut services.objects) diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs index 2f35ea124..d7ca55ac7 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs @@ -87,9 +87,7 @@ mod tests { let mut services = Services::new(); let surface = Partial::from(services.objects.surfaces.xy_plane()); - let mut curve = PartialCurve { - ..Default::default() - }; + let mut curve = PartialCurve::default(); curve.update_as_u_axis(); let curve = curve.build(&mut services.objects); let half_edge = { @@ -117,9 +115,7 @@ mod tests { let mut services = Services::new(); let surface = Partial::from(services.objects.surfaces.xy_plane()); - let mut curve = PartialCurve { - ..Default::default() - }; + let mut curve = PartialCurve::default(); curve.update_as_u_axis(); let curve = curve.build(&mut services.objects); let half_edge = { @@ -147,9 +143,7 @@ mod tests { let mut services = Services::new(); let surface = Partial::from(services.objects.surfaces.xy_plane()); - let mut curve = PartialCurve { - ..Default::default() - }; + let mut curve = PartialCurve::default(); curve.update_as_u_axis(); let curve = curve.build(&mut services.objects); let half_edge = { @@ -172,9 +166,7 @@ mod tests { let mut services = Services::new(); let surface = Partial::from(services.objects.surfaces.xy_plane()); - let mut curve = PartialCurve { - ..Default::default() - }; + let mut curve = PartialCurve::default(); curve.update_as_u_axis(); let curve = curve.build(&mut services.objects); let half_edge = { diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index 50eaa4627..5e5048d89 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -163,9 +163,7 @@ mod tests { let surface = Partial::from(services.objects.surfaces.xy_plane()); - let mut curve = PartialCurve { - ..Default::default() - }; + let mut curve = PartialCurve::default(); curve.update_as_line_from_points([[-3., 0.], [-2., 0.]]); let curve = curve.build(&mut services.objects); diff --git a/crates/fj-kernel/src/algorithms/intersect/face_face.rs b/crates/fj-kernel/src/algorithms/intersect/face_face.rs index 1c0407f03..fcf233da8 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -133,9 +133,7 @@ mod tests { FaceFaceIntersection::compute([&a, &b], &mut services.objects); let expected_curves = surfaces.map(|_| { - let mut curve = PartialCurve { - ..Default::default() - }; + let mut curve = PartialCurve::default(); curve.update_as_line_from_points([[0., 0.], [1., 0.]]); curve .build(&mut services.objects) diff --git a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs index 9732f1f37..a77bea030 100644 --- a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs +++ b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs @@ -120,16 +120,12 @@ mod tests { None, ); - let mut expected_xy = PartialCurve { - ..Default::default() - }; + let mut expected_xy = PartialCurve::default(); expected_xy.update_as_u_axis(); let expected_xy = expected_xy .build(&mut services.objects) .insert(&mut services.objects); - let mut expected_xz = PartialCurve { - ..Default::default() - }; + let mut expected_xz = PartialCurve::default(); expected_xz.update_as_u_axis(); let expected_xz = expected_xz .build(&mut services.objects) From 86f0defde40d90a7eb9efee9d75410ae083f8931 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Feb 2023 12:15:12 +0100 Subject: [PATCH 20/22] Improve formatting --- crates/fj-kernel/src/algorithms/intersect/surface_surface.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs index a77bea030..3b5da8c83 100644 --- a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs +++ b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs @@ -125,6 +125,7 @@ mod tests { let expected_xy = expected_xy .build(&mut services.objects) .insert(&mut services.objects); + let mut expected_xz = PartialCurve::default(); expected_xz.update_as_u_axis(); let expected_xz = expected_xz From 7066f6bc349cd778cbaef32b25a79600b5960e83 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Feb 2023 12:19:07 +0100 Subject: [PATCH 21/22] Remove unused data from array --- .../src/algorithms/intersect/surface_surface.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs index 3b5da8c83..29bc7a58c 100644 --- a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs +++ b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs @@ -27,11 +27,8 @@ impl SurfaceSurfaceIntersection { // Adaptations were made to get the intersection curves in local // coordinates for each surface. - let surfaces_and_planes = surfaces.map(|surface| { - let plane = plane_from_surface(&surface); - (surface, plane) - }); - let [a, b] = surfaces_and_planes.clone().map(|(_, plane)| plane); + let planes = surfaces.map(|surface| plane_from_surface(&surface)); + let [a, b] = planes; let (a_distance, a_normal) = a.constant_normal_form(); let (b_distance, b_normal) = b.constant_normal_form(); @@ -57,7 +54,7 @@ impl SurfaceSurfaceIntersection { let line = Line::from_origin_and_direction(origin, direction); - let curves = surfaces_and_planes.map(|(_, plane)| { + let curves = planes.map(|plane| { let path = SurfacePath::Line(plane.project_line(&line)); let global_form = GlobalCurve.insert(objects); From dd9b8340777aeb89f4adb8824734ec810140d7c4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Feb 2023 12:20:09 +0100 Subject: [PATCH 22/22] Consolidate duplicated code --- crates/fj-kernel/src/algorithms/intersect/surface_surface.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs index 29bc7a58c..48b37f882 100644 --- a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs +++ b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs @@ -28,10 +28,9 @@ impl SurfaceSurfaceIntersection { // coordinates for each surface. let planes = surfaces.map(|surface| plane_from_surface(&surface)); - let [a, b] = planes; - let (a_distance, a_normal) = a.constant_normal_form(); - let (b_distance, b_normal) = b.constant_normal_form(); + let [(a_distance, a_normal), (b_distance, b_normal)] = + planes.map(|plane| plane.constant_normal_form()); let direction = a_normal.cross(&b_normal);