Skip to content

Commit

Permalink
Merge pull request #2270 from hannobraun/geometry
Browse files Browse the repository at this point in the history
Add operation for updating half-edge geometry
  • Loading branch information
hannobraun authored Mar 18, 2024
2 parents 811a24b + e51cd31 commit 795fe38
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 50 deletions.
60 changes: 60 additions & 0 deletions crates/fj-core/src/operations/geometry/half_edge.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use fj_math::Point;

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

/// Update the geometry of a [`HalfEdge`]
pub trait UpdateHalfEdgeGeometry {
/// Update the path of the edge
#[must_use]
fn update_path(
&self,
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> {
fn update_path(
&self,
update: impl FnOnce(SurfacePath) -> SurfacePath,
core: &mut Core,
) -> Self {
let path = update(self.path());

HalfEdge::new(
path,
self.boundary(),
self.curve().clone(),
self.start_vertex().clone(),
)
.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)
}
}
5 changes: 5 additions & 0 deletions crates/fj-core/src/operations/geometry/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! Operations to update the geometry of objects
mod half_edge;

pub use self::half_edge::UpdateHalfEdgeGeometry;
1 change: 1 addition & 0 deletions crates/fj-core/src/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
pub mod build;
pub mod derive;
pub mod geometry;
pub mod holes;
pub mod insert;
pub mod join;
Expand Down
48 changes: 1 addition & 47 deletions crates/fj-core/src/operations/update/half_edge.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
use fj_math::Point;

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

/// Update a [`HalfEdge`]
pub trait UpdateHalfEdge: Sized {
/// Update the path of the edge
#[must_use]
fn update_path(
&self,
update: impl FnOnce(SurfacePath) -> SurfacePath,
core: &mut Core,
) -> Handle<Self>;

/// Update the boundary of the edge
#[must_use]
fn update_boundary(
&self,
update: impl FnOnce(CurveBoundary<Point<1>>) -> CurveBoundary<Point<1>>,
) -> Self;

pub trait UpdateHalfEdge {
/// Update the curve of the edge
#[must_use]
fn update_curve<T>(
Expand All @@ -47,34 +29,6 @@ pub trait UpdateHalfEdge: Sized {
}

impl UpdateHalfEdge for HalfEdge {
fn update_path(
&self,
update: impl FnOnce(SurfacePath) -> SurfacePath,
core: &mut Core,
) -> Handle<Self> {
let path = update(self.path());

HalfEdge::new(
path,
self.boundary(),
self.curve().clone(),
self.start_vertex().clone(),
)
.insert(core)
}

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
8 changes: 5 additions & 3 deletions crates/fj-core/src/validate/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ mod tests {
objects::{Curve, Shell},
operations::{
build::BuildShell,
geometry::UpdateHalfEdgeGeometry,
update::{
UpdateCycle, UpdateFace, UpdateHalfEdge, UpdateRegion,
UpdateShell,
Expand Down Expand Up @@ -435,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 795fe38

Please sign in to comment.