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

Make some cleanups in operations API #1794

Merged
merged 7 commits into from
Apr 26, 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
41 changes: 20 additions & 21 deletions crates/fj-kernel/src/operations/build/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,47 +35,46 @@ pub trait BuildShell {
) -> Tetrahedron {
let [a, b, c, d] = points.map(Into::into);

let face_abc = Face::triangle([a, b, c], objects).face;
let face_bad =
let abc = Face::triangle([a, b, c], objects).face;
let bad =
Face::triangle([b, a, d], objects)
.face
.update_exterior(|cycle| {
cycle
.join_to(face_abc.exterior(), 0..=0, 0..=0, objects)
.join_to(abc.exterior(), 0..=0, 0..=0, objects)
.insert(objects)
});
let face_dac =
let dac =
Face::triangle([d, a, c], objects)
.face
.update_exterior(|cycle| {
cycle
.join_to(face_abc.exterior(), 1..=1, 2..=2, objects)
.join_to(face_bad.exterior(), 0..=0, 1..=1, objects)
.join_to(abc.exterior(), 1..=1, 2..=2, objects)
.join_to(bad.exterior(), 0..=0, 1..=1, objects)
.insert(objects)
});
let face_cbd =
let cbd =
Face::triangle([c, b, d], objects)
.face
.update_exterior(|cycle| {
cycle
.join_to(face_abc.exterior(), 0..=0, 1..=1, objects)
.join_to(face_bad.exterior(), 1..=1, 2..=2, objects)
.join_to(face_dac.exterior(), 2..=2, 2..=2, objects)
.join_to(abc.exterior(), 0..=0, 1..=1, objects)
.join_to(bad.exterior(), 1..=1, 2..=2, objects)
.join_to(dac.exterior(), 2..=2, 2..=2, objects)
.insert(objects)
});

let faces = [face_abc, face_bad, face_dac, face_cbd]
.map(|face| face.insert(objects));
let faces = [abc, bad, dac, cbd].map(|face| face.insert(objects));
let shell = Shell::new(faces.clone());

let [face_abc, face_bad, face_dac, face_cbd] = faces;
let [abc, bad, dac, cbd] = faces;

Tetrahedron {
shell,
face_abc,
face_bad,
face_dac,
face_cbd,
abc,
bad,
dac,
cbd,
}
}
}
Expand All @@ -94,14 +93,14 @@ pub struct Tetrahedron {
pub shell: Shell,

/// The face formed by the points `a`, `b`, and `c`.
pub face_abc: Handle<Face>,
pub abc: Handle<Face>,

/// The face formed by the points `b`, `a`, and `d`.
pub face_bad: Handle<Face>,
pub bad: Handle<Face>,

/// The face formed by the points `d`, `a`, and `c`.
pub face_dac: Handle<Face>,
pub dac: Handle<Face>,

/// The face formed by the points `c`, `b`, and `d`.
pub face_cbd: Handle<Face>,
pub cbd: Handle<Face>,
}
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/operations/update/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ pub trait UpdateCycle {
replacement: Handle<HalfEdge>,
) -> Cycle;

/// Replace the half-edge at the given index
/// Update the half-edge at the given index
///
/// # Panics
///
/// Panics, unless this operation replaces exactly one half-edge.
/// Panics, unless this operation updates exactly one half-edge.
fn update_nth_half_edge(
&self,
index: usize,
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/operations/update/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ pub trait UpdateFace {
fn update_exterior(
&self,
f: impl FnOnce(&Handle<Cycle>) -> Handle<Cycle>,
) -> Face;
) -> Self;
}

impl UpdateFace for Face {
fn update_exterior(
&self,
f: impl FnOnce(&Handle<Cycle>) -> Handle<Cycle>,
) -> Face {
) -> Self {
let exterior = f(self.exterior());

Face::new(
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/validate/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ mod tests {
[[0., 0., 0.], [0., 1., 0.], [1., 0., 0.], [0., 0., 1.]],
&mut services.objects,
);
let invalid = valid.shell.update_face(&valid.face_abc, |face| {
let invalid = valid.shell.update_face(&valid.abc, |face| {
face.update_exterior(|cycle| {
cycle
.update_nth_half_edge(0, |half_edge| {
Expand Down Expand Up @@ -243,7 +243,7 @@ mod tests {
[[0., 0., 0.], [0., 1., 0.], [1., 0., 0.], [0., 0., 1.]],
&mut services.objects,
);
let invalid = valid.shell.remove_face(&valid.face_abc);
let invalid = valid.shell.remove_face(&valid.abc);

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