Merge pull request #1816 from hannobraun/operations

Clean up operations API
This commit is contained in:
Hanno Braun 2023-05-04 13:02:35 +02:00 committed by GitHub
commit 3bf425c91a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 54 additions and 63 deletions

View File

@ -3,12 +3,10 @@ use itertools::Itertools;
use crate::{ use crate::{
objects::{Cycle, HalfEdge}, objects::{Cycle, HalfEdge},
operations::Insert, operations::{BuildHalfEdge, Insert},
services::Services, services::Services,
}; };
use super::BuildHalfEdge;
/// Build a [`Cycle`] /// Build a [`Cycle`]
pub trait BuildCycle { pub trait BuildCycle {
/// Build an empty cycle /// Build an empty cycle

View File

@ -3,13 +3,14 @@ use fj_math::Point;
use crate::{ use crate::{
objects::{Cycle, Face, HalfEdge, Surface, Vertex}, objects::{Cycle, Face, HalfEdge, Surface, Vertex},
operations::{Insert, IsInserted, IsInsertedNo}, operations::{
BuildCycle, BuildHalfEdge, BuildSurface, Insert, IsInserted,
IsInsertedNo,
},
services::Services, services::Services,
storage::Handle, storage::Handle,
}; };
use super::{BuildCycle, BuildHalfEdge, BuildSurface};
/// Build a [`Face`] /// Build a [`Face`]
pub trait BuildFace { pub trait BuildFace {
/// Build a face with an empty exterior, no interiors, and no color /// Build a face with an empty exterior, no interiors, and no color

View File

@ -1,15 +1,6 @@
mod cycle; pub mod cycle;
mod edge; pub mod edge;
mod face; pub mod face;
mod shell; pub mod shell;
mod solid; pub mod solid;
mod surface; pub mod surface;
pub use self::{
cycle::BuildCycle,
edge::BuildHalfEdge,
face::{BuildFace, Polygon},
shell::{BuildShell, TetrahedronShell},
solid::{BuildSolid, Tetrahedron},
surface::BuildSurface,
};

View File

@ -3,13 +3,12 @@ use fj_math::Point;
use crate::{ use crate::{
objects::{Face, Shell}, objects::{Face, Shell},
operations::{ operations::{
Insert, IsInserted, IsInsertedNo, IsInsertedYes, JoinCycle, UpdateFace, BuildFace, Insert, IsInserted, IsInsertedNo, IsInsertedYes, JoinCycle,
Polygon, UpdateFace,
}, },
services::Services, services::Services,
}; };
use super::{BuildFace, Polygon};
/// Build a [`Shell`] /// Build a [`Shell`]
pub trait BuildShell { pub trait BuildShell {
/// Build a tetrahedron from the provided points /// Build a tetrahedron from the provided points

View File

@ -1,3 +1 @@
mod cycle; pub mod cycle;
pub use self::cycle::JoinCycle;

View File

@ -7,12 +7,17 @@ mod update;
pub use self::{ pub use self::{
build::{ build::{
BuildCycle, BuildFace, BuildHalfEdge, BuildShell, BuildSolid, cycle::BuildCycle,
BuildSurface, Polygon, Tetrahedron, TetrahedronShell, edge::BuildHalfEdge,
face::{BuildFace, Polygon},
shell::{BuildShell, TetrahedronShell},
solid::{BuildSolid, Tetrahedron},
surface::BuildSurface,
}, },
insert::{Insert, IsInserted, IsInsertedNo, IsInsertedYes}, insert::{Insert, IsInserted, IsInsertedNo, IsInsertedYes},
join::JoinCycle, join::cycle::JoinCycle,
update::{ update::{
UpdateCycle, UpdateFace, UpdateHalfEdge, UpdateShell, UpdateSolid, cycle::UpdateCycle, edge::UpdateHalfEdge, face::UpdateFace,
shell::UpdateShell, solid::UpdateSolid,
}, },
}; };

View File

@ -1,10 +1,5 @@
mod cycle; pub mod cycle;
mod edge; pub mod edge;
mod face; pub mod face;
mod shell; pub mod shell;
mod solid; pub mod solid;
pub use self::{
cycle::UpdateCycle, edge::UpdateHalfEdge, face::UpdateFace,
shell::UpdateShell, solid::UpdateSolid,
};

View File

@ -6,10 +6,10 @@ use crate::{
/// Update a [`Shell`] /// Update a [`Shell`]
pub trait UpdateShell { pub trait UpdateShell {
/// Update a face of the shell /// Update a face of the shell
fn update_face( fn replace_face(
&self, &self,
handle: &Handle<Face>, original: &Handle<Face>,
f: impl FnMut(&Handle<Face>) -> Handle<Face>, replacement: Handle<Face>,
) -> Shell; ) -> Shell;
/// Remove a face from the shell /// Remove a face from the shell
@ -17,14 +17,14 @@ pub trait UpdateShell {
} }
impl UpdateShell for Shell { impl UpdateShell for Shell {
fn update_face( fn replace_face(
&self, &self,
handle: &Handle<Face>, original: &Handle<Face>,
mut f: impl FnMut(&Handle<Face>) -> Handle<Face>, replacement: Handle<Face>,
) -> Shell { ) -> Shell {
let faces = self.faces().into_iter().map(|face| { let faces = self.faces().into_iter().map(|face| {
if face.id() == handle.id() { if face.id() == original.id() {
f(face) replacement.clone()
} else { } else {
face.clone() face.clone()
} }

View File

@ -210,20 +210,24 @@ mod tests {
[[0., 0., 0.], [0., 1., 0.], [1., 0., 0.], [0., 0., 1.]], [[0., 0., 0.], [0., 1., 0.], [1., 0., 0.], [0., 0., 1.]],
&mut services, &mut services,
); );
let invalid = valid.shell.update_face(&valid.abc.face, |face| { let invalid = valid.shell.replace_face(
face.update_exterior(|cycle| { &valid.abc.face,
cycle valid
.update_nth_half_edge(0, |half_edge| { .abc
let global_form = .face
GlobalEdge::new().insert(&mut services); .update_exterior(|cycle| {
half_edge cycle
.replace_global_form(global_form) .update_nth_half_edge(0, |half_edge| {
.insert(&mut services) let global_form =
}) GlobalEdge::new().insert(&mut services);
.insert(&mut services) half_edge
}) .replace_global_form(global_form)
.insert(&mut services) .insert(&mut services)
}); })
.insert(&mut services)
})
.insert(&mut services),
);
valid.shell.validate_and_return_first_error()?; valid.shell.validate_and_return_first_error()?;
assert_contains_err!( assert_contains_err!(