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

Clean up operations API #1816

Merged
merged 7 commits into from
May 4, 2023
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
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