-
-
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 #1718 from hannobraun/build
Extract build operations from builder API
- Loading branch information
Showing
9 changed files
with
135 additions
and
98 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 was deleted.
Oops, something went wrong.
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,66 @@ | ||
use fj_interop::ext::ArrayExt; | ||
use fj_math::Point; | ||
|
||
use crate::{ | ||
builder::HalfEdgeBuilder, | ||
objects::{Cycle, Face, GlobalEdge, Objects, Surface}, | ||
operations::Insert, | ||
services::Service, | ||
storage::Handle, | ||
}; | ||
|
||
use super::BuildSurface; | ||
|
||
/// Build a [`Face`] | ||
pub trait BuildFace { | ||
/// Build a triangle | ||
fn triangle( | ||
points: [impl Into<Point<3>>; 3], | ||
edges: [Option<Handle<GlobalEdge>>; 3], | ||
objects: &mut Service<Objects>, | ||
) -> Triangle { | ||
let [a, b, c] = points.map(Into::into); | ||
|
||
let surface = Surface::plane_from_points([a, b, c]).insert(objects); | ||
let (exterior, edges) = { | ||
let half_edges = [[a, b], [b, c], [c, a]].zip_ext(edges).map( | ||
|(points, global_form)| { | ||
let mut builder = | ||
HalfEdgeBuilder::line_segment_from_global_points( | ||
points, &surface, None, | ||
); | ||
|
||
if let Some(global_form) = global_form { | ||
builder = builder.with_global_form(global_form); | ||
} | ||
|
||
builder.build(objects).insert(objects) | ||
}, | ||
); | ||
|
||
let cycle = Cycle::new(half_edges.clone()).insert(objects); | ||
|
||
let global_edges = | ||
half_edges.map(|half_edge| half_edge.global_form().clone()); | ||
|
||
(cycle, global_edges) | ||
}; | ||
|
||
let face = Face::new(surface, exterior, [], None); | ||
|
||
Triangle { face, edges } | ||
} | ||
} | ||
|
||
impl BuildFace for Face {} | ||
|
||
/// A triangle | ||
/// | ||
/// Returned by [`BuildFace::triangle`]. | ||
pub struct Triangle { | ||
/// The face that forms the triangle | ||
pub face: Face, | ||
|
||
/// The edges of the triangle | ||
pub edges: [Handle<GlobalEdge>; 3], | ||
} |
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 face; | ||
mod shell; | ||
mod surface; | ||
|
||
pub use self::{ | ||
face::{BuildFace, Triangle}, | ||
shell::BuildShell, | ||
surface::BuildSurface, | ||
}; |
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,41 @@ | ||
use fj_math::Point; | ||
|
||
use crate::{ | ||
objects::{Face, Objects, Shell}, | ||
operations::Insert, | ||
services::Service, | ||
}; | ||
|
||
use super::{BuildFace, Triangle}; | ||
|
||
/// Build a [`Shell`] | ||
pub trait BuildShell { | ||
/// Build a tetrahedron from the provided points | ||
fn tetrahedron( | ||
points: [impl Into<Point<3>>; 4], | ||
objects: &mut Service<Objects>, | ||
) -> Shell { | ||
let [a, b, c, d] = points.map(Into::into); | ||
|
||
let Triangle { | ||
face: base, | ||
edges: [ab, bc, ca], | ||
} = Face::triangle([a, b, c], [None, None, None], objects); | ||
let Triangle { | ||
face: side_a, | ||
edges: [_, bd, da], | ||
} = Face::triangle([a, b, d], [Some(ab), None, None], objects); | ||
let Triangle { | ||
face: side_b, | ||
edges: [_, _, dc], | ||
} = Face::triangle([c, a, d], [Some(ca), Some(da), None], objects); | ||
let Triangle { face: side_c, .. } = | ||
Face::triangle([b, c, d], [Some(bc), Some(dc), Some(bd)], objects); | ||
|
||
let faces = | ||
[base, side_a, side_b, side_c].map(|face| face.insert(objects)); | ||
Shell::new(faces) | ||
} | ||
} | ||
|
||
impl BuildShell for Shell {} |
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
//! Operations to update shapes | ||
mod build; | ||
mod insert; | ||
|
||
pub use self::insert::Insert; | ||
pub use self::{ | ||
build::{BuildFace, BuildShell, BuildSurface, Triangle}, | ||
insert::Insert, | ||
}; |
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