mirror of https://github.com/hannobraun/Fornjot
Merge pull request #1816 from hannobraun/operations
Clean up operations API
This commit is contained in:
commit
3bf425c91a
|
@ -3,12 +3,10 @@ use itertools::Itertools;
|
|||
|
||||
use crate::{
|
||||
objects::{Cycle, HalfEdge},
|
||||
operations::Insert,
|
||||
operations::{BuildHalfEdge, Insert},
|
||||
services::Services,
|
||||
};
|
||||
|
||||
use super::BuildHalfEdge;
|
||||
|
||||
/// Build a [`Cycle`]
|
||||
pub trait BuildCycle {
|
||||
/// Build an empty cycle
|
||||
|
|
|
@ -3,13 +3,14 @@ use fj_math::Point;
|
|||
|
||||
use crate::{
|
||||
objects::{Cycle, Face, HalfEdge, Surface, Vertex},
|
||||
operations::{Insert, IsInserted, IsInsertedNo},
|
||||
operations::{
|
||||
BuildCycle, BuildHalfEdge, BuildSurface, Insert, IsInserted,
|
||||
IsInsertedNo,
|
||||
},
|
||||
services::Services,
|
||||
storage::Handle,
|
||||
};
|
||||
|
||||
use super::{BuildCycle, BuildHalfEdge, BuildSurface};
|
||||
|
||||
/// Build a [`Face`]
|
||||
pub trait BuildFace {
|
||||
/// Build a face with an empty exterior, no interiors, and no color
|
||||
|
|
|
@ -1,15 +1,6 @@
|
|||
mod cycle;
|
||||
mod edge;
|
||||
mod face;
|
||||
mod shell;
|
||||
mod solid;
|
||||
mod surface;
|
||||
|
||||
pub use self::{
|
||||
cycle::BuildCycle,
|
||||
edge::BuildHalfEdge,
|
||||
face::{BuildFace, Polygon},
|
||||
shell::{BuildShell, TetrahedronShell},
|
||||
solid::{BuildSolid, Tetrahedron},
|
||||
surface::BuildSurface,
|
||||
};
|
||||
pub mod cycle;
|
||||
pub mod edge;
|
||||
pub mod face;
|
||||
pub mod shell;
|
||||
pub mod solid;
|
||||
pub mod surface;
|
||||
|
|
|
@ -3,13 +3,12 @@ use fj_math::Point;
|
|||
use crate::{
|
||||
objects::{Face, Shell},
|
||||
operations::{
|
||||
Insert, IsInserted, IsInsertedNo, IsInsertedYes, JoinCycle, UpdateFace,
|
||||
BuildFace, Insert, IsInserted, IsInsertedNo, IsInsertedYes, JoinCycle,
|
||||
Polygon, UpdateFace,
|
||||
},
|
||||
services::Services,
|
||||
};
|
||||
|
||||
use super::{BuildFace, Polygon};
|
||||
|
||||
/// Build a [`Shell`]
|
||||
pub trait BuildShell {
|
||||
/// Build a tetrahedron from the provided points
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
mod cycle;
|
||||
|
||||
pub use self::cycle::JoinCycle;
|
||||
pub mod cycle;
|
||||
|
|
|
@ -7,12 +7,17 @@ mod update;
|
|||
|
||||
pub use self::{
|
||||
build::{
|
||||
BuildCycle, BuildFace, BuildHalfEdge, BuildShell, BuildSolid,
|
||||
BuildSurface, Polygon, Tetrahedron, TetrahedronShell,
|
||||
cycle::BuildCycle,
|
||||
edge::BuildHalfEdge,
|
||||
face::{BuildFace, Polygon},
|
||||
shell::{BuildShell, TetrahedronShell},
|
||||
solid::{BuildSolid, Tetrahedron},
|
||||
surface::BuildSurface,
|
||||
},
|
||||
insert::{Insert, IsInserted, IsInsertedNo, IsInsertedYes},
|
||||
join::JoinCycle,
|
||||
join::cycle::JoinCycle,
|
||||
update::{
|
||||
UpdateCycle, UpdateFace, UpdateHalfEdge, UpdateShell, UpdateSolid,
|
||||
cycle::UpdateCycle, edge::UpdateHalfEdge, face::UpdateFace,
|
||||
shell::UpdateShell, solid::UpdateSolid,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
mod cycle;
|
||||
mod edge;
|
||||
mod face;
|
||||
mod shell;
|
||||
mod solid;
|
||||
|
||||
pub use self::{
|
||||
cycle::UpdateCycle, edge::UpdateHalfEdge, face::UpdateFace,
|
||||
shell::UpdateShell, solid::UpdateSolid,
|
||||
};
|
||||
pub mod cycle;
|
||||
pub mod edge;
|
||||
pub mod face;
|
||||
pub mod shell;
|
||||
pub mod solid;
|
||||
|
|
|
@ -6,10 +6,10 @@ use crate::{
|
|||
/// Update a [`Shell`]
|
||||
pub trait UpdateShell {
|
||||
/// Update a face of the shell
|
||||
fn update_face(
|
||||
fn replace_face(
|
||||
&self,
|
||||
handle: &Handle<Face>,
|
||||
f: impl FnMut(&Handle<Face>) -> Handle<Face>,
|
||||
original: &Handle<Face>,
|
||||
replacement: Handle<Face>,
|
||||
) -> Shell;
|
||||
|
||||
/// Remove a face from the shell
|
||||
|
@ -17,14 +17,14 @@ pub trait UpdateShell {
|
|||
}
|
||||
|
||||
impl UpdateShell for Shell {
|
||||
fn update_face(
|
||||
fn replace_face(
|
||||
&self,
|
||||
handle: &Handle<Face>,
|
||||
mut f: impl FnMut(&Handle<Face>) -> Handle<Face>,
|
||||
original: &Handle<Face>,
|
||||
replacement: Handle<Face>,
|
||||
) -> Shell {
|
||||
let faces = self.faces().into_iter().map(|face| {
|
||||
if face.id() == handle.id() {
|
||||
f(face)
|
||||
if face.id() == original.id() {
|
||||
replacement.clone()
|
||||
} else {
|
||||
face.clone()
|
||||
}
|
||||
|
|
|
@ -210,8 +210,12 @@ mod tests {
|
|||
[[0., 0., 0.], [0., 1., 0.], [1., 0., 0.], [0., 0., 1.]],
|
||||
&mut services,
|
||||
);
|
||||
let invalid = valid.shell.update_face(&valid.abc.face, |face| {
|
||||
face.update_exterior(|cycle| {
|
||||
let invalid = valid.shell.replace_face(
|
||||
&valid.abc.face,
|
||||
valid
|
||||
.abc
|
||||
.face
|
||||
.update_exterior(|cycle| {
|
||||
cycle
|
||||
.update_nth_half_edge(0, |half_edge| {
|
||||
let global_form =
|
||||
|
@ -222,8 +226,8 @@ mod tests {
|
|||
})
|
||||
.insert(&mut services)
|
||||
})
|
||||
.insert(&mut services)
|
||||
});
|
||||
.insert(&mut services),
|
||||
);
|
||||
|
||||
valid.shell.validate_and_return_first_error()?;
|
||||
assert_contains_err!(
|
||||
|
|
Loading…
Reference in New Issue