1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//! Add holes to shapes
use fj_math::{Point, Scalar, Vector};
use crate::{
objects::{Cycle, Face, HalfEdge, Region, Shell},
storage::Handle,
Core,
};
use super::{
build::{BuildCycle, BuildHalfEdge, BuildRegion},
join::JoinCycle,
sweep::{SweepCache, SweepRegion},
update::{UpdateCycle, UpdateFace, UpdateRegion, UpdateShell},
};
/// Add a hole to a [`Shell`]
pub trait AddHole {
/// Add a blind hole at the provided location
fn add_blind_hole(
&self,
location: HoleLocation,
radius: impl Into<Scalar>,
path: impl Into<Vector<3>>,
core: &mut Core,
) -> Self;
/// Add a through hole between the provided locations
fn add_through_hole(
&self,
locations: [HoleLocation; 2],
radius: impl Into<Scalar>,
core: &mut Core,
) -> Self;
}
impl AddHole for Shell {
fn add_blind_hole(
&self,
location: HoleLocation,
radius: impl Into<Scalar>,
path: impl Into<Vector<3>>,
core: &mut Core,
) -> Self {
let entry = HalfEdge::circle(location.position, radius, core);
let hole = Region::empty(core)
.update_exterior(
|_, core| Cycle::empty().add_half_edges([entry.clone()], core),
core,
)
.sweep_region(
location.face.surface(),
None,
path,
&mut SweepCache::default(),
core,
)
.all_faces()
.collect::<Vec<_>>();
self.update_face(
location.face,
|face, core| {
[face.update_region(
|region, core| {
region.add_interiors(
[Cycle::empty().add_joined_edges(
[(
entry.clone(),
core.layers
.geometry
.of_half_edge(&entry)
.path,
entry.boundary(),
)],
core,
)],
core,
)
},
core,
)]
},
core,
)
.add_faces(hole, core)
}
fn add_through_hole(
&self,
[entry_location, exit_location]: [HoleLocation; 2],
radius: impl Into<Scalar>,
core: &mut Core,
) -> Self {
let radius = radius.into();
let entry = HalfEdge::circle(entry_location.position, radius, core);
let path = {
let point = |location: &HoleLocation| {
core.layers
.geometry
.of_surface(location.face.surface())
.point_from_surface_coords(location.position)
};
let entry_point = point(&entry_location);
let exit_point = point(&exit_location);
exit_point - entry_point
};
let swept_region = Region::empty(core)
.update_exterior(
|_, core| Cycle::empty().add_half_edges([entry.clone()], core),
core,
)
.sweep_region(
entry_location.face.surface(),
None,
path,
&mut SweepCache::default(),
core,
);
let hole = swept_region.side_faces.into_iter().collect::<Vec<_>>();
let exit = swept_region
.top_face
.region()
.exterior()
.half_edges()
.only();
self.update_face(
entry_location.face,
|face, core| {
[face.update_region(
|region, core| {
region.add_interiors(
[Cycle::empty().add_joined_edges(
[(
entry.clone(),
core.layers
.geometry
.of_half_edge(&entry)
.path,
entry.boundary(),
)],
core,
)],
core,
)
},
core,
)]
},
core,
)
.update_face(
exit_location.face,
|face, core| {
[face.update_region(
|region, core| {
region.add_interiors(
[Cycle::empty().add_joined_edges(
[(
exit.clone(),
core.layers
.geometry
.of_half_edge(exit)
.path,
exit.boundary(),
)],
core,
)],
core,
)
},
core,
)]
},
core,
)
.add_faces(hole, core)
}
}
/// 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>,
}