Merge pull request #2283 from hannobraun/geometry

Remove redundant geometry from `HalfEdge`
This commit is contained in:
Hanno Braun 2024-03-22 18:23:11 +01:00 committed by GitHub
commit 7115ad074b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 10 additions and 27 deletions

View File

@ -11,7 +11,7 @@ use super::{GlobalPath, HalfEdgeGeometry, SurfaceGeometry};
/// Geometric data that is associated with topological objects /// Geometric data that is associated with topological objects
pub struct Geometry { pub struct Geometry {
half_edge: BTreeMap<Handle<HalfEdge>, HalfEdgeGeometry>, half_edge: BTreeMap<HandleWrapper<HalfEdge>, HalfEdgeGeometry>,
surface: BTreeMap<HandleWrapper<Surface>, SurfaceGeometry>, surface: BTreeMap<HandleWrapper<Surface>, SurfaceGeometry>,
xy_plane: Handle<Surface>, xy_plane: Handle<Surface>,
@ -61,7 +61,7 @@ impl Geometry {
half_edge: Handle<HalfEdge>, half_edge: Handle<HalfEdge>,
geometry: HalfEdgeGeometry, geometry: HalfEdgeGeometry,
) { ) {
self.half_edge.insert(half_edge, geometry); self.half_edge.insert(half_edge.into(), geometry);
} }
pub(crate) fn define_surface_inner( pub(crate) fn define_surface_inner(
@ -82,7 +82,7 @@ impl Geometry {
half_edge: &Handle<HalfEdge>, half_edge: &Handle<HalfEdge>,
) -> HalfEdgeGeometry { ) -> HalfEdgeGeometry {
self.half_edge self.half_edge
.get(half_edge) .get(&half_edge.clone().into())
.copied() .copied()
.expect("Expected geometry of half-edge to be defined") .expect("Expected geometry of half-edge to be defined")
} }

View File

@ -1,7 +1,7 @@
use fj_math::Point; use fj_math::Point;
use crate::{ use crate::{
geometry::{CurveBoundary, SurfacePath}, geometry::CurveBoundary,
objects::{Curve, Vertex}, objects::{Curve, Vertex},
storage::{Handle, HandleWrapper}, storage::{Handle, HandleWrapper},
}; };
@ -35,7 +35,6 @@ use crate::{
/// [`Shell`]: crate::objects::Shell /// [`Shell`]: crate::objects::Shell
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct HalfEdge { pub struct HalfEdge {
path: SurfacePath,
boundary: CurveBoundary<Point<1>>, boundary: CurveBoundary<Point<1>>,
curve: HandleWrapper<Curve>, curve: HandleWrapper<Curve>,
start_vertex: HandleWrapper<Vertex>, start_vertex: HandleWrapper<Vertex>,
@ -44,24 +43,17 @@ pub struct HalfEdge {
impl HalfEdge { impl HalfEdge {
/// Create an instance of `Edge` /// Create an instance of `Edge`
pub fn new( pub fn new(
path: SurfacePath,
boundary: impl Into<CurveBoundary<Point<1>>>, boundary: impl Into<CurveBoundary<Point<1>>>,
curve: Handle<Curve>, curve: Handle<Curve>,
start_vertex: Handle<Vertex>, start_vertex: Handle<Vertex>,
) -> Self { ) -> Self {
Self { Self {
path,
boundary: boundary.into(), boundary: boundary.into(),
curve: curve.into(), curve: curve.into(),
start_vertex: start_vertex.into(), start_vertex: start_vertex.into(),
} }
} }
/// Access the curve that defines the edge's geometry
pub fn path(&self) -> SurfacePath {
self.path
}
/// Access the boundary points of the edge on the curve /// Access the boundary points of the edge on the curve
pub fn boundary(&self) -> CurveBoundary<Point<1>> { pub fn boundary(&self) -> CurveBoundary<Point<1>> {
self.boundary self.boundary

View File

@ -17,14 +17,13 @@ use crate::{
pub trait BuildHalfEdge { pub trait BuildHalfEdge {
/// Create a half-edge that is not joined to a sibling /// Create a half-edge that is not joined to a sibling
fn unjoined( fn unjoined(
path: SurfacePath,
boundary: impl Into<CurveBoundary<Point<1>>>, boundary: impl Into<CurveBoundary<Point<1>>>,
core: &mut Core, core: &mut Core,
) -> HalfEdge { ) -> HalfEdge {
let curve = Curve::new().insert(core); let curve = Curve::new().insert(core);
let start_vertex = Vertex::new().insert(core); let start_vertex = Vertex::new().insert(core);
HalfEdge::new(path, boundary, curve, start_vertex) HalfEdge::new(boundary, curve, start_vertex)
} }
/// Create a half-edge from its sibling /// Create a half-edge from its sibling
@ -34,7 +33,6 @@ pub trait BuildHalfEdge {
core: &mut Core, core: &mut Core,
) -> Handle<HalfEdge> { ) -> Handle<HalfEdge> {
let half_edge = HalfEdge::new( let half_edge = HalfEdge::new(
core.layers.geometry.of_half_edge(sibling).path,
sibling.boundary().reverse(), sibling.boundary().reverse(),
sibling.curve().clone(), sibling.curve().clone(),
start_vertex, start_vertex,
@ -74,7 +72,7 @@ pub trait BuildHalfEdge {
let boundary = let boundary =
[arc.start_angle, arc.end_angle].map(|coord| Point::from([coord])); [arc.start_angle, arc.end_angle].map(|coord| Point::from([coord]));
let half_edge = HalfEdge::unjoined(path, boundary, core).insert(core); let half_edge = HalfEdge::unjoined(boundary, core).insert(core);
core.layers core.layers
.geometry .geometry
.define_half_edge(half_edge.clone(), HalfEdgeGeometry { path }); .define_half_edge(half_edge.clone(), HalfEdgeGeometry { path });
@ -92,7 +90,7 @@ pub trait BuildHalfEdge {
let boundary = let boundary =
[Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord]));
let half_edge = HalfEdge::unjoined(path, boundary, core).insert(core); let half_edge = HalfEdge::unjoined(boundary, core).insert(core);
core.layers core.layers
.geometry .geometry
.define_half_edge(half_edge.clone(), HalfEdgeGeometry { path }); .define_half_edge(half_edge.clone(), HalfEdgeGeometry { path });
@ -112,7 +110,7 @@ pub trait BuildHalfEdge {
boundary.zip_ext(points_surface), boundary.zip_ext(points_surface),
); );
HalfEdge::unjoined(path, boundary, core) HalfEdge::unjoined(boundary, core)
.insert(core) .insert(core)
.set_path(path, &mut core.layers.geometry) .set_path(path, &mut core.layers.geometry)
} }

View File

@ -90,7 +90,7 @@ impl JoinCycle for Cycle {
.into_iter() .into_iter()
.circular_tuple_windows() .circular_tuple_windows()
.map(|((prev_half_edge, _, _), (half_edge, path, boundary))| { .map(|((prev_half_edge, _, _), (half_edge, path, boundary))| {
HalfEdge::unjoined(path, boundary, core) HalfEdge::unjoined(boundary, core)
.update_curve(|_, _| half_edge.curve().clone(), core) .update_curve(|_, _| half_edge.curve().clone(), core)
.update_start_vertex( .update_start_vertex(
|_, _| prev_half_edge.start_vertex().clone(), |_, _| prev_half_edge.start_vertex().clone(),

View File

@ -17,7 +17,6 @@ impl Reverse for Cycle {
let path = core.layers.geometry.of_half_edge(current).path; let path = core.layers.geometry.of_half_edge(current).path;
HalfEdge::new( HalfEdge::new(
path,
current.boundary().reverse(), current.boundary().reverse(),
current.curve().clone(), current.curve().clone(),
next.start_vertex().clone(), next.start_vertex().clone(),

View File

@ -14,7 +14,6 @@ impl ReverseCurveCoordinateSystems for Handle<HalfEdge> {
let boundary = self.boundary().reverse(); let boundary = self.boundary().reverse();
let half_edge = HalfEdge::new( let half_edge = HalfEdge::new(
path,
boundary, boundary,
self.curve().clone(), self.curve().clone(),
self.start_vertex().clone(), self.start_vertex().clone(),

View File

@ -44,14 +44,12 @@ impl SplitHalfEdge for Handle<HalfEdge> {
let [start, end] = self.boundary().inner; let [start, end] = self.boundary().inner;
let a = HalfEdge::new( let a = HalfEdge::new(
core.layers.geometry.of_half_edge(self).path,
[start, point], [start, point],
self.curve().clone(), self.curve().clone(),
self.start_vertex().clone(), self.start_vertex().clone(),
) )
.insert(core); .insert(core);
let b = HalfEdge::new( let b = HalfEdge::new(
core.layers.geometry.of_half_edge(self).path,
[point, end], [point, end],
self.curve().clone(), self.curve().clone(),
Vertex::new().insert(core), Vertex::new().insert(core),

View File

@ -28,7 +28,7 @@ impl TransformObject for Handle<HalfEdge> {
.transform_with_cache(transform, core, cache); .transform_with_cache(transform, core, cache);
let half_edge = let half_edge =
HalfEdge::new(path, boundary, curve, start_vertex).insert(core); HalfEdge::new(boundary, curve, start_vertex).insert(core);
core.layers core.layers
.geometry .geometry

View File

@ -38,7 +38,6 @@ impl UpdateHalfEdge for HalfEdge {
T: Insert<Inserted = Handle<Curve>>, T: Insert<Inserted = Handle<Curve>>,
{ {
HalfEdge::new( HalfEdge::new(
self.path(),
self.boundary(), self.boundary(),
update(self.curve(), core) update(self.curve(), core)
.insert(core) .insert(core)
@ -56,7 +55,6 @@ impl UpdateHalfEdge for HalfEdge {
T: Insert<Inserted = Handle<Vertex>>, T: Insert<Inserted = Handle<Vertex>>,
{ {
HalfEdge::new( HalfEdge::new(
self.path(),
self.boundary(), self.boundary(),
self.curve().clone(), self.curve().clone(),
update(self.start_vertex(), core) update(self.start_vertex(), core)

View File

@ -446,7 +446,6 @@ mod tests {
cycle.half_edges().nth_circular(0), cycle.half_edges().nth_circular(0),
|half_edge, core| { |half_edge, core| {
[HalfEdge::new( [HalfEdge::new(
half_edge.path().reverse(),
half_edge.boundary().reverse(), half_edge.boundary().reverse(),
half_edge.curve().clone(), half_edge.curve().clone(),
half_edge.start_vertex().clone(), half_edge.start_vertex().clone(),