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

Add HoleLocation #2136

Merged
merged 4 commits into from
Dec 12, 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
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