Skip to content

Commit

Permalink
Merge pull request #1816 from hannobraun/operations
Browse files Browse the repository at this point in the history
Clean up operations API
  • Loading branch information
hannobraun authored May 4, 2023
2 parents 6fc68a9 + 2e196ad commit 3bf425c
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 63 deletions.
4 changes: 1 addition & 3 deletions crates/fj-kernel/src/operations/build/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions crates/fj-kernel/src/operations/build/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 6 additions & 15 deletions crates/fj-kernel/src/operations/build/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 2 additions & 3 deletions crates/fj-kernel/src/operations/build/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions crates/fj-kernel/src/operations/join/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
mod cycle;

pub use self::cycle::JoinCycle;
pub mod cycle;
13 changes: 9 additions & 4 deletions crates/fj-kernel/src/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
15 changes: 5 additions & 10 deletions crates/fj-kernel/src/operations/update/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
16 changes: 8 additions & 8 deletions crates/fj-kernel/src/operations/update/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ 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
fn remove_face(&self, handle: &Handle<Face>) -> Shell;
}

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()
}
Expand Down
32 changes: 18 additions & 14 deletions crates/fj-kernel/src/validate/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,24 @@ 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| {
cycle
.update_nth_half_edge(0, |half_edge| {
let global_form =
GlobalEdge::new().insert(&mut services);
half_edge
.replace_global_form(global_form)
.insert(&mut services)
})
.insert(&mut services)
})
.insert(&mut services)
});
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 =
GlobalEdge::new().insert(&mut services);
half_edge
.replace_global_form(global_form)
.insert(&mut services)
})
.insert(&mut services)
})
.insert(&mut services),
);

valid.shell.validate_and_return_first_error()?;
assert_contains_err!(
Expand Down

0 comments on commit 3bf425c

Please sign in to comment.