-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1719 from hannobraun/operations
Add "update" operations; use them to clean up `Shell` validation tests
- Loading branch information
Showing
9 changed files
with
205 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use crate::{ | ||
objects::{Cycle, HalfEdge}, | ||
storage::Handle, | ||
}; | ||
|
||
/// Update a [`Cycle`] | ||
pub trait UpdateCycle { | ||
/// Update a half-edge of the cycle | ||
fn update_half_edge( | ||
&self, | ||
index: usize, | ||
f: impl FnMut(&Handle<HalfEdge>) -> Handle<HalfEdge>, | ||
) -> Cycle; | ||
} | ||
|
||
impl UpdateCycle for Cycle { | ||
fn update_half_edge( | ||
&self, | ||
index: usize, | ||
mut f: impl FnMut(&Handle<HalfEdge>) -> Handle<HalfEdge>, | ||
) -> Cycle { | ||
let half_edges = self.half_edges().enumerate().map(|(i, cycle)| { | ||
if i == index { | ||
f(cycle) | ||
} else { | ||
cycle.clone() | ||
} | ||
}); | ||
|
||
Cycle::new(half_edges) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use crate::{ | ||
objects::{GlobalEdge, HalfEdge}, | ||
storage::Handle, | ||
}; | ||
|
||
/// Update a [`HalfEdge`] | ||
pub trait UpdateHalfEdge { | ||
/// Update the global form of the half-edge | ||
fn update_global_form(&self, global_form: Handle<GlobalEdge>) -> HalfEdge; | ||
} | ||
|
||
impl UpdateHalfEdge for HalfEdge { | ||
fn update_global_form(&self, global_form: Handle<GlobalEdge>) -> HalfEdge { | ||
HalfEdge::new( | ||
self.curve(), | ||
self.boundary(), | ||
self.start_vertex().clone(), | ||
global_form, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::{ | ||
objects::{Cycle, Face}, | ||
storage::Handle, | ||
}; | ||
|
||
/// Update a [`Face`] | ||
pub trait UpdateFace { | ||
/// Update the exterior of the face | ||
fn update_exterior( | ||
&self, | ||
f: impl FnOnce(&Handle<Cycle>) -> Handle<Cycle>, | ||
) -> Face; | ||
} | ||
|
||
impl UpdateFace for Face { | ||
fn update_exterior( | ||
&self, | ||
f: impl FnOnce(&Handle<Cycle>) -> Handle<Cycle>, | ||
) -> Face { | ||
let exterior = f(self.exterior()); | ||
|
||
Face::new( | ||
self.surface().clone(), | ||
exterior, | ||
self.interiors().cloned(), | ||
self.color(), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
mod cycle; | ||
mod edge; | ||
mod face; | ||
mod shell; | ||
|
||
pub use self::{ | ||
cycle::UpdateCycle, edge::UpdateHalfEdge, face::UpdateFace, | ||
shell::UpdateShell, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use crate::{ | ||
objects::{Face, Shell}, | ||
storage::Handle, | ||
}; | ||
|
||
/// Update a [`Shell`] | ||
pub trait UpdateShell { | ||
/// Update a face of the shell | ||
fn update_face( | ||
&self, | ||
handle: &Handle<Face>, | ||
f: impl FnMut(&Handle<Face>) -> Handle<Face>, | ||
) -> Shell; | ||
|
||
/// Remove a face from the shell | ||
fn remove_face(&self, handle: &Handle<Face>) -> Shell; | ||
} | ||
|
||
impl UpdateShell for Shell { | ||
fn update_face( | ||
&self, | ||
handle: &Handle<Face>, | ||
mut f: impl FnMut(&Handle<Face>) -> Handle<Face>, | ||
) -> Shell { | ||
let faces = self.faces().into_iter().map(|face| { | ||
if face.id() == handle.id() { | ||
f(face) | ||
} else { | ||
face.clone() | ||
} | ||
}); | ||
|
||
Shell::new(faces) | ||
} | ||
|
||
fn remove_face(&self, handle: &Handle<Face>) -> Shell { | ||
let faces = self | ||
.faces() | ||
.into_iter() | ||
.filter(|face| face.id() == handle.id()) | ||
.cloned(); | ||
|
||
Shell::new(faces) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters