Migrate update_boundary to new trait

This commit is contained in:
Hanno Braun 2024-03-18 13:22:15 +01:00
parent 671def72bd
commit e51cd314fd
3 changed files with 33 additions and 27 deletions

View File

@ -1,6 +1,11 @@
use fj_math::Point;
use crate::{ use crate::{
geometry::SurfacePath, objects::HalfEdge, operations::insert::Insert, geometry::{CurveBoundary, SurfacePath},
storage::Handle, Core, objects::HalfEdge,
operations::insert::Insert,
storage::Handle,
Core,
}; };
/// Update the geometry of a [`HalfEdge`] /// Update the geometry of a [`HalfEdge`]
@ -12,6 +17,14 @@ pub trait UpdateHalfEdgeGeometry {
update: impl FnOnce(SurfacePath) -> SurfacePath, update: impl FnOnce(SurfacePath) -> SurfacePath,
core: &mut Core, core: &mut Core,
) -> Self; ) -> Self;
/// Update the boundary of the edge
#[must_use]
fn update_boundary(
&self,
update: impl FnOnce(CurveBoundary<Point<1>>) -> CurveBoundary<Point<1>>,
core: &mut Core,
) -> Self;
} }
impl UpdateHalfEdgeGeometry for Handle<HalfEdge> { impl UpdateHalfEdgeGeometry for Handle<HalfEdge> {
@ -30,4 +43,18 @@ impl UpdateHalfEdgeGeometry for Handle<HalfEdge> {
) )
.insert(core) .insert(core)
} }
fn update_boundary(
&self,
update: impl FnOnce(CurveBoundary<Point<1>>) -> CurveBoundary<Point<1>>,
core: &mut Core,
) -> Self {
HalfEdge::new(
self.path(),
update(self.boundary()),
self.curve().clone(),
self.start_vertex().clone(),
)
.insert(core)
}
} }

View File

@ -1,7 +1,4 @@
use fj_math::Point;
use crate::{ use crate::{
geometry::CurveBoundary,
objects::{Curve, HalfEdge, Vertex}, objects::{Curve, HalfEdge, Vertex},
operations::{derive::DeriveFrom, insert::Insert}, operations::{derive::DeriveFrom, insert::Insert},
storage::Handle, storage::Handle,
@ -10,13 +7,6 @@ use crate::{
/// Update a [`HalfEdge`] /// Update a [`HalfEdge`]
pub trait UpdateHalfEdge { pub trait UpdateHalfEdge {
/// Update the boundary of the edge
#[must_use]
fn update_boundary(
&self,
update: impl FnOnce(CurveBoundary<Point<1>>) -> CurveBoundary<Point<1>>,
) -> Self;
/// Update the curve of the edge /// Update the curve of the edge
#[must_use] #[must_use]
fn update_curve<T>( fn update_curve<T>(
@ -39,18 +29,6 @@ pub trait UpdateHalfEdge {
} }
impl UpdateHalfEdge for HalfEdge { impl UpdateHalfEdge for HalfEdge {
fn update_boundary(
&self,
update: impl FnOnce(CurveBoundary<Point<1>>) -> CurveBoundary<Point<1>>,
) -> Self {
HalfEdge::new(
self.path(),
update(self.boundary()),
self.curve().clone(),
self.start_vertex().clone(),
)
}
fn update_curve<T>( fn update_curve<T>(
&self, &self,
update: impl FnOnce(&Handle<Curve>, &mut Core) -> T, update: impl FnOnce(&Handle<Curve>, &mut Core) -> T,

View File

@ -436,9 +436,10 @@ mod tests {
|path| path.reverse(), |path| path.reverse(),
core, core,
) )
.update_boundary(|boundary| { .update_boundary(
boundary.reverse() |boundary| boundary.reverse(),
})] core,
)]
}, },
core, core,
) )