From 252d43959209e3a8fd38bfbade6781901ea186d1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Feb 2023 12:10:30 +0100 Subject: [PATCH] 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(),