Skip to content

Commit

Permalink
Merge pull request #1913 from hannobraun/operations
Browse files Browse the repository at this point in the history
Expand and update operations API
  • Loading branch information
hannobraun authored Jul 3, 2023
2 parents f8b0087 + 2927aa1 commit 5fc2086
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
5 changes: 5 additions & 0 deletions crates/fj-core/src/operations/build/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ use crate::{

/// Build a [`Shell`]
pub trait BuildShell {
/// Build an empty shell
fn empty() -> Shell {
Shell::new([])
}

/// Build a tetrahedron from the provided points
///
/// Accepts 4 points, naturally. For the purposes of the following
Expand Down
12 changes: 6 additions & 6 deletions crates/fj-core/src/operations/update/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub trait UpdateCycle {
fn add_half_edges(
&self,
half_edges: impl IntoIterator<Item = Handle<HalfEdge>>,
) -> Cycle;
) -> Self;

/// Replace the provided half-edge
///
Expand All @@ -20,7 +20,7 @@ pub trait UpdateCycle {
&self,
original: &Handle<HalfEdge>,
replacement: Handle<HalfEdge>,
) -> Cycle;
) -> Self;

/// Update the half-edge at the given index
///
Expand All @@ -31,14 +31,14 @@ pub trait UpdateCycle {
&self,
index: usize,
f: impl FnMut(&Handle<HalfEdge>) -> Handle<HalfEdge>,
) -> Cycle;
) -> Self;
}

impl UpdateCycle for Cycle {
fn add_half_edges(
&self,
half_edges: impl IntoIterator<Item = Handle<HalfEdge>>,
) -> Cycle {
) -> Self {
let half_edges = self.half_edges().cloned().chain(half_edges);
Cycle::new(half_edges)
}
Expand All @@ -47,7 +47,7 @@ impl UpdateCycle for Cycle {
&self,
original: &Handle<HalfEdge>,
replacement: Handle<HalfEdge>,
) -> Cycle {
) -> Self {
let mut num_replacements = 0;

let half_edges = self.half_edges().map(|half_edge| {
Expand All @@ -73,7 +73,7 @@ impl UpdateCycle for Cycle {
&self,
index: usize,
mut f: impl FnMut(&Handle<HalfEdge>) -> Handle<HalfEdge>,
) -> Cycle {
) -> Self {
let mut num_replacements = 0;

let half_edges = self.half_edges().enumerate().map(|(i, half_edge)| {
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-core/src/operations/update/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use crate::{
/// Update a [`HalfEdge`]
pub trait UpdateHalfEdge {
/// Update the start vertex of the half-edge
fn replace_start_vertex(&self, start_vertex: Handle<Vertex>) -> HalfEdge;
fn replace_start_vertex(&self, start_vertex: Handle<Vertex>) -> Self;

/// Update the global form of the half-edge
fn replace_global_form(&self, global_form: Handle<GlobalEdge>) -> HalfEdge;
fn replace_global_form(&self, global_form: Handle<GlobalEdge>) -> Self;
}

impl UpdateHalfEdge for HalfEdge {
fn replace_start_vertex(&self, start_vertex: Handle<Vertex>) -> HalfEdge {
fn replace_start_vertex(&self, start_vertex: Handle<Vertex>) -> Self {
HalfEdge::new(
self.curve(),
self.boundary(),
Expand All @@ -22,7 +22,7 @@ impl UpdateHalfEdge for HalfEdge {
)
}

fn replace_global_form(&self, global_form: Handle<GlobalEdge>) -> HalfEdge {
fn replace_global_form(&self, global_form: Handle<GlobalEdge>) -> Self {
HalfEdge::new(
self.curve(),
self.boundary(),
Expand Down
16 changes: 12 additions & 4 deletions crates/fj-core/src/operations/update/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,31 @@ use crate::{

/// Update a [`Shell`]
pub trait UpdateShell {
/// Add faces to the shell
fn add_faces(&self, faces: impl IntoIterator<Item = Handle<Face>>) -> Self;

/// Update a face of the shell
fn replace_face(
&self,
original: &Handle<Face>,
replacement: Handle<Face>,
) -> Shell;
) -> Self;

/// Remove a face from the shell
fn remove_face(&self, handle: &Handle<Face>) -> Shell;
fn remove_face(&self, handle: &Handle<Face>) -> Self;
}

impl UpdateShell for Shell {
fn add_faces(&self, faces: impl IntoIterator<Item = Handle<Face>>) -> Self {
let faces = self.faces().into_iter().cloned().chain(faces);
Shell::new(faces)
}

fn replace_face(
&self,
original: &Handle<Face>,
replacement: Handle<Face>,
) -> Shell {
) -> Self {
let faces = self.faces().into_iter().map(|face| {
if face.id() == original.id() {
replacement.clone()
Expand All @@ -33,7 +41,7 @@ impl UpdateShell for Shell {
Shell::new(faces)
}

fn remove_face(&self, handle: &Handle<Face>) -> Shell {
fn remove_face(&self, handle: &Handle<Face>) -> Self {
let faces = self
.faces()
.into_iter()
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/operations/update/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ pub trait UpdateSolid {
fn add_shells(
&self,
shells: impl IntoIterator<Item = Handle<Shell>>,
) -> Solid;
) -> Self;
}

impl UpdateSolid for Solid {
fn add_shells(
&self,
shells: impl IntoIterator<Item = Handle<Shell>>,
) -> Solid {
) -> Self {
let shells = self.shells().cloned().chain(shells);
Solid::new(shells)
}
Expand Down

0 comments on commit 5fc2086

Please sign in to comment.