Merge pull request #2270 from hannobraun/geometry

Add operation for updating half-edge geometry
This commit is contained in:
Hanno Braun 2024-03-18 13:43:10 +01:00 committed by GitHub
commit 795fe382a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 72 additions and 50 deletions

View File

@ -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)
}
}

View File

@ -0,0 +1,5 @@
//! Operations to update the geometry of objects
mod half_edge;
pub use self::half_edge::UpdateHalfEdgeGeometry;

View File

@ -40,6 +40,7 @@
pub mod build; pub mod build;
pub mod derive; pub mod derive;
pub mod geometry;
pub mod holes; pub mod holes;
pub mod insert; pub mod insert;
pub mod join; pub mod join;

View File

@ -1,7 +1,4 @@
use fj_math::Point;
use crate::{ use crate::{
geometry::{CurveBoundary, SurfacePath},
objects::{Curve, HalfEdge, Vertex}, objects::{Curve, HalfEdge, Vertex},
operations::{derive::DeriveFrom, insert::Insert}, operations::{derive::DeriveFrom, insert::Insert},
storage::Handle, storage::Handle,
@ -9,22 +6,7 @@ use crate::{
}; };
/// Update a [`HalfEdge`] /// Update a [`HalfEdge`]
pub trait UpdateHalfEdge: Sized { pub trait UpdateHalfEdge {
/// 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;
/// Update the curve of the edge /// Update the curve of the edge
#[must_use] #[must_use]
fn update_curve<T>( fn update_curve<T>(
@ -47,34 +29,6 @@ pub trait UpdateHalfEdge: Sized {
} }
impl UpdateHalfEdge for HalfEdge { 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>( fn update_curve<T>(
&self, &self,
update: impl FnOnce(&Handle<Curve>, &mut Core) -> T, update: impl FnOnce(&Handle<Curve>, &mut Core) -> T,

View File

@ -403,6 +403,7 @@ mod tests {
objects::{Curve, Shell}, objects::{Curve, Shell},
operations::{ operations::{
build::BuildShell, build::BuildShell,
geometry::UpdateHalfEdgeGeometry,
update::{ update::{
UpdateCycle, UpdateFace, UpdateHalfEdge, UpdateRegion, UpdateCycle, UpdateFace, UpdateHalfEdge, UpdateRegion,
UpdateShell, UpdateShell,
@ -435,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,
) )