Skip to content

Commit

Permalink
Merge pull request #2136 from hannobraun/holes
Browse files Browse the repository at this point in the history
Add `HoleLocation`
  • Loading branch information
hannobraun authored Dec 12, 2023
2 parents 2032e02 + 0d53138 commit c70d86b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
25 changes: 16 additions & 9 deletions crates/fj-core/src/operations/holes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ use super::{

/// Add a hole to a [`Shell`]
pub trait AddHole {
/// Add a blind hole to the provided face of the shell
/// Add a blind hole at the provided location
fn add_blind_hole(
&self,
face: &Handle<Face>,
position: impl Into<Point<2>>,
location: HoleLocation,
radius: impl Into<Scalar>,
path: impl Into<Vector<3>>,
services: &mut Services,
Expand All @@ -32,22 +31,21 @@ pub trait AddHole {
impl AddHole for Shell {
fn add_blind_hole(
&self,
face: &Handle<Face>,
position: impl Into<Point<2>>,
location: HoleLocation,
radius: impl Into<Scalar>,
path: impl Into<Vector<3>>,
services: &mut Services,
) -> Self {
let half_edge =
HalfEdge::circle(position, radius, services).insert(services);
let half_edge = HalfEdge::circle(location.position, radius, services)
.insert(services);
let hole = Region::empty(services)
.update_exterior(|_| {
Cycle::empty()
.add_half_edges([half_edge.clone()])
.insert(services)
})
.sweep_region(
face.surface(),
location.face.surface(),
path,
&mut SweepCache::default(),
services,
Expand All @@ -56,7 +54,7 @@ impl AddHole for Shell {
.map(|face| face.insert(services))
.collect::<Vec<_>>();

self.update_face(face, |face| {
self.update_face(location.face, |face| {
face.update_region(|region| {
region
.add_interiors([Cycle::empty()
Expand All @@ -76,3 +74,12 @@ impl AddHole for Shell {
.add_faces(hole)
}
}

/// Defines the location of a hole
pub struct HoleLocation<'r> {
/// The face that the hole is in
pub face: &'r Handle<Face>,

/// The position of the hole within the face, in surface coordinates
pub position: Point<2>,
}
14 changes: 9 additions & 5 deletions models/holes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use fj::{
core::{
objects::Solid,
operations::{holes::AddHole, insert::Insert, update::UpdateSolid},
operations::{
holes::{AddHole, HoleLocation},
insert::Insert,
update::UpdateSolid,
},
services::Services,
storage::Handle,
},
Expand All @@ -20,14 +24,14 @@ pub fn model(
cuboid
.update_shell(cuboid.shells().first(), |shell| {
let bottom_face = shell.faces().first();

let hole_position = [0., 0.];
let depth = size / 2.;

shell
.add_blind_hole(
bottom_face,
hole_position,
HoleLocation {
face: bottom_face,
position: [0., 0.].into(),
},
radius,
[Scalar::ZERO, Scalar::ZERO, depth],
services,
Expand Down

0 comments on commit c70d86b

Please sign in to comment.