Skip to content

Commit

Permalink
Migrate update_boundary to new trait
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Mar 18, 2024
1 parent 671def7 commit e51cd31
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
31 changes: 29 additions & 2 deletions crates/fj-core/src/operations/geometry/half_edge.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use fj_math::Point;

use crate::{
geometry::SurfacePath, objects::HalfEdge, operations::insert::Insert,
storage::Handle, Core,
geometry::{CurveBoundary, SurfacePath},
objects::HalfEdge,
operations::insert::Insert,
storage::Handle,
Core,
};

/// Update the geometry of a [`HalfEdge`]
Expand All @@ -12,6 +17,14 @@ pub trait UpdateHalfEdgeGeometry {
update: impl FnOnce(SurfacePath) -> SurfacePath,
core: &mut Core,
) -> 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> {
Expand All @@ -30,4 +43,18 @@ impl UpdateHalfEdgeGeometry for Handle<HalfEdge> {
)
.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)
}
}
22 changes: 0 additions & 22 deletions crates/fj-core/src/operations/update/half_edge.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use fj_math::Point;

use crate::{
geometry::CurveBoundary,
objects::{Curve, HalfEdge, Vertex},
operations::{derive::DeriveFrom, insert::Insert},
storage::Handle,
Expand All @@ -10,13 +7,6 @@ use crate::{

/// Update a [`HalfEdge`]
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
#[must_use]
fn update_curve<T>(
Expand All @@ -39,18 +29,6 @@ pub trait UpdateHalfEdge {
}

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>(
&self,
update: impl FnOnce(&Handle<Curve>, &mut Core) -> T,
Expand Down
7 changes: 4 additions & 3 deletions crates/fj-core/src/validate/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,10 @@ mod tests {
|path| path.reverse(),
core,
)
.update_boundary(|boundary| {
boundary.reverse()
})]
.update_boundary(
|boundary| boundary.reverse(),
core,
)]
},
core,
)
Expand Down

0 comments on commit e51cd31

Please sign in to comment.