-
-
Notifications
You must be signed in to change notification settings - Fork 116
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 #2093 from hannobraun/split
Add edge splitting operation
- Loading branch information
Showing
10 changed files
with
165 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,61 @@ | ||
use fj_math::Point; | ||
|
||
use crate::{ | ||
objects::{HalfEdge, Shell}, | ||
operations::{ | ||
insert::Insert, replace::ReplaceHalfEdge, split::SplitHalfEdge, | ||
update::UpdateHalfEdge, | ||
}, | ||
queries::SiblingOfHalfEdge, | ||
services::Services, | ||
storage::Handle, | ||
}; | ||
|
||
/// Split a pair of [`HalfEdge`]s into two | ||
pub trait SplitEdge { | ||
/// Split the provided [`HalfEdge`], as well as its sibling, into two | ||
/// | ||
/// # Panics | ||
/// | ||
/// Panics, if the provided half-edge is not a part of this shell. | ||
#[must_use] | ||
fn split_edge( | ||
&self, | ||
half_edge: &Handle<HalfEdge>, | ||
point: impl Into<Point<1>>, | ||
services: &mut Services, | ||
) -> Self; | ||
} | ||
|
||
impl SplitEdge for Shell { | ||
fn split_edge( | ||
&self, | ||
half_edge: &Handle<HalfEdge>, | ||
point: impl Into<Point<1>>, | ||
services: &mut Services, | ||
) -> Self { | ||
let point = point.into(); | ||
|
||
let sibling = self | ||
.get_sibling_of(half_edge) | ||
.expect("Expected half-edge and its sibling to be part of shell"); | ||
|
||
let [half_edge_a, half_edge_b] = half_edge | ||
.split_half_edge(point, services) | ||
.map(|half_edge| half_edge.insert(services)); | ||
|
||
let [sibling_a, sibling_b] = sibling.split_half_edge(point, services); | ||
let sibling_b = sibling_b | ||
.update_start_vertex(|_| half_edge_b.start_vertex().clone()); | ||
|
||
self.replace_half_edge(half_edge, [half_edge_a, half_edge_b], services) | ||
.into_inner() | ||
.replace_half_edge( | ||
&sibling, | ||
[sibling_a, sibling_b] | ||
.map(|half_edge| half_edge.insert(services)), | ||
services, | ||
) | ||
.into_inner() | ||
} | ||
} |
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,8 +1,11 @@ | ||
//! # Operations to split objects | ||
//! | ||
//! See [`SplitHalfEdge`], which is currently the only trait in this module, for | ||
//! more information. | ||
//! Splitting means removing an object, replacing it with to new ones that fill | ||
//! the same space. This often makes sense, when you want to modify only part of | ||
//! an object. In such a case, you can split off the part you want to modify, | ||
//! leaving the rest unchanged. | ||
|
||
mod edge; | ||
mod half_edge; | ||
|
||
pub use self::half_edge::SplitHalfEdge; | ||
pub use self::{edge::SplitEdge, half_edge::SplitHalfEdge}; |
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,7 @@ | ||
[package] | ||
name = "split" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies.fj] | ||
path = "../../crates/fj" |
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,58 @@ | ||
use fj::{ | ||
core::{ | ||
algorithms::sweep::Sweep, | ||
objects::{Region, Sketch, Solid}, | ||
operations::{ | ||
build::{BuildRegion, BuildSketch}, | ||
insert::Insert, | ||
split::SplitEdge, | ||
update::{UpdateSketch, UpdateSolid}, | ||
}, | ||
services::Services, | ||
storage::Handle, | ||
}, | ||
math::Vector, | ||
}; | ||
|
||
pub fn model( | ||
size: f64, | ||
split_pos: f64, | ||
services: &mut Services, | ||
) -> Handle<Solid> { | ||
let sketch = Sketch::empty() | ||
.add_region( | ||
Region::polygon( | ||
[ | ||
[-size / 2., -size / 2.], | ||
[size / 2., -size / 2.], | ||
[size / 2., size / 2.], | ||
[-size / 2., size / 2.], | ||
], | ||
services, | ||
) | ||
.insert(services), | ||
) | ||
.insert(services); | ||
|
||
let surface = services.objects.surfaces.xy_plane(); | ||
let path = Vector::from([0., 0., size]); | ||
let solid = (sketch, surface).sweep(path, services); | ||
|
||
solid | ||
.update_shell(solid.shells().only(), |shell| { | ||
shell | ||
.split_edge( | ||
shell | ||
.faces() | ||
.first() | ||
.region() | ||
.exterior() | ||
.half_edges() | ||
.first(), | ||
[split_pos], | ||
services, | ||
) | ||
.insert(services) | ||
}) | ||
.insert(services) | ||
} |
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,8 @@ | ||
use fj::{core::services::Services, handle_model}; | ||
|
||
fn main() -> fj::Result { | ||
let mut services = Services::new(); | ||
let model = split::model(1.0, 0.5, &mut services); | ||
handle_model(model, services)?; | ||
Ok(()) | ||
} |