-
-
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 #2128 from hannobraun/holes
Add operation for adding blind holes
- Loading branch information
Showing
7 changed files
with
128 additions
and
0 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,76 @@ | ||
//! Add holes to shapes | ||
|
||
use fj_math::{Point, Vector}; | ||
|
||
use crate::{ | ||
objects::{Cycle, Face, HalfEdge, Region, Shell}, | ||
services::Services, | ||
storage::Handle, | ||
}; | ||
|
||
use super::{ | ||
build::{BuildCycle, BuildHalfEdge, BuildRegion}, | ||
insert::Insert, | ||
join::JoinCycle, | ||
sweep::{SweepCache, SweepRegion}, | ||
update::{UpdateCycle, UpdateFace, UpdateRegion, UpdateShell}, | ||
}; | ||
|
||
/// Add a hole to a [`Shell`] | ||
pub trait AddHole { | ||
/// Add a blind hole to the provided face of the shell | ||
fn add_blind_hole( | ||
&self, | ||
face: &Handle<Face>, | ||
position: impl Into<Point<2>>, | ||
path: impl Into<Vector<3>>, | ||
services: &mut Services, | ||
) -> Self; | ||
} | ||
|
||
impl AddHole for Shell { | ||
fn add_blind_hole( | ||
&self, | ||
face: &Handle<Face>, | ||
position: impl Into<Point<2>>, | ||
path: impl Into<Vector<3>>, | ||
services: &mut Services, | ||
) -> Self { | ||
let half_edge = | ||
HalfEdge::circle(position, 0.25, services).insert(services); | ||
let hole = Region::empty(services) | ||
.update_exterior(|_| { | ||
Cycle::empty() | ||
.add_half_edges([half_edge.clone()]) | ||
.insert(services) | ||
}) | ||
.sweep_region( | ||
face.surface(), | ||
path, | ||
&mut SweepCache::default(), | ||
services, | ||
) | ||
.into_iter() | ||
.map(|face| face.insert(services)) | ||
.collect::<Vec<_>>(); | ||
|
||
self.update_face(face, |face| { | ||
face.update_region(|region| { | ||
region | ||
.add_interiors([Cycle::empty() | ||
.add_joined_edges( | ||
[( | ||
half_edge.clone(), | ||
half_edge.path(), | ||
half_edge.boundary(), | ||
)], | ||
services, | ||
) | ||
.insert(services)]) | ||
.insert(services) | ||
}) | ||
.insert(services) | ||
}) | ||
.add_faces(hole) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
//! send a pull request! | ||
|
||
pub mod build; | ||
pub mod holes; | ||
pub mod insert; | ||
pub mod join; | ||
pub mod merge; | ||
|
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,10 @@ | ||
[package] | ||
name = "holes" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies.fj] | ||
path = "../../crates/fj" | ||
|
||
[dependencies.cuboid] | ||
path = "../cuboid" |
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,24 @@ | ||
use fj::core::{ | ||
objects::Solid, | ||
operations::{holes::AddHole, insert::Insert, update::UpdateSolid}, | ||
services::Services, | ||
storage::Handle, | ||
}; | ||
|
||
pub fn model(services: &mut Services) -> Handle<Solid> { | ||
let cuboid = cuboid::model(1., 1., 1., services); | ||
|
||
let shell = cuboid.shells().first(); | ||
let bottom_face = shell.faces().first(); | ||
|
||
let hole_position = [0., 0.]; | ||
let hole_path = [0., 0., 0.5]; | ||
|
||
cuboid | ||
.update_shell(shell, |shell| { | ||
shell | ||
.add_blind_hole(bottom_face, hole_position, hole_path, 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 = holes::model(&mut services); | ||
handle_model(model, services)?; | ||
Ok(()) | ||
} |