Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add operation for updating half-edge geometry #2270

Merged
merged 4 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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