diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index 5bdc07ff8..06d049cc2 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -161,10 +161,10 @@ mod tests { fn compute() { let mut services = Services::new(); - let surface = services.objects.surfaces.xy_plane(); + let surface = Partial::from(services.objects.surfaces.xy_plane()); let mut curve = PartialCurve { - surface: Partial::from(surface.clone()), + surface: surface.clone(), ..Default::default() }; curve.update_as_line_from_points([[-3., 0.], [-2., 0.]]); @@ -187,8 +187,9 @@ mod tests { let face = { let mut face = PartialFace::default(); - face.update_exterior_as_polygon(surface.clone(), exterior); - face.add_interior_polygon(surface, interior); + face.exterior.write().surface = surface; + face.update_exterior_as_polygon(exterior); + face.add_interior_polygon(interior); face.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 2a619779b..adf9a5496 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -94,7 +94,8 @@ mod tests { ] .map(|surface| { let mut face = PartialFace::default(); - face.update_exterior_as_polygon(surface, points); + face.exterior.write().surface = Partial::from(surface); + face.update_exterior_as_polygon(points); face.build(&mut services.objects) }); @@ -122,7 +123,8 @@ mod tests { ]; let [a, b] = surfaces.clone().map(|surface| { let mut face = PartialFace::default(); - face.update_exterior_as_polygon(surface, points); + face.exterior.write().surface = Partial::from(surface); + face.update_exterior_as_polygon(points); face.build(&mut services.objects) }); diff --git a/crates/fj-kernel/src/algorithms/intersect/face_point.rs b/crates/fj-kernel/src/algorithms/intersect/face_point.rs index 1ab7f6879..78c2dcade 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_point.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_point.rs @@ -139,7 +139,7 @@ mod tests { builder::FaceBuilder, insert::Insert, iter::ObjectIters, - partial::{PartialFace, PartialObject}, + partial::{Partial, PartialFace, PartialObject}, services::Services, }; @@ -147,12 +147,10 @@ mod tests { fn point_is_outside_face() { let mut services = Services::new(); - let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface, - [[0., 0.], [1., 1.], [0., 2.]], - ); + face.exterior.write().surface = + Partial::from(services.objects.surfaces.xy_plane()); + face.update_exterior_as_polygon([[0., 0.], [1., 1.], [0., 2.]]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -166,12 +164,10 @@ mod tests { fn ray_hits_vertex_while_passing_outside() { let mut services = Services::new(); - let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface, - [[0., 0.], [2., 1.], [0., 2.]], - ); + face.exterior.write().surface = + Partial::from(services.objects.surfaces.xy_plane()); + face.update_exterior_as_polygon([[0., 0.], [2., 1.], [0., 2.]]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -188,12 +184,10 @@ mod tests { fn ray_hits_vertex_at_cycle_seam() { let mut services = Services::new(); - let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface, - [[4., 2.], [0., 4.], [0., 0.]], - ); + face.exterior.write().surface = + Partial::from(services.objects.surfaces.xy_plane()); + face.update_exterior_as_polygon([[4., 2.], [0., 4.], [0., 0.]]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -210,12 +204,15 @@ mod tests { fn ray_hits_vertex_while_staying_inside() { let mut services = Services::new(); - let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface, - [[0., 0.], [2., 1.], [3., 0.], [3., 4.]], - ); + face.exterior.write().surface = + Partial::from(services.objects.surfaces.xy_plane()); + face.update_exterior_as_polygon([ + [0., 0.], + [2., 1.], + [3., 0.], + [3., 4.], + ]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -232,12 +229,15 @@ mod tests { fn ray_hits_parallel_edge_and_leaves_face_at_vertex() { let mut services = Services::new(); - let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface, - [[0., 0.], [2., 1.], [3., 1.], [0., 2.]], - ); + face.exterior.write().surface = + Partial::from(services.objects.surfaces.xy_plane()); + face.update_exterior_as_polygon([ + [0., 0.], + [2., 1.], + [3., 1.], + [0., 2.], + ]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -254,12 +254,16 @@ mod tests { fn ray_hits_parallel_edge_and_does_not_leave_face_there() { let mut services = Services::new(); - let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface, - [[0., 0.], [2., 1.], [3., 1.], [4., 0.], [4., 5.]], - ); + face.exterior.write().surface = + Partial::from(services.objects.surfaces.xy_plane()); + face.update_exterior_as_polygon([ + [0., 0.], + [2., 1.], + [3., 1.], + [4., 0.], + [4., 5.], + ]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -276,12 +280,10 @@ mod tests { fn point_is_coincident_with_edge() { let mut services = Services::new(); - let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface, - [[0., 0.], [2., 0.], [0., 1.]], - ); + face.exterior.write().surface = + Partial::from(services.objects.surfaces.xy_plane()); + face.update_exterior_as_polygon([[0., 0.], [2., 0.], [0., 1.]]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -307,12 +309,10 @@ mod tests { fn point_is_coincident_with_vertex() { let mut services = Services::new(); - let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface, - [[0., 0.], [1., 0.], [0., 1.]], - ); + face.exterior.write().surface = + Partial::from(services.objects.surfaces.xy_plane()); + face.update_exterior_as_polygon([[0., 0.], [1., 0.], [0., 1.]]); let face = face .build(&mut services.objects) .insert(&mut services.objects); diff --git a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs index 7d1e22a8d..4ed0094db 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs @@ -155,7 +155,7 @@ mod tests { builder::FaceBuilder, insert::Insert, iter::ObjectIters, - partial::{PartialFace, PartialObject}, + partial::{Partial, PartialFace, PartialObject}, services::Services, }; @@ -165,12 +165,15 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); - let surface = services.objects.surfaces.yz_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface, - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - ); + face.exterior.write().surface = + Partial::from(services.objects.surfaces.yz_plane()); + face.update_exterior_as_polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]); let face = face .build(&mut services.objects) .insert(&mut services.objects) @@ -185,12 +188,15 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); - let surface = services.objects.surfaces.yz_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface, - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - ); + face.exterior.write().surface = + Partial::from(services.objects.surfaces.yz_plane()); + face.update_exterior_as_polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]); let face = face .build(&mut services.objects) .insert(&mut services.objects) @@ -208,12 +214,15 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); - let surface = services.objects.surfaces.yz_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface, - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - ); + face.exterior.write().surface = + Partial::from(services.objects.surfaces.yz_plane()); + face.update_exterior_as_polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]); let face = face .build(&mut services.objects) .insert(&mut services.objects) @@ -228,12 +237,15 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); - let surface = services.objects.surfaces.yz_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface, - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - ); + face.exterior.write().surface = + Partial::from(services.objects.surfaces.yz_plane()); + face.update_exterior_as_polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]); let face = face .build(&mut services.objects) .insert(&mut services.objects) @@ -259,12 +271,15 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); - let surface = services.objects.surfaces.yz_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface, - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - ); + face.exterior.write().surface = + Partial::from(services.objects.surfaces.yz_plane()); + face.update_exterior_as_polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]); let face = face .build(&mut services.objects) .insert(&mut services.objects) @@ -288,12 +303,15 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); - let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface, - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - ); + face.exterior.write().surface = + Partial::from(services.objects.surfaces.xy_plane()); + face.update_exterior_as_polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -310,12 +328,15 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); - let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface, - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - ); + face.exterior.write().surface = + Partial::from(services.objects.surfaces.xy_plane()); + face.update_exterior_as_polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]); let face = face .build(&mut services.objects) .insert(&mut services.objects) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 815f05b97..799803854 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -89,7 +89,9 @@ mod tests { algorithms::{reverse::Reverse, transform::TransformObject}, builder::{FaceBuilder, HalfEdgeBuilder, SketchBuilder}, insert::Insert, - partial::{PartialFace, PartialHalfEdge, PartialObject, PartialSketch}, + partial::{ + Partial, PartialFace, PartialHalfEdge, PartialObject, PartialSketch, + }, services::Services, }; @@ -113,16 +115,16 @@ mod tests { .sweep(UP, &mut services.objects); let mut bottom = PartialFace::default(); - bottom.update_exterior_as_polygon(surface.clone(), TRIANGLE); + bottom.exterior.write().surface = Partial::from(surface.clone()); + bottom.update_exterior_as_polygon(TRIANGLE); let bottom = bottom .build(&mut services.objects) .insert(&mut services.objects) .reverse(&mut services.objects); let mut top = PartialFace::default(); - top.update_exterior_as_polygon( - surface.translate(UP, &mut services.objects), - TRIANGLE, - ); + top.exterior.write().surface = + Partial::from(surface.translate(UP, &mut services.objects)); + top.update_exterior_as_polygon(TRIANGLE); let top = top .build(&mut services.objects) .insert(&mut services.objects); @@ -164,16 +166,17 @@ mod tests { .sweep(DOWN, &mut services.objects); let mut bottom = PartialFace::default(); - bottom.update_exterior_as_polygon( + bottom.exterior.write().surface = Partial::from( surface.clone().translate(DOWN, &mut services.objects), - TRIANGLE, ); + bottom.update_exterior_as_polygon(TRIANGLE); let bottom = bottom .build(&mut services.objects) .insert(&mut services.objects) .reverse(&mut services.objects); let mut top = PartialFace::default(); - top.update_exterior_as_polygon(surface, TRIANGLE); + top.exterior.write().surface = Partial::from(surface); + top.update_exterior_as_polygon(TRIANGLE); let top = top .build(&mut services.objects) .insert(&mut services.objects); diff --git a/crates/fj-kernel/src/algorithms/triangulate/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs index 6779e26c7..695c7aad0 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -80,7 +80,7 @@ mod tests { builder::FaceBuilder, insert::Insert, objects::Face, - partial::{PartialFace, PartialObject}, + partial::{Partial, PartialFace, PartialObject}, services::Services, storage::Handle, }; @@ -96,9 +96,10 @@ mod tests { let c = [2., 2.]; let d = [0., 1.]; - let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon(surface, [a, b, c, d]); + face.exterior.write().surface = + Partial::from(services.objects.surfaces.xy_plane()); + face.update_exterior_as_polygon([a, b, c, d]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -134,8 +135,9 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon(surface.clone(), [a, b, c, d]); - face.add_interior_polygon(surface.clone(), [e, f, g, h]); + face.exterior.write().surface = Partial::from(surface.clone()); + face.update_exterior_as_polygon([a, b, c, d]); + face.add_interior_polygon([e, f, g, h]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -193,7 +195,8 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon(surface.clone(), [a, b, c, d, e]); + face.exterior.write().surface = Partial::from(surface.clone()); + face.update_exterior_as_polygon([a, b, c, d, e]); let face = face .build(&mut services.objects) .insert(&mut services.objects); diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 4944c8b61..cc34a6d36 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -1,7 +1,7 @@ use fj_math::Point; use crate::{ - objects::{HalfEdge, Surface}, + objects::HalfEdge, partial::{Partial, PartialCycle}, }; @@ -12,7 +12,6 @@ pub trait CycleBuilder { /// Create a cycle as a polygonal chain from the provided points fn update_as_polygon_from_points( &mut self, - surface: impl Into>, points: impl IntoIterator>>, ) -> Vec>; @@ -49,17 +48,14 @@ pub trait CycleBuilder { impl CycleBuilder for PartialCycle { fn update_as_polygon_from_points( &mut self, - surface: impl Into>, points: impl IntoIterator>>, ) -> Vec> { - let surface = surface.into(); let mut points = points.into_iter().map(Into::into); let mut half_edges = Vec::new(); if let Some(point) = points.next() { - let mut half_edge = self.add_half_edge_from_point_to_start(point); - half_edge.write().replace_surface(surface); + let half_edge = self.add_half_edge_from_point_to_start(point); half_edges.push(half_edge); } @@ -111,13 +107,12 @@ impl CycleBuilder for PartialCycle { { let shared_surface_vertex = first_half_edge.read().back().read().surface_form.clone(); - let shared_surface = shared_surface_vertex.read().surface.clone(); let mut new_half_edge = new_half_edge.write(); new_half_edge.front_mut().write().surface_form = shared_surface_vertex; - new_half_edge.replace_surface(shared_surface); + new_half_edge.replace_surface(self.surface.clone()); new_half_edge.infer_global_form(); } diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index c2c0669b8..bc1c49ee9 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -1,7 +1,7 @@ use fj_math::Point; use crate::{ - objects::{HalfEdge, Surface}, + objects::HalfEdge, partial::{Partial, PartialCycle, PartialFace}, }; @@ -12,14 +12,12 @@ pub trait FaceBuilder { /// Update the [`PartialFace`] with an exterior polygon fn update_exterior_as_polygon( &mut self, - surface: impl Into>, points: impl IntoIterator>>, ) -> Vec>; /// Update the [`PartialFace`] with an interior polygon fn add_interior_polygon( &mut self, - surface: impl Into>, points: impl IntoIterator>>, ); } @@ -27,24 +25,20 @@ pub trait FaceBuilder { impl FaceBuilder for PartialFace { fn update_exterior_as_polygon( &mut self, - surface: impl Into>, points: impl IntoIterator>>, ) -> Vec> { - let mut cycle = PartialCycle::default(); - let half_edges = cycle.update_as_polygon_from_points(surface, points); - - self.exterior = Partial::from_partial(cycle); - - half_edges + self.exterior.write().update_as_polygon_from_points(points) } fn add_interior_polygon( &mut self, - surface: impl Into>, points: impl IntoIterator>>, ) { - let mut cycle = PartialCycle::default(); - cycle.update_as_polygon_from_points(surface, points); + let mut cycle = PartialCycle { + surface: self.exterior.read().surface.clone(), + ..Default::default() + }; + cycle.update_as_polygon_from_points(points); self.interiors.push(Partial::from_partial(cycle)); } diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 1e2006ba5..77d952867 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -42,10 +42,13 @@ impl ShellBuilder for PartialShell { objects.surfaces.xy_plane().translate([Z, Z, -h], objects); let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface, - [[-h, -h], [h, -h], [h, h], [-h, h]], - ); + face.exterior.write().surface = Partial::from(surface); + face.update_exterior_as_polygon([ + [-h, -h], + [h, -h], + [h, h], + [-h, h], + ]); face }; @@ -322,8 +325,11 @@ impl ShellBuilder for PartialShell { half_edges.push(Partial::from_partial(half_edge)); } + let mut exterior = PartialCycle::default(); + exterior.half_edges.extend(half_edges); + PartialFace { - exterior: Partial::from_partial(PartialCycle { half_edges }), + exterior: Partial::from_partial(exterior), ..Default::default() } }; diff --git a/crates/fj-kernel/src/builder/sketch.rs b/crates/fj-kernel/src/builder/sketch.rs index c100f0d6f..1436ad2cd 100644 --- a/crates/fj-kernel/src/builder/sketch.rs +++ b/crates/fj-kernel/src/builder/sketch.rs @@ -24,7 +24,8 @@ impl SketchBuilder for PartialSketch { points: impl IntoIterator>>, ) { let mut face = PartialFace::default(); - face.update_exterior_as_polygon(surface, points); + face.exterior.write().surface = surface.into(); + face.update_exterior_as_polygon(points); self.faces.extend([Partial::from_partial(face)]); } diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index 5fd84832a..8a7353747 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -408,11 +408,11 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let object = { - let mut cycle = PartialCycle::default(); - cycle.update_as_polygon_from_points( - surface, - [[0., 0.], [1., 0.], [0., 1.]], - ); + let mut cycle = PartialCycle { + surface: surface.into(), + ..Default::default() + }; + cycle.update_as_polygon_from_points([[0., 0.], [1., 0.], [0., 1.]]); cycle .build(&mut services.objects) .insert(&mut services.objects) @@ -435,12 +435,10 @@ mod tests { fn face() { let mut services = Services::new(); - let surface = services.objects.surfaces.xy_plane(); let mut object = PartialFace::default(); - object.update_exterior_as_polygon( - surface, - [[0., 0.], [1., 0.], [0., 1.]], - ); + object.exterior.write().surface = + Partial::from(services.objects.surfaces.xy_plane()); + object.update_exterior_as_polygon([[0., 0.], [1., 0.], [0., 1.]]); let object = object .build(&mut services.objects) .insert(&mut services.objects); @@ -554,12 +552,10 @@ mod tests { fn sketch() { let mut services = Services::new(); - let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface, - [[0., 0.], [1., 0.], [0., 1.]], - ); + face.exterior.write().surface = + Partial::from(services.objects.surfaces.xy_plane()); + face.update_exterior_as_polygon([[0., 0.], [1., 0.], [0., 1.]]); let object = PartialSketch { faces: vec![Partial::from_partial(face)], } diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index ba1f21fb8..e1d109555 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -7,24 +7,19 @@ use crate::{ /// A partial [`Cycle`] #[derive(Clone, Debug, Default)] pub struct PartialCycle { + /// The surface that the cycle is defined in + pub surface: Partial, + /// The half-edges that make up the cycle pub half_edges: Vec>, } -impl PartialCycle { - /// Access the surface of the [`Cycle`] - pub fn surface(&self) -> Option> { - self.half_edges - .first() - .map(|half_edge| half_edge.read().curve().read().surface.clone()) - } -} - impl PartialObject for PartialCycle { type Full = Cycle; fn from_full(cycle: &Self::Full, cache: &mut FullToPartialCache) -> Self { Self { + surface: Partial::from_full(cycle.surface().clone(), cache), half_edges: cycle .half_edges() .cloned() diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index d0731ec56..1fd6b2fb8 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -78,11 +78,11 @@ mod tests { let mut services = Services::new(); let valid = { - let mut cycle = PartialCycle::default(); - cycle.update_as_polygon_from_points( - services.objects.surfaces.xy_plane(), - [[0., 0.], [1., 0.], [0., 1.]], - ); + let mut cycle = PartialCycle { + surface: Partial::from(services.objects.surfaces.xy_plane()), + ..Default::default() + }; + cycle.update_as_polygon_from_points([[0., 0.], [1., 0.], [0., 1.]]); cycle.build(&mut services.objects) }; let invalid = { diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index 9a84917b7..893683beb 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -108,7 +108,7 @@ mod tests { builder::{CycleBuilder, FaceBuilder}, insert::Insert, objects::Face, - partial::{PartialCycle, PartialFace, PartialObject}, + partial::{Partial, PartialCycle, PartialFace, PartialObject}, services::Services, validate::Validate, }; @@ -121,20 +121,18 @@ mod tests { let valid = { let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface.clone(), - [[0., 0.], [3., 0.], [0., 3.]], - ); - face.add_interior_polygon(surface, [[1., 1.], [1., 2.], [2., 1.]]); + face.exterior.write().surface = Partial::from(surface); + face.update_exterior_as_polygon([[0., 0.], [3., 0.], [0., 3.]]); + face.add_interior_polygon([[1., 1.], [1., 2.], [2., 1.]]); face.build(&mut services.objects) }; let invalid = { - let mut cycle = PartialCycle::default(); - cycle.update_as_polygon_from_points( - services.objects.surfaces.xz_plane(), - [[1., 1.], [1., 2.], [2., 1.]], - ); + let mut cycle = PartialCycle { + surface: Partial::from(services.objects.surfaces.xz_plane()), + ..Default::default() + }; + cycle.update_as_polygon_from_points([[1., 1.], [1., 2.], [2., 1.]]); let cycle = cycle .build(&mut services.objects) .insert(&mut services.objects); @@ -155,11 +153,9 @@ mod tests { let valid = { let mut face = PartialFace::default(); - face.update_exterior_as_polygon( - surface.clone(), - [[0., 0.], [3., 0.], [0., 3.]], - ); - face.add_interior_polygon(surface, [[1., 1.], [1., 2.], [2., 1.]]); + face.exterior.write().surface = Partial::from(surface); + face.update_exterior_as_polygon([[0., 0.], [3., 0.], [0., 3.]]); + face.add_interior_polygon([[1., 1.], [1., 2.], [2., 1.]]); face.build(&mut services.objects) }; let invalid = { diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index c34e44682..61318cce6 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -43,12 +43,14 @@ impl Shape for fj::Sketch { Partial::from_partial(half_edge) }; - let cycle = Partial::from_partial(PartialCycle { - half_edges: vec![half_edge], - }); + let exterior = { + let mut cycle = PartialCycle::default(); + cycle.half_edges.push(half_edge); + Partial::from_partial(cycle) + }; PartialFace { - exterior: cycle, + exterior, color: Some(Color(self.color())), ..Default::default() } @@ -61,7 +63,8 @@ impl Shape for fj::Sketch { .map(Point::from); let mut face = PartialFace::default(); - face.update_exterior_as_polygon(surface, points); + face.exterior.write().surface = Partial::from(surface); + face.update_exterior_as_polygon(points); face.color = Some(Color(self.color())); face