diff --git a/crates/fj-core/src/algorithms/approx/cycle.rs b/crates/fj-core/src/algorithms/approx/cycle.rs index 94c3e9564..ad6d4e489 100644 --- a/crates/fj-core/src/algorithms/approx/cycle.rs +++ b/crates/fj-core/src/algorithms/approx/cycle.rs @@ -26,7 +26,7 @@ impl Approx for (&Cycle, &Surface) { let tolerance = tolerance.into(); let edges = cycle - .edges() + .half_edges() .iter() .map(|edge| { (edge.deref(), surface).approx_with_cache(tolerance, cache) diff --git a/crates/fj-core/src/algorithms/approx/edge.rs b/crates/fj-core/src/algorithms/approx/edge.rs index 6427882b7..b4c05e8ec 100644 --- a/crates/fj-core/src/algorithms/approx/edge.rs +++ b/crates/fj-core/src/algorithms/approx/edge.rs @@ -11,7 +11,7 @@ use fj_math::Point; use crate::{ geometry::{CurveBoundary, GlobalPath, SurfacePath}, - objects::{Curve, Edge, Surface, Vertex}, + objects::{Curve, HalfEdge, Surface, Vertex}, storage::{Handle, HandleWrapper}, }; @@ -22,7 +22,7 @@ use super::{ Approx, ApproxPoint, Tolerance, }; -impl Approx for (&Edge, &Surface) { +impl Approx for (&HalfEdge, &Surface) { type Approximation = EdgeApprox; type Cache = EdgeApproxCache; @@ -109,7 +109,7 @@ impl Approx for (&Edge, &Surface) { } } -/// An approximation of an [`Edge`] +/// An approximation of a [`HalfEdge`] #[derive(Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct EdgeApprox { /// The point that approximates the first vertex of the edge @@ -263,8 +263,8 @@ mod tests { use crate::{ algorithms::approx::{Approx, ApproxPoint}, geometry::{CurveBoundary, GlobalPath, SurfaceGeometry}, - objects::{Edge, Surface}, - operations::BuildEdge, + objects::{HalfEdge, Surface}, + operations::BuildHalfEdge, services::Services, }; @@ -274,7 +274,7 @@ mod tests { let surface = services.objects.surfaces.xz_plane(); let edge = - Edge::line_segment([[1., 1.], [2., 1.]], None, &mut services); + HalfEdge::line_segment([[1., 1.], [2., 1.]], None, &mut services); let tolerance = 1.; let approx = (&edge, surface.deref()).approx(tolerance); @@ -291,7 +291,7 @@ mod tests { v: [0., 0., 1.].into(), }); let edge = - Edge::line_segment([[1., 1.], [2., 1.]], None, &mut services); + HalfEdge::line_segment([[1., 1.], [2., 1.]], None, &mut services); let tolerance = 1.; let approx = (&edge, &surface).approx(tolerance); @@ -310,7 +310,7 @@ mod tests { u: path, v: [0., 0., 1.].into(), }); - let edge = Edge::line_segment( + let edge = HalfEdge::line_segment( [[0., 1.], [TAU, 1.]], Some(boundary.inner), &mut services, @@ -338,7 +338,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xz_plane(); - let edge = Edge::circle([0., 0.], 1., &mut services); + let edge = HalfEdge::circle([0., 0.], 1., &mut services); let tolerance = 1.; let approx = (&edge, surface.deref()).approx(tolerance); diff --git a/crates/fj-core/src/algorithms/bounding_volume/cycle.rs b/crates/fj-core/src/algorithms/bounding_volume/cycle.rs index 84431f075..e705dc308 100644 --- a/crates/fj-core/src/algorithms/bounding_volume/cycle.rs +++ b/crates/fj-core/src/algorithms/bounding_volume/cycle.rs @@ -6,7 +6,7 @@ impl super::BoundingVolume<2> for Cycle { fn aabb(&self) -> Option> { let mut aabb: Option> = None; - for edge in self.edges() { + for edge in self.half_edges() { let new_aabb = edge.aabb().expect("`Edge` can always compute AABB"); aabb = Some(aabb.map_or(new_aabb, |aabb| aabb.merged(&new_aabb))); } diff --git a/crates/fj-core/src/algorithms/bounding_volume/edge.rs b/crates/fj-core/src/algorithms/bounding_volume/edge.rs index 507f6040d..50be621af 100644 --- a/crates/fj-core/src/algorithms/bounding_volume/edge.rs +++ b/crates/fj-core/src/algorithms/bounding_volume/edge.rs @@ -1,8 +1,8 @@ use fj_math::{Aabb, Vector}; -use crate::{geometry::SurfacePath, objects::Edge}; +use crate::{geometry::SurfacePath, objects::HalfEdge}; -impl super::BoundingVolume<2> for Edge { +impl super::BoundingVolume<2> for HalfEdge { fn aabb(&self) -> Option> { match self.path() { SurfacePath::Circle(circle) => { diff --git a/crates/fj-core/src/algorithms/intersect/curve_edge.rs b/crates/fj-core/src/algorithms/intersect/curve_edge.rs index 230a646ca..f4ce6ef55 100644 --- a/crates/fj-core/src/algorithms/intersect/curve_edge.rs +++ b/crates/fj-core/src/algorithms/intersect/curve_edge.rs @@ -1,10 +1,10 @@ use fj_math::{Point, Segment}; -use crate::{geometry::SurfacePath, objects::Edge}; +use crate::{geometry::SurfacePath, objects::HalfEdge}; use super::LineSegmentIntersection; -/// The intersection between a curve and an [`Edge`] +/// The intersection between a curve and a [`HalfEdge`] #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub enum CurveEdgeIntersection { /// The curve and edge intersect at a point @@ -26,8 +26,8 @@ impl CurveEdgeIntersection { /// # Panics /// /// Currently, only intersections between lines and line segments can be - /// computed. Panics, if a different type of curve or [`Edge`] is passed. - pub fn compute(path: &SurfacePath, edge: &Edge) -> Option { + /// computed. Panics, if a different type of curve or [`HalfEdge`] is passed. + pub fn compute(path: &SurfacePath, edge: &HalfEdge) -> Option { let path_as_line = match path { SurfacePath::Line(line) => line, _ => todo!("Curve-edge intersection only supports lines"), @@ -72,7 +72,7 @@ mod tests { use fj_math::Point; use crate::{ - geometry::SurfacePath, objects::Edge, operations::BuildEdge, + geometry::SurfacePath, objects::HalfEdge, operations::BuildHalfEdge, services::Services, }; @@ -84,7 +84,7 @@ mod tests { let path = SurfacePath::u_axis(); let edge = - Edge::line_segment([[1., -1.], [1., 1.]], None, &mut services); + HalfEdge::line_segment([[1., -1.], [1., 1.]], None, &mut services); let intersection = CurveEdgeIntersection::compute(&path, &edge); @@ -101,8 +101,11 @@ mod tests { let mut services = Services::new(); let path = SurfacePath::u_axis(); - let edge = - Edge::line_segment([[-1., -1.], [-1., 1.]], None, &mut services); + let edge = HalfEdge::line_segment( + [[-1., -1.], [-1., 1.]], + None, + &mut services, + ); let intersection = CurveEdgeIntersection::compute(&path, &edge); @@ -119,8 +122,11 @@ mod tests { let mut services = Services::new(); let path = SurfacePath::u_axis(); - let edge = - Edge::line_segment([[-1., -1.], [1., -1.]], None, &mut services); + let edge = HalfEdge::line_segment( + [[-1., -1.], [1., -1.]], + None, + &mut services, + ); let intersection = CurveEdgeIntersection::compute(&path, &edge); @@ -133,7 +139,7 @@ mod tests { let path = SurfacePath::u_axis(); let edge = - Edge::line_segment([[-1., 0.], [1., 0.]], None, &mut services); + HalfEdge::line_segment([[-1., 0.], [1., 0.]], None, &mut services); let intersection = CurveEdgeIntersection::compute(&path, &edge); diff --git a/crates/fj-core/src/algorithms/intersect/curve_face.rs b/crates/fj-core/src/algorithms/intersect/curve_face.rs index 5d5a4e066..5be8c82b4 100644 --- a/crates/fj-core/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-core/src/algorithms/intersect/curve_face.rs @@ -29,7 +29,10 @@ impl CurveFaceIntersection { /// Compute the intersection pub fn compute(path: &SurfacePath, face: &Face) -> Self { - let edges = face.region().all_cycles().flat_map(|cycle| cycle.edges()); + let edges = face + .region() + .all_cycles() + .flat_map(|cycle| cycle.half_edges()); let mut intersections = Vec::new(); diff --git a/crates/fj-core/src/algorithms/intersect/face_point.rs b/crates/fj-core/src/algorithms/intersect/face_point.rs index 50fd269f0..467235439 100644 --- a/crates/fj-core/src/algorithms/intersect/face_point.rs +++ b/crates/fj-core/src/algorithms/intersect/face_point.rs @@ -3,7 +3,7 @@ use fj_math::Point; use crate::{ - objects::{Edge, Face}, + objects::{Face, HalfEdge}, storage::Handle, }; @@ -28,12 +28,12 @@ impl Intersect for (&Face, &Point<2>) { // as long as we initialize the `previous_hit` variable with the // result of the last segment. let mut previous_hit = cycle - .edges() + .half_edges() .iter() .last() .and_then(|edge| (&ray, edge).intersect()); - for (edge, next_edge) in cycle.edges().pairs() { + for (edge, next_edge) in cycle.half_edges().pairs() { let hit = (&ray, edge).intersect(); let count_hit = match (hit, previous_hit) { @@ -122,7 +122,7 @@ pub enum FacePointIntersection { PointIsInsideFace, /// The point is coincident with an edge - PointIsOnEdge(Handle), + PointIsOnEdge(Handle), /// The point is coincident with a vertex PointIsOnVertex(Point<2>), @@ -335,7 +335,7 @@ mod tests { let edge = face .region() .exterior() - .edges() + .half_edges() .iter() .find(|edge| edge.start_position() == Point::from([0., 0.])) .unwrap(); @@ -371,7 +371,7 @@ mod tests { let vertex = face .region() .exterior() - .edges() + .half_edges() .iter() .find(|edge| edge.start_position() == Point::from([1., 0.])) .map(|edge| edge.start_position()) diff --git a/crates/fj-core/src/algorithms/intersect/ray_edge.rs b/crates/fj-core/src/algorithms/intersect/ray_edge.rs index 2e8679b5c..dab988e9d 100644 --- a/crates/fj-core/src/algorithms/intersect/ray_edge.rs +++ b/crates/fj-core/src/algorithms/intersect/ray_edge.rs @@ -5,13 +5,13 @@ use fj_math::Segment; use crate::{ algorithms::intersect::{HorizontalRayToTheRight, Intersect}, geometry::SurfacePath, - objects::Edge, + objects::HalfEdge, storage::Handle, }; use super::ray_segment::RaySegmentIntersection; -impl Intersect for (&HorizontalRayToTheRight<2>, &Handle) { +impl Intersect for (&HorizontalRayToTheRight<2>, &Handle) { type Intersection = RaySegmentIntersection; fn intersect(self) -> Option { diff --git a/crates/fj-core/src/algorithms/intersect/ray_face.rs b/crates/fj-core/src/algorithms/intersect/ray_face.rs index 164c0cb8b..815b24a77 100644 --- a/crates/fj-core/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-core/src/algorithms/intersect/ray_face.rs @@ -5,7 +5,7 @@ use fj_math::{Plane, Point, Scalar}; use crate::{ algorithms::intersect::face_point::FacePointIntersection, geometry::GlobalPath, - objects::{Edge, Face}, + objects::{Face, HalfEdge}, storage::Handle, }; @@ -134,7 +134,7 @@ pub enum RayFaceIntersection { RayHitsFaceAndAreParallel, /// The ray hits an edge - RayHitsEdge(Handle), + RayHitsEdge(Handle), /// The ray hits a vertex RayHitsVertex(Point<2>), @@ -262,7 +262,7 @@ mod tests { let edge = face .region() .exterior() - .edges() + .half_edges() .iter() .find(|edge| edge.start_position() == Point::from([-1., 1.])) .unwrap(); @@ -298,7 +298,7 @@ mod tests { let vertex = face .region() .exterior() - .edges() + .half_edges() .iter() .find(|edge| edge.start_position() == Point::from([-1., -1.])) .map(|edge| edge.start_position()) diff --git a/crates/fj-core/src/algorithms/sweep/edge.rs b/crates/fj-core/src/algorithms/sweep/edge.rs index 5428d29a9..41578f955 100644 --- a/crates/fj-core/src/algorithms/sweep/edge.rs +++ b/crates/fj-core/src/algorithms/sweep/edge.rs @@ -2,16 +2,16 @@ use fj_interop::{ext::ArrayExt, mesh::Color}; use fj_math::{Point, Scalar, Vector}; use crate::{ - objects::{Cycle, Edge, Face, Region, Surface, Vertex}, - operations::{BuildEdge, Insert, UpdateCycle, UpdateEdge}, + objects::{Cycle, Face, HalfEdge, Region, Surface, Vertex}, + operations::{BuildHalfEdge, Insert, UpdateCycle, UpdateHalfEdge}, services::Services, storage::Handle, }; use super::{Sweep, SweepCache}; -impl Sweep for (&Edge, &Handle, &Surface, Option) { - type Swept = (Handle, Handle); +impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { + type Swept = (Handle, Handle); fn sweep_with_cache( self, @@ -81,7 +81,7 @@ impl Sweep for (&Edge, &Handle, &Surface, Option) { .zip_ext(curves) .map(|((((boundary, start), end), start_vertex), curve)| { let edge = { - let edge = Edge::line_segment( + let edge = HalfEdge::line_segment( [start, end], Some(boundary), services, @@ -97,8 +97,9 @@ impl Sweep for (&Edge, &Handle, &Surface, Option) { edge.insert(services) }; - exterior = - Some(exterior.take().unwrap().add_edges([edge.clone()])); + exterior = Some( + exterior.take().unwrap().add_half_edges([edge.clone()]), + ); edge }); diff --git a/crates/fj-core/src/algorithms/sweep/face.rs b/crates/fj-core/src/algorithms/sweep/face.rs index f8afd52da..d098e661d 100644 --- a/crates/fj-core/src/algorithms/sweep/face.rs +++ b/crates/fj-core/src/algorithms/sweep/face.rs @@ -61,7 +61,7 @@ impl Sweep for Handle { let cycle = cycle.reverse(services); let mut top_edges = Vec::new(); - for (edge, next) in cycle.edges().pairs() { + for (edge, next) in cycle.half_edges().pairs() { let (face, top_edge) = ( edge.deref(), next.start_vertex(), diff --git a/crates/fj-core/src/algorithms/transform/cycle.rs b/crates/fj-core/src/algorithms/transform/cycle.rs index 98241f52b..e9b886939 100644 --- a/crates/fj-core/src/algorithms/transform/cycle.rs +++ b/crates/fj-core/src/algorithms/transform/cycle.rs @@ -11,7 +11,7 @@ impl TransformObject for Cycle { services: &mut Services, cache: &mut TransformCache, ) -> Self { - let edges = self.edges().iter().map(|edge| { + let edges = self.half_edges().iter().map(|edge| { edge.clone() .transform_with_cache(transform, services, cache) }); diff --git a/crates/fj-core/src/algorithms/transform/edge.rs b/crates/fj-core/src/algorithms/transform/edge.rs index b6c0b93e0..11526bff0 100644 --- a/crates/fj-core/src/algorithms/transform/edge.rs +++ b/crates/fj-core/src/algorithms/transform/edge.rs @@ -1,10 +1,10 @@ use fj_math::Transform; -use crate::{objects::Edge, services::Services}; +use crate::{objects::HalfEdge, services::Services}; use super::{TransformCache, TransformObject}; -impl TransformObject for Edge { +impl TransformObject for HalfEdge { fn transform_with_cache( self, transform: &Transform, diff --git a/crates/fj-core/src/objects/kinds/curve.rs b/crates/fj-core/src/objects/kinds/curve.rs index 73e314e87..f68676e32 100644 --- a/crates/fj-core/src/objects/kinds/curve.rs +++ b/crates/fj-core/src/objects/kinds/curve.rs @@ -1,10 +1,10 @@ /// A curve /// /// `Curve` represents a curve in space, but holds no data to define that curve. -/// It is referenced by [`Edge`], which defines the curve in the coordinates of -/// its surface. +/// It is referenced by [`HalfEdge`], which defines the curve in the coordinates +/// of its surface. /// -/// `Curve` exists to allow identifying which [`Edge`]s are supposed to be +/// `Curve` exists to allow identifying which [`HalfEdge`]s are supposed to be /// coincident in global space. /// /// # Equality @@ -20,7 +20,7 @@ /// `Eq`/`Ord`/..., you can use `HandleWrapper` to do that. It will use /// `Handle::id` to provide those `Eq`/`Ord`/... implementations. /// -/// [`Edge`]: crate::objects::Edge +/// [`HalfEdge`]: crate::objects::HalfEdge #[derive(Clone, Debug, Default, Hash)] pub struct Curve {} diff --git a/crates/fj-core/src/objects/kinds/cycle.rs b/crates/fj-core/src/objects/kinds/cycle.rs index e2e47bbff..f8f92db16 100644 --- a/crates/fj-core/src/objects/kinds/cycle.rs +++ b/crates/fj-core/src/objects/kinds/cycle.rs @@ -2,26 +2,26 @@ use fj_math::{Scalar, Winding}; use crate::{ geometry::SurfacePath, - objects::{handles::Handles, Edge}, + objects::{handles::Handles, HalfEdge}, storage::Handle, }; /// A cycle of connected edges #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct Cycle { - edges: Handles, + half_edges: Handles, } impl Cycle { /// Create an instance of `Cycle` - pub fn new(edges: impl IntoIterator>) -> Self { - let edges = edges.into_iter().collect(); - Self { edges } + pub fn new(half_edges: impl IntoIterator>) -> Self { + let half_edges = half_edges.into_iter().collect(); + Self { half_edges } } /// Access the edges that make up the cycle - pub fn edges(&self) -> &Handles { - &self.edges + pub fn half_edges(&self) -> &Handles { + &self.half_edges } /// Indicate the cycle's winding, assuming a right-handed coordinate system @@ -33,9 +33,9 @@ impl Cycle { // The cycle could be made up of one or two circles. If that is the // case, the winding of the cycle is determined by the winding of the // first circle. - if self.edges.len() < 3 { + if self.half_edges.len() < 3 { let first = self - .edges() + .half_edges() .iter() .next() .expect("Invalid cycle: expected at least one edge"); @@ -64,7 +64,7 @@ impl Cycle { let mut sum = Scalar::ZERO; - for (a, b) in self.edges().pairs() { + for (a, b) in self.half_edges().pairs() { let [a, b] = [a, b].map(|edge| edge.start_position()); sum += (b.u - a.u) * (b.v + a.v); diff --git a/crates/fj-core/src/objects/kinds/edge.rs b/crates/fj-core/src/objects/kinds/edge.rs index 1e38a1076..31aeb265d 100644 --- a/crates/fj-core/src/objects/kinds/edge.rs +++ b/crates/fj-core/src/objects/kinds/edge.rs @@ -13,14 +13,14 @@ use crate::{ /// `Edge`s of other faces, where those faces touch. Such coincident `Edge`s /// must always refer to the same `Curve`. #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] -pub struct Edge { +pub struct HalfEdge { path: SurfacePath, boundary: CurveBoundary>, curve: HandleWrapper, start_vertex: HandleWrapper, } -impl Edge { +impl HalfEdge { /// Create an instance of `Edge` pub fn new( path: SurfacePath, diff --git a/crates/fj-core/src/objects/kinds/face.rs b/crates/fj-core/src/objects/kinds/face.rs index f97b4145d..1c6428dd4 100644 --- a/crates/fj-core/src/objects/kinds/face.rs +++ b/crates/fj-core/src/objects/kinds/face.rs @@ -24,10 +24,10 @@ use crate::{ /// /// Interior cycles must have the opposite winding of the exterior cycle, /// meaning on the front side of the face, they must appear clockwise. This -/// means that all [`Edge`]s that bound a `Face` have the interior of the face -/// on their left side (on the face's front side). +/// means that all [`HalfEdge`]s that bound a `Face` have the interior of the +/// face on their left side (on the face's front side). /// -/// [`Edge`]: crate::objects::Edge +/// [`HalfEdge`]: crate::objects::HalfEdge /// [`Shell`]: crate::objects::Shell #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct Face { diff --git a/crates/fj-core/src/objects/kinds/region.rs b/crates/fj-core/src/objects/kinds/region.rs index a68d06594..a15cc40cf 100644 --- a/crates/fj-core/src/objects/kinds/region.rs +++ b/crates/fj-core/src/objects/kinds/region.rs @@ -10,10 +10,10 @@ use crate::{ /// /// Interior cycles must have the opposite winding of the exterior cycle, /// meaning on the front side of the region, they must appear clockwise. This -/// means that all [`Edge`]s that bound a `Region` have the interior of the +/// means that all [`HalfEdge`]s that bound a `Region` have the interior of the /// region on their left side (on the region's front side). /// -/// [`Edge`]: crate::objects::Edge +/// [`HalfEdge`]: crate::objects::HalfEdge #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct Region { exterior: Handle, diff --git a/crates/fj-core/src/objects/mod.rs b/crates/fj-core/src/objects/mod.rs index 033d91c0d..606edc845 100644 --- a/crates/fj-core/src/objects/mod.rs +++ b/crates/fj-core/src/objects/mod.rs @@ -50,7 +50,7 @@ pub use self::{ kinds::{ curve::Curve, cycle::Cycle, - edge::Edge, + edge::HalfEdge, face::{Face, Handedness}, region::Region, shell::Shell, diff --git a/crates/fj-core/src/objects/object.rs b/crates/fj-core/src/objects/object.rs index d6b465bf8..3cddf3f7a 100644 --- a/crates/fj-core/src/objects/object.rs +++ b/crates/fj-core/src/objects/object.rs @@ -1,6 +1,6 @@ use crate::{ objects::{ - Curve, Cycle, Edge, Face, Objects, Region, Shell, Sketch, Solid, + Curve, Cycle, Face, HalfEdge, Objects, Region, Shell, Sketch, Solid, Surface, Vertex, }, storage::{Handle, HandleWrapper, ObjectId}, @@ -94,7 +94,7 @@ object!( Curve, "curve", curves; Cycle, "cycle", cycles; Face, "face", faces; - Edge, "edge", edges; + HalfEdge, "half-edge", half_edges; Region, "region", regions; Shell, "shell", shells; Sketch, "sketch", sketches; diff --git a/crates/fj-core/src/objects/set.rs b/crates/fj-core/src/objects/set.rs index 59b44c30b..72117a153 100644 --- a/crates/fj-core/src/objects/set.rs +++ b/crates/fj-core/src/objects/set.rs @@ -1,6 +1,8 @@ use std::collections::{btree_set, BTreeSet}; -use super::{BehindHandle, Curve, Cycle, Edge, Face, Object, Surface, Vertex}; +use super::{ + BehindHandle, Curve, Cycle, Face, HalfEdge, Object, Surface, Vertex, +}; /// A graph of objects and their relationships pub struct ObjectSet { @@ -61,7 +63,7 @@ impl InsertIntoSet for Curve { impl InsertIntoSet for Cycle { fn insert_into_set(&self, objects: &mut ObjectSet) { - for edge in self.edges() { + for edge in self.half_edges() { objects.inner.insert(edge.clone().into()); edge.insert_into_set(objects); } @@ -87,7 +89,7 @@ impl InsertIntoSet for Face { } } -impl InsertIntoSet for Edge { +impl InsertIntoSet for HalfEdge { fn insert_into_set(&self, objects: &mut ObjectSet) { objects.inner.insert(self.curve().clone().into()); self.curve().insert_into_set(objects); diff --git a/crates/fj-core/src/objects/stores.rs b/crates/fj-core/src/objects/stores.rs index 00796bb72..c9811c6a3 100644 --- a/crates/fj-core/src/objects/stores.rs +++ b/crates/fj-core/src/objects/stores.rs @@ -6,7 +6,7 @@ use crate::{ }; use super::{ - Curve, Cycle, Edge, Face, Region, Shell, Sketch, Solid, Surface, Vertex, + Curve, Cycle, Face, HalfEdge, Region, Shell, Sketch, Solid, Surface, Vertex, }; /// The available object stores @@ -18,12 +18,12 @@ pub struct Objects { /// Store for [`Cycle`]s pub cycles: Store, - /// Store for [`Edge`]s - pub edges: Store, - /// Store for [`Face`]s pub faces: Store, + /// Store for [`HalfEdge`]s + pub half_edges: Store, + /// Store for [`Region`]s pub regions: Store, diff --git a/crates/fj-core/src/operations/build/cycle.rs b/crates/fj-core/src/operations/build/cycle.rs index 5ecf4211e..bc6bc611d 100644 --- a/crates/fj-core/src/operations/build/cycle.rs +++ b/crates/fj-core/src/operations/build/cycle.rs @@ -2,8 +2,8 @@ use fj_math::{Point, Scalar}; use itertools::Itertools; use crate::{ - objects::{Cycle, Edge}, - operations::{BuildEdge, Insert, UpdateCycle}, + objects::{Cycle, HalfEdge}, + operations::{BuildHalfEdge, Insert, UpdateCycle}, services::Services, }; @@ -20,8 +20,9 @@ pub trait BuildCycle { radius: impl Into, services: &mut Services, ) -> Cycle { - let circle = Edge::circle(center, radius, services).insert(services); - Cycle::empty().add_edges([circle]) + let circle = + HalfEdge::circle(center, radius, services).insert(services); + Cycle::empty().add_half_edges([circle]) } /// Build a polygon @@ -36,7 +37,7 @@ pub trait BuildCycle { .map(Into::into) .circular_tuple_windows() .map(|(start, end)| { - Edge::line_segment([start, end], None, services) + HalfEdge::line_segment([start, end], None, services) .insert(services) }); diff --git a/crates/fj-core/src/operations/build/edge.rs b/crates/fj-core/src/operations/build/edge.rs index fd33b319e..4356174ac 100644 --- a/crates/fj-core/src/operations/build/edge.rs +++ b/crates/fj-core/src/operations/build/edge.rs @@ -3,23 +3,23 @@ use fj_math::{Arc, Point, Scalar}; use crate::{ geometry::{CurveBoundary, SurfacePath}, - objects::{Curve, Edge, Vertex}, + objects::{Curve, HalfEdge, Vertex}, operations::Insert, services::Services, }; -/// Build an [`Edge`] -pub trait BuildEdge { - /// Create an edge that is not joined to another +/// Build a [`HalfEdge`] +pub trait BuildHalfEdge { + /// Create a half-edge that is not joined to a sibling fn unjoined( path: SurfacePath, boundary: impl Into>>, services: &mut Services, - ) -> Edge { + ) -> HalfEdge { let curve = Curve::new().insert(services); let start_vertex = Vertex::new().insert(services); - Edge::new(path, boundary, curve, start_vertex) + HalfEdge::new(path, boundary, curve, start_vertex) } /// Create an arc @@ -32,7 +32,7 @@ pub trait BuildEdge { end: impl Into>, angle_rad: impl Into, services: &mut Services, - ) -> Edge { + ) -> HalfEdge { let angle_rad = angle_rad.into(); if angle_rad <= -Scalar::TAU || angle_rad >= Scalar::TAU { panic!("arc angle must be in the range (-2pi, 2pi) radians"); @@ -45,7 +45,7 @@ pub trait BuildEdge { let boundary = [arc.start_angle, arc.end_angle].map(|coord| Point::from([coord])); - Edge::unjoined(path, boundary, services) + HalfEdge::unjoined(path, boundary, services) } /// Create a circle @@ -53,12 +53,12 @@ pub trait BuildEdge { center: impl Into>, radius: impl Into, services: &mut Services, - ) -> Edge { + ) -> HalfEdge { let path = SurfacePath::circle_from_center_and_radius(center, radius); let boundary = [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); - Edge::unjoined(path, boundary, services) + HalfEdge::unjoined(path, boundary, services) } /// Create a line segment @@ -66,15 +66,15 @@ pub trait BuildEdge { points_surface: [impl Into>; 2], boundary: Option<[Point<1>; 2]>, services: &mut Services, - ) -> Edge { + ) -> HalfEdge { let boundary = boundary.unwrap_or_else(|| [[0.], [1.]].map(Point::from)); let path = SurfacePath::line_from_points_with_coords( boundary.zip_ext(points_surface), ); - Edge::unjoined(path, boundary, services) + HalfEdge::unjoined(path, boundary, services) } } -impl BuildEdge for Edge {} +impl BuildHalfEdge for HalfEdge {} diff --git a/crates/fj-core/src/operations/build/face.rs b/crates/fj-core/src/operations/build/face.rs index 361638565..3e8dccb34 100644 --- a/crates/fj-core/src/operations/build/face.rs +++ b/crates/fj-core/src/operations/build/face.rs @@ -4,7 +4,7 @@ use fj_interop::ext::ArrayExt; use fj_math::Point; use crate::{ - objects::{Cycle, Edge, Face, Region, Surface, Vertex}, + objects::{Cycle, Face, HalfEdge, Region, Surface, Vertex}, operations::{ BuildCycle, BuildRegion, BuildSurface, Insert, IsInserted, IsInsertedNo, }, @@ -31,8 +31,9 @@ pub trait BuildFace { let face = Face::polygon(surface, points_surface, services); - let edges = { - let mut edges = face.region().exterior().edges().iter().cloned(); + let half_edges = { + let mut edges = + face.region().exterior().half_edges().iter().cloned(); let array = array::from_fn(|_| edges.next()).map(|edge| { edge.expect("Just asserted that there are three edges") @@ -42,13 +43,13 @@ pub trait BuildFace { array }; - let vertices = edges + let vertices = half_edges .each_ref_ext() - .map(|edge: &Handle| edge.start_vertex().clone()); + .map(|edge: &Handle| edge.start_vertex().clone()); Polygon { face, - edges, + half_edges, vertices, } } @@ -82,8 +83,8 @@ pub struct Polygon { /// The face that forms the polygon pub face: I::T, - /// The edges of the polygon - pub edges: [Handle; D], + /// The half-edges of the polygon + pub half_edges: [Handle; D], /// The vertices of the polygon pub vertices: [Handle; D], @@ -95,11 +96,11 @@ impl Polygon { /// Returns a new instance of `Polygon` with the replaced face. Also updates /// the other fields of `Polygon` to match the new face. pub fn replace_face(&self, face: I::T) -> Self { - let edges = array::from_fn(|i| { + let half_edges = array::from_fn(|i| { face.borrow() .region() .exterior() - .edges() + .half_edges() .nth(i) .expect("Operation should not have changed length of cycle") .clone() @@ -111,7 +112,7 @@ impl Polygon { face.borrow() .region() .exterior() - .edges() + .half_edges() .nth(i) .expect("Operation should not have changed length of cycle") .start_vertex() @@ -120,7 +121,7 @@ impl Polygon { Self { face, - edges, + half_edges, vertices, } } diff --git a/crates/fj-core/src/operations/build/shell.rs b/crates/fj-core/src/operations/build/shell.rs index bc9dd78ff..05b7b54ed 100644 --- a/crates/fj-core/src/operations/build/shell.rs +++ b/crates/fj-core/src/operations/build/shell.rs @@ -46,10 +46,13 @@ pub trait BuildShell { region .update_exterior(|cycle| { cycle - .update_edge(cycle.edges().nth_circular(0), |edge| { - edge.reverse_curve_coordinate_systems(services) - .insert(services) - }) + .update_half_edge( + cycle.half_edges().nth_circular(0), + |edge| { + edge.reverse_curve_coordinate_systems(services) + .insert(services) + }, + ) .join_to( abc.face.region().exterior(), 0..=0, @@ -64,20 +67,26 @@ pub trait BuildShell { region .update_exterior(|cycle| { cycle - .update_edge(cycle.edges().nth_circular(1), |edge| { - edge.reverse_curve_coordinate_systems(services) - .insert(services) - }) + .update_half_edge( + cycle.half_edges().nth_circular(1), + |edge| { + edge.reverse_curve_coordinate_systems(services) + .insert(services) + }, + ) .join_to( abc.face.region().exterior(), 1..=1, 2..=2, services, ) - .update_edge(cycle.edges().nth_circular(0), |edge| { - edge.reverse_curve_coordinate_systems(services) - .insert(services) - }) + .update_half_edge( + cycle.half_edges().nth_circular(0), + |edge| { + edge.reverse_curve_coordinate_systems(services) + .insert(services) + }, + ) .join_to( bad.face.region().exterior(), 0..=0, @@ -92,18 +101,27 @@ pub trait BuildShell { region .update_exterior(|cycle| { cycle - .update_edge(cycle.edges().nth_circular(0), |edge| { - edge.reverse_curve_coordinate_systems(services) - .insert(services) - }) - .update_edge(cycle.edges().nth_circular(1), |edge| { - edge.reverse_curve_coordinate_systems(services) - .insert(services) - }) - .update_edge(cycle.edges().nth_circular(2), |edge| { - edge.reverse_curve_coordinate_systems(services) - .insert(services) - }) + .update_half_edge( + cycle.half_edges().nth_circular(0), + |edge| { + edge.reverse_curve_coordinate_systems(services) + .insert(services) + }, + ) + .update_half_edge( + cycle.half_edges().nth_circular(1), + |edge| { + edge.reverse_curve_coordinate_systems(services) + .insert(services) + }, + ) + .update_half_edge( + cycle.half_edges().nth_circular(2), + |edge| { + edge.reverse_curve_coordinate_systems(services) + .insert(services) + }, + ) .join_to( abc.face.region().exterior(), 0..=0, diff --git a/crates/fj-core/src/operations/insert/insert_trait.rs b/crates/fj-core/src/operations/insert/insert_trait.rs index bf1d0a40a..bac9fa1d6 100644 --- a/crates/fj-core/src/operations/insert/insert_trait.rs +++ b/crates/fj-core/src/operations/insert/insert_trait.rs @@ -1,6 +1,7 @@ use crate::{ objects::{ - Curve, Cycle, Edge, Face, Region, Shell, Sketch, Solid, Surface, Vertex, + Curve, Cycle, Face, HalfEdge, Region, Shell, Sketch, Solid, Surface, + Vertex, }, operations::{Polygon, TetrahedronShell}, services::Services, @@ -46,7 +47,7 @@ impl_insert!( Curve, curves; Cycle, cycles; Face, faces; - Edge, edges; + HalfEdge, half_edges; Region, regions; Shell, shells; Sketch, sketches; @@ -61,7 +62,7 @@ impl Insert for Polygon { fn insert(self, services: &mut Services) -> Self::Inserted { Polygon { face: self.face.insert(services), - edges: self.edges, + half_edges: self.half_edges, vertices: self.vertices, } } diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index 4ecd16c0a..e89e7814d 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -5,8 +5,8 @@ use itertools::Itertools; use crate::{ geometry::{CurveBoundary, SurfacePath}, - objects::{Cycle, Edge}, - operations::{BuildEdge, Insert, UpdateCycle, UpdateEdge}, + objects::{Cycle, HalfEdge}, + operations::{BuildHalfEdge, Insert, UpdateCycle, UpdateHalfEdge}, services::Services, storage::Handle, }; @@ -18,7 +18,7 @@ pub trait JoinCycle { fn add_joined_edges(&self, edges: Es, services: &mut Services) -> Self where Es: IntoIterator< - Item = (Handle, SurfacePath, CurveBoundary>), + Item = (Handle, SurfacePath, CurveBoundary>), >, Es::IntoIter: Clone + ExactSizeIterator; @@ -77,13 +77,13 @@ impl JoinCycle for Cycle { fn add_joined_edges(&self, edges: Es, services: &mut Services) -> Self where Es: IntoIterator< - Item = (Handle, SurfacePath, CurveBoundary>), + Item = (Handle, SurfacePath, CurveBoundary>), >, Es::IntoIter: Clone + ExactSizeIterator, { - self.add_edges(edges.into_iter().circular_tuple_windows().map( + self.add_half_edges(edges.into_iter().circular_tuple_windows().map( |((prev, _, _), (edge, curve, boundary))| { - Edge::unjoined(curve, boundary, services) + HalfEdge::unjoined(curve, boundary, services) .update_curve(|_| edge.curve().clone()) .update_start_vertex(|_| prev.start_vertex().clone()) .insert(services) @@ -107,26 +107,32 @@ impl JoinCycle for Cycle { range.zip(range_other).fold( self.clone(), |cycle, (index, index_other)| { - let edge_other = other.edges().nth_circular(index_other); + let edge_other = other.half_edges().nth_circular(index_other); cycle - .update_edge(self.edges().nth_circular(index), |edge| { - edge.update_curve(|_| edge_other.curve().clone()) - .update_start_vertex(|_| { - other - .edges() - .nth_circular(index_other + 1) - .start_vertex() - .clone() + .update_half_edge( + self.half_edges().nth_circular(index), + |edge| { + edge.update_curve(|_| edge_other.curve().clone()) + .update_start_vertex(|_| { + other + .half_edges() + .nth_circular(index_other + 1) + .start_vertex() + .clone() + }) + .insert(services) + }, + ) + .update_half_edge( + self.half_edges().nth_circular(index + 1), + |edge| { + edge.update_start_vertex(|_| { + edge_other.start_vertex().clone() }) .insert(services) - }) - .update_edge(self.edges().nth_circular(index + 1), |edge| { - edge.update_start_vertex(|_| { - edge_other.start_vertex().clone() - }) - .insert(services) - }) + }, + ) }, ) } diff --git a/crates/fj-core/src/operations/mod.rs b/crates/fj-core/src/operations/mod.rs index c9b7b1bd5..3cd87865a 100644 --- a/crates/fj-core/src/operations/mod.rs +++ b/crates/fj-core/src/operations/mod.rs @@ -10,7 +10,7 @@ mod update; pub use self::{ build::{ cycle::BuildCycle, - edge::BuildEdge, + edge::BuildHalfEdge, face::{BuildFace, Polygon}, region::BuildRegion, shell::{BuildShell, TetrahedronShell}, @@ -23,7 +23,7 @@ pub use self::{ merge::Merge, reverse::Reverse, update::{ - cycle::UpdateCycle, edge::UpdateEdge, face::UpdateFace, + cycle::UpdateCycle, edge::UpdateHalfEdge, face::UpdateFace, region::UpdateRegion, shell::UpdateShell, sketch::UpdateSketch, solid::UpdateSolid, }, diff --git a/crates/fj-core/src/operations/reverse/cycle.rs b/crates/fj-core/src/operations/reverse/cycle.rs index 5e569163a..de654b2a8 100644 --- a/crates/fj-core/src/operations/reverse/cycle.rs +++ b/crates/fj-core/src/operations/reverse/cycle.rs @@ -1,5 +1,5 @@ use crate::{ - objects::{Cycle, Edge}, + objects::{Cycle, HalfEdge}, operations::Insert, services::Services, }; @@ -9,10 +9,10 @@ use super::{Reverse, ReverseCurveCoordinateSystems}; impl Reverse for Cycle { fn reverse(&self, services: &mut Services) -> Self { let mut edges = self - .edges() + .half_edges() .pairs() .map(|(current, next)| { - Edge::new( + HalfEdge::new( current.path(), current.boundary().reverse(), current.curve().clone(), @@ -33,7 +33,7 @@ impl ReverseCurveCoordinateSystems for Cycle { &self, services: &mut Services, ) -> Self { - let edges = self.edges().iter().map(|edge| { + let edges = self.half_edges().iter().map(|edge| { edge.reverse_curve_coordinate_systems(services) .insert(services) }); diff --git a/crates/fj-core/src/operations/reverse/edge.rs b/crates/fj-core/src/operations/reverse/edge.rs index 4079289e5..3820d0422 100644 --- a/crates/fj-core/src/operations/reverse/edge.rs +++ b/crates/fj-core/src/operations/reverse/edge.rs @@ -1,13 +1,13 @@ -use crate::{objects::Edge, services::Services}; +use crate::{objects::HalfEdge, services::Services}; use super::ReverseCurveCoordinateSystems; -impl ReverseCurveCoordinateSystems for Edge { +impl ReverseCurveCoordinateSystems for HalfEdge { fn reverse_curve_coordinate_systems(&self, _: &mut Services) -> Self { let path = self.path().reverse(); let boundary = self.boundary().reverse(); - Edge::new( + HalfEdge::new( path, boundary, self.curve().clone(), diff --git a/crates/fj-core/src/operations/update/cycle.rs b/crates/fj-core/src/operations/update/cycle.rs index df4b3c720..b7e5ab9b7 100644 --- a/crates/fj-core/src/operations/update/cycle.rs +++ b/crates/fj-core/src/operations/update/cycle.rs @@ -1,5 +1,5 @@ use crate::{ - objects::{Cycle, Edge}, + objects::{Cycle, HalfEdge}, storage::Handle, }; @@ -7,7 +7,10 @@ use crate::{ pub trait UpdateCycle { /// Add edges to the cycle #[must_use] - fn add_edges(&self, edges: impl IntoIterator>) -> Self; + fn add_half_edges( + &self, + edges: impl IntoIterator>, + ) -> Self; /// Update an edge of the cycle /// @@ -17,16 +20,16 @@ pub trait UpdateCycle { /// /// [`Handles::update`]: crate::objects::Handles::update #[must_use] - fn update_edge( + fn update_half_edge( &self, - handle: &Handle, - update: impl FnOnce(&Handle) -> Handle, + handle: &Handle, + update: impl FnOnce(&Handle) -> Handle, ) -> Self; /// Replace an edge of the cycle /// - /// This is a more general version of [`UpdateCycle::update_edge`] which can - /// replace a single edge with multiple others. + /// This is a more general version of [`UpdateCycle::update_half_edge`] + /// which can replace a single edge with multiple others. /// /// # Panics /// @@ -34,34 +37,37 @@ pub trait UpdateCycle { /// /// [`Handles::replace`]: crate::objects::Handles::replace #[must_use] - fn replace_edge( + fn replace_half_edge( &self, - handle: &Handle, - replace: impl FnOnce(&Handle) -> [Handle; N], + handle: &Handle, + replace: impl FnOnce(&Handle) -> [Handle; N], ) -> Self; } impl UpdateCycle for Cycle { - fn add_edges(&self, edges: impl IntoIterator>) -> Self { - let edges = self.edges().iter().cloned().chain(edges); + fn add_half_edges( + &self, + edges: impl IntoIterator>, + ) -> Self { + let edges = self.half_edges().iter().cloned().chain(edges); Cycle::new(edges) } - fn update_edge( + fn update_half_edge( &self, - handle: &Handle, - update: impl FnOnce(&Handle) -> Handle, + handle: &Handle, + update: impl FnOnce(&Handle) -> Handle, ) -> Self { - let edges = self.edges().update(handle, update); + let edges = self.half_edges().update(handle, update); Cycle::new(edges) } - fn replace_edge( + fn replace_half_edge( &self, - handle: &Handle, - replace: impl FnOnce(&Handle) -> [Handle; N], + handle: &Handle, + replace: impl FnOnce(&Handle) -> [Handle; N], ) -> Self { - let edges = self.edges().replace(handle, replace); + let edges = self.half_edges().replace(handle, replace); Cycle::new(edges) } } diff --git a/crates/fj-core/src/operations/update/edge.rs b/crates/fj-core/src/operations/update/edge.rs index b1b180def..c555c9cf8 100644 --- a/crates/fj-core/src/operations/update/edge.rs +++ b/crates/fj-core/src/operations/update/edge.rs @@ -2,12 +2,12 @@ use fj_math::Point; use crate::{ geometry::{CurveBoundary, SurfacePath}, - objects::{Curve, Edge, Vertex}, + objects::{Curve, HalfEdge, Vertex}, storage::Handle, }; -/// Update a [`Edge`] -pub trait UpdateEdge { +/// Update a [`HalfEdge`] +pub trait UpdateHalfEdge { /// Update the path of the edge #[must_use] fn update_path( @@ -37,12 +37,12 @@ pub trait UpdateEdge { ) -> Self; } -impl UpdateEdge for Edge { +impl UpdateHalfEdge for HalfEdge { fn update_path( &self, update: impl FnOnce(SurfacePath) -> SurfacePath, ) -> Self { - Edge::new( + HalfEdge::new( update(self.path()), self.boundary(), self.curve().clone(), @@ -54,7 +54,7 @@ impl UpdateEdge for Edge { &self, update: impl FnOnce(CurveBoundary>) -> CurveBoundary>, ) -> Self { - Edge::new( + HalfEdge::new( self.path(), update(self.boundary()), self.curve().clone(), @@ -66,7 +66,7 @@ impl UpdateEdge for Edge { &self, update: impl FnOnce(&Handle) -> Handle, ) -> Self { - Edge::new( + HalfEdge::new( self.path(), self.boundary(), update(self.curve()), @@ -78,7 +78,7 @@ impl UpdateEdge for Edge { &self, update: impl FnOnce(&Handle) -> Handle, ) -> Self { - Edge::new( + HalfEdge::new( self.path(), self.boundary(), self.curve().clone(), diff --git a/crates/fj-core/src/queries/all_edges_with_surface.rs b/crates/fj-core/src/queries/all_edges_with_surface.rs index f77dd4424..e2901009a 100644 --- a/crates/fj-core/src/queries/all_edges_with_surface.rs +++ b/crates/fj-core/src/queries/all_edges_with_surface.rs @@ -1,5 +1,5 @@ use crate::{ - objects::{Edge, Face, Shell, Surface}, + objects::{Face, HalfEdge, Shell, Surface}, storage::Handle, }; @@ -8,19 +8,19 @@ pub trait AllEdgesWithSurface { /// Access all edges referenced by the object and the surface they're on fn all_edges_with_surface( &self, - result: &mut Vec<(Handle, Handle)>, + result: &mut Vec<(Handle, Handle)>, ); } impl AllEdgesWithSurface for Face { fn all_edges_with_surface( &self, - result: &mut Vec<(Handle, Handle)>, + result: &mut Vec<(Handle, Handle)>, ) { for cycle in self.region().all_cycles() { result.extend( cycle - .edges() + .half_edges() .iter() .cloned() .map(|edge| (edge, self.surface().clone())), @@ -32,7 +32,7 @@ impl AllEdgesWithSurface for Face { impl AllEdgesWithSurface for Shell { fn all_edges_with_surface( &self, - result: &mut Vec<(Handle, Handle)>, + result: &mut Vec<(Handle, Handle)>, ) { for face in self.faces() { face.all_edges_with_surface(result); diff --git a/crates/fj-core/src/queries/bounding_vertices_of_edge.rs b/crates/fj-core/src/queries/bounding_vertices_of_edge.rs index 845629c3c..7c86118d9 100644 --- a/crates/fj-core/src/queries/bounding_vertices_of_edge.rs +++ b/crates/fj-core/src/queries/bounding_vertices_of_edge.rs @@ -1,6 +1,6 @@ use crate::{ geometry::CurveBoundary, - objects::{Cycle, Edge, Face, Region, Shell, Vertex}, + objects::{Cycle, Face, HalfEdge, Region, Shell, Vertex}, storage::Handle, }; @@ -12,17 +12,17 @@ pub trait BoundingVerticesOfEdge { /// method is called on. fn bounding_vertices_of_edge( &self, - edge: &Handle, + edge: &Handle, ) -> Option>; } impl BoundingVerticesOfEdge for Cycle { fn bounding_vertices_of_edge( &self, - edge: &Handle, + edge: &Handle, ) -> Option> { let start = edge.start_vertex().clone(); - let end = self.edges().after(edge)?.start_vertex().clone(); + let end = self.half_edges().after(edge)?.start_vertex().clone(); Some(CurveBoundary::from([start, end])) } @@ -31,7 +31,7 @@ impl BoundingVerticesOfEdge for Cycle { impl BoundingVerticesOfEdge for Region { fn bounding_vertices_of_edge( &self, - edge: &Handle, + edge: &Handle, ) -> Option> { for cycle in self.all_cycles() { if let Some(vertices) = cycle.bounding_vertices_of_edge(edge) { @@ -46,7 +46,7 @@ impl BoundingVerticesOfEdge for Region { impl BoundingVerticesOfEdge for Face { fn bounding_vertices_of_edge( &self, - edge: &Handle, + edge: &Handle, ) -> Option> { self.region().bounding_vertices_of_edge(edge) } @@ -55,7 +55,7 @@ impl BoundingVerticesOfEdge for Face { impl BoundingVerticesOfEdge for Shell { fn bounding_vertices_of_edge( &self, - edge: &Handle, + edge: &Handle, ) -> Option> { for face in self.faces() { if let Some(vertices) = face.bounding_vertices_of_edge(edge) { diff --git a/crates/fj-core/src/validate/cycle.rs b/crates/fj-core/src/validate/cycle.rs index 81a00b817..3cfe70f8f 100644 --- a/crates/fj-core/src/validate/cycle.rs +++ b/crates/fj-core/src/validate/cycle.rs @@ -1,6 +1,6 @@ use fj_math::{Point, Scalar}; -use crate::objects::{Cycle, Edge}; +use crate::objects::{Cycle, HalfEdge}; use super::{Validate, ValidationConfig, ValidationError}; @@ -23,23 +23,23 @@ pub enum CycleValidationError { "Adjacent `Edge`s are distinct\n\ - End position of first `Edge`: {end_of_first:?}\n\ - Start position of second `Edge`: {start_of_second:?}\n\ - - `Edge`s: {edges:#?}" + - `Edge`s: {half_edges:#?}" )] EdgesDisconnected { - /// The end position of the first [`Edge`] + /// The end position of the first [`HalfEdge`] end_of_first: Point<2>, - /// The start position of the second [`Edge`] + /// The start position of the second [`HalfEdge`] start_of_second: Point<2>, /// The distance between the two vertices distance: Scalar, /// The edges - edges: Box<(Edge, Edge)>, + half_edges: Box<(HalfEdge, HalfEdge)>, }, - /// [`Cycle`]'s should have at least one [`Edge`] + /// [`Cycle`]'s should have at least one [`HalfEdge`] #[error("Expected at least one `Edge`\n")] NotEnoughEdges, } @@ -51,7 +51,7 @@ impl CycleValidationError { errors: &mut Vec, ) { // If there are no half edges - if cycle.edges().iter().next().is_none() { + if cycle.half_edges().iter().next().is_none() { errors.push(Self::NotEnoughEdges.into()); } } @@ -61,7 +61,7 @@ impl CycleValidationError { config: &ValidationConfig, errors: &mut Vec, ) { - for (first, second) in cycle.edges().pairs() { + for (first, second) in cycle.half_edges().pairs() { let end_of_first = { let [_, end] = first.boundary().inner; first.path().point_from_path_coords(end) @@ -76,7 +76,7 @@ impl CycleValidationError { end_of_first, start_of_second, distance, - edges: Box::new(( + half_edges: Box::new(( first.clone_object(), second.clone_object(), )), @@ -93,8 +93,8 @@ mod tests { use crate::{ assert_contains_err, - objects::{Cycle, Edge}, - operations::{BuildCycle, BuildEdge, Insert, UpdateCycle}, + objects::{Cycle, HalfEdge}, + operations::{BuildCycle, BuildHalfEdge, Insert, UpdateCycle}, services::Services, validate::{cycle::CycleValidationError, Validate, ValidationError}, }; @@ -110,12 +110,20 @@ mod tests { let disconnected = { let edges = [ - Edge::line_segment([[0., 0.], [1., 0.]], None, &mut services), - Edge::line_segment([[0., 0.], [1., 0.]], None, &mut services), + HalfEdge::line_segment( + [[0., 0.], [1., 0.]], + None, + &mut services, + ), + HalfEdge::line_segment( + [[0., 0.], [1., 0.]], + None, + &mut services, + ), ]; let edges = edges.map(|edge| edge.insert(&mut services)); - Cycle::empty().add_edges(edges) + Cycle::empty().add_half_edges(edges) }; assert_contains_err!( diff --git a/crates/fj-core/src/validate/edge.rs b/crates/fj-core/src/validate/edge.rs index d52d301c5..f9ca0e6db 100644 --- a/crates/fj-core/src/validate/edge.rs +++ b/crates/fj-core/src/validate/edge.rs @@ -1,10 +1,10 @@ use fj_math::{Point, Scalar}; -use crate::objects::Edge; +use crate::objects::HalfEdge; use super::{Validate, ValidationConfig, ValidationError}; -impl Validate for Edge { +impl Validate for HalfEdge { fn validate_with_config( &self, config: &ValidationConfig, @@ -14,15 +14,15 @@ impl Validate for Edge { } } -/// [`Edge`] validation failed +/// [`HalfEdge`] validation failed #[derive(Clone, Debug, thiserror::Error)] pub enum EdgeValidationError { - /// [`Edge`]'s vertices are coincident + /// [`HalfEdge`]'s vertices are coincident #[error( "Vertices of `Edge` on curve are coincident\n\ - Position of back vertex: {back_position:?}\n\ - Position of front vertex: {front_position:?}\n\ - - `Edge`: {edge:#?}" + - `Edge`: {half_edge:#?}" )] VerticesAreCoincident { /// The position of the back vertex @@ -35,13 +35,13 @@ pub enum EdgeValidationError { distance: Scalar, /// The edge - edge: Edge, + half_edge: HalfEdge, }, } impl EdgeValidationError { fn check_vertex_coincidence( - edge: &Edge, + edge: &HalfEdge, config: &ValidationConfig, errors: &mut Vec, ) { @@ -54,7 +54,7 @@ impl EdgeValidationError { back_position, front_position, distance, - edge: edge.clone(), + half_edge: edge.clone(), } .into(), ); @@ -68,8 +68,8 @@ mod tests { use crate::{ assert_contains_err, - objects::Edge, - operations::BuildEdge, + objects::HalfEdge, + operations::BuildHalfEdge, services::Services, validate::{EdgeValidationError, Validate, ValidationError}, }; @@ -79,11 +79,11 @@ mod tests { let mut services = Services::new(); let valid = - Edge::line_segment([[0., 0.], [1., 0.]], None, &mut services); + HalfEdge::line_segment([[0., 0.], [1., 0.]], None, &mut services); let invalid = { let boundary = [Point::from([0.]); 2]; - Edge::new( + HalfEdge::new( valid.path(), boundary, valid.curve().clone(), diff --git a/crates/fj-core/src/validate/face.rs b/crates/fj-core/src/validate/face.rs index da834c3d8..be0687d68 100644 --- a/crates/fj-core/src/validate/face.rs +++ b/crates/fj-core/src/validate/face.rs @@ -38,7 +38,7 @@ pub enum FaceValidationError { impl FaceValidationError { fn check_interior_winding(face: &Face, errors: &mut Vec) { - if face.region().exterior().edges().is_empty() { + if face.region().exterior().half_edges().is_empty() { // Can't determine winding, if the cycle has no edges. Sounds like a // job for a different validation check. return; @@ -47,7 +47,7 @@ impl FaceValidationError { let exterior_winding = face.region().exterior().winding(); for interior in face.region().interiors() { - if interior.edges().is_empty() { + if interior.half_edges().is_empty() { // Can't determine winding, if the cycle has no edges. Sounds // like a job for a different validation check. continue; diff --git a/crates/fj-core/src/validate/shell.rs b/crates/fj-core/src/validate/shell.rs index 84cb4dc04..fa39a129b 100644 --- a/crates/fj-core/src/validate/shell.rs +++ b/crates/fj-core/src/validate/shell.rs @@ -4,7 +4,7 @@ use fj_math::{Point, Scalar}; use crate::{ geometry::{CurveBoundaries, SurfaceGeometry}, - objects::{Edge, Shell, Surface}, + objects::{HalfEdge, Shell, Surface}, queries::{AllEdgesWithSurface, BoundingVerticesOfEdge}, storage::{Handle, HandleWrapper}, }; @@ -46,25 +46,25 @@ pub enum ShellValidationError { Edge 1: {0:#?}\n\ Edge 2: {1:#?}" )] - CoincidentEdgesNotIdentical(Handle, Handle), + CoincidentEdgesNotIdentical(Handle, Handle), /// [`Shell`] contains edges that are identical, but do not coincide #[error( "Shell contains `Edge`s that are identical but do not coincide\n\ - Edge 1: {edge_a:#?}\n\ + Edge 1: {half_edge_a:#?}\n\ Surface for edge 1: {surface_a:#?}\n\ - Edge 2: {edge_b:#?}\n\ + Edge 2: {half_edge_b:#?}\n\ Surface for edge 2: {surface_b:#?}" )] IdenticalEdgesNotCoincident { /// The first edge - edge_a: Handle, + half_edge_a: Handle, /// The surface that the first edge is on surface_a: Handle, /// The second edge - edge_b: Handle, + half_edge_b: Handle, /// The surface that the second edge is on surface_b: Handle, @@ -79,14 +79,14 @@ pub enum ShellValidationError { /// /// Returns an [`Iterator`] of the distance at each sample. fn distances( - edge_a: Handle, + edge_a: Handle, surface_a: Handle, - edge_b: Handle, + edge_b: Handle, surface_b: Handle, ) -> impl Iterator { fn sample( percent: f64, - (edge, surface): (&Handle, SurfaceGeometry), + (edge, surface): (&Handle, SurfaceGeometry), ) -> Point<3> { let [start, end] = edge.boundary().inner; let path_coords = start + (end - start) * percent; @@ -132,9 +132,9 @@ impl ShellValidationError { } fn compare_curve_coords( - edge_a: &Handle, + edge_a: &Handle, surface_a: &Handle, - edge_b: &Handle, + edge_b: &Handle, surface_b: &Handle, config: &ValidationConfig, mismatches: &mut Vec, @@ -164,8 +164,8 @@ impl ShellValidationError { if distance > config.identical_max_distance { mismatches.push(CurveCoordinateSystemMismatch { - edge_a: edge_a.clone(), - edge_b: edge_b.clone(), + half_edge_a: edge_a.clone(), + half_edge_b: edge_b.clone(), point_curve, point_a: a_global, point_b: b_global, @@ -255,9 +255,9 @@ impl ShellValidationError { { errors.push( Self::IdenticalEdgesNotCoincident { - edge_a: edge_a.clone(), + half_edge_a: edge_a.clone(), surface_a: surface_a.clone(), - edge_b: edge_b.clone(), + half_edge_b: edge_b.clone(), surface_b: surface_b.clone(), } .into(), @@ -298,7 +298,7 @@ impl ShellValidationError { for face in shell.faces() { for cycle in face.region().all_cycles() { - for edge in cycle.edges() { + for edge in cycle.half_edges() { let curve = HandleWrapper::from(edge.curve().clone()); let unmatched_edges = unmatched_edges_by_curve @@ -327,7 +327,7 @@ impl ShellValidationError { for face in shell.faces() { for cycle in face.region().all_cycles() { - for edge in cycle.edges() { + for edge in cycle.half_edges() { let curve = HandleWrapper::from(edge.curve().clone()); let boundary = cycle .bounding_vertices_of_edge(edge) @@ -362,8 +362,8 @@ impl ShellValidationError { #[derive(Clone, Debug)] pub struct CurveCoordinateSystemMismatch { - pub edge_a: Handle, - pub edge_b: Handle, + pub half_edge_a: Handle, + pub half_edge_b: Handle, pub point_curve: Point<1>, pub point_a: Point<3>, pub point_b: Point<3>, @@ -376,8 +376,8 @@ mod tests { assert_contains_err, objects::{Curve, Shell}, operations::{ - BuildShell, Insert, Reverse, UpdateCycle, UpdateEdge, UpdateFace, - UpdateRegion, UpdateShell, + BuildShell, Insert, Reverse, UpdateCycle, UpdateFace, + UpdateHalfEdge, UpdateRegion, UpdateShell, }, services::Services, validate::{shell::ShellValidationError, Validate, ValidationError}, @@ -396,8 +396,8 @@ mod tests { region .update_exterior(|cycle| { cycle - .update_edge( - cycle.edges().nth_circular(0), + .update_half_edge( + cycle.half_edges().nth_circular(0), |edge| { edge.update_path(|path| path.reverse()) .update_boundary(|boundary| { @@ -437,8 +437,8 @@ mod tests { region .update_exterior(|cycle| { cycle - .update_edge( - cycle.edges().nth_circular(0), + .update_half_edge( + cycle.half_edges().nth_circular(0), |edge| { edge.update_curve(|_| { Curve::new().insert(&mut services) diff --git a/crates/fj-core/src/validate/solid.rs b/crates/fj-core/src/validate/solid.rs index 4c11a405b..0e830d913 100644 --- a/crates/fj-core/src/validate/solid.rs +++ b/crates/fj-core/src/validate/solid.rs @@ -75,7 +75,7 @@ impl SolidValidationError { .flat_map(|face| { face.region() .all_cycles() - .flat_map(|cycle| cycle.edges().iter().cloned()) + .flat_map(|cycle| cycle.half_edges().iter().cloned()) .zip(repeat(face.surface().geometry())) }) .map(|(h, s)| {