Struct fj_kernel::partial::PartialHalfEdge
source · pub struct PartialHalfEdge {
pub vertices: [Partial<Vertex>; 2],
pub global_form: Partial<GlobalEdge>,
}Expand description
A partial HalfEdge
Fields§
§vertices: [Partial<Vertex>; 2]The vertices that bound the half-edge on the curve
global_form: Partial<GlobalEdge>The global form of the half-edge
Implementations§
source§impl PartialHalfEdge
impl PartialHalfEdge
sourcepub fn curve(&self) -> Partial<Curve>
pub fn curve(&self) -> Partial<Curve>
Access the curve the partial edge is defined on
Examples found in repository?
More examples
src/builder/edge.rs (line 53)
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
fn update_as_circle_from_radius(&mut self, radius: impl Into<Scalar>) {
let mut curve = self.curve();
curve.write().update_as_circle_from_radius(radius);
let path = curve
.read()
.path
.expect("Expected path that was just created");
let [a_curve, b_curve] =
[Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord]));
let mut surface_vertex = {
let [vertex, _] = &mut self.vertices;
vertex.write().surface_form.clone()
};
surface_vertex.write().position =
Some(path.point_from_path_coords(a_curve));
for (vertex, point_curve) in
self.vertices.each_mut_ext().zip_ext([a_curve, b_curve])
{
let mut vertex = vertex.write();
vertex.position = Some(point_curve);
vertex.surface_form = surface_vertex.clone();
}
self.infer_global_form();
}
fn update_as_line_segment_from_points(
&mut self,
surface: impl Into<Partial<Surface>>,
points: [impl Into<Point<2>>; 2],
) {
let surface = surface.into();
for (vertex, point) in self.vertices.each_mut_ext().zip_ext(points) {
let mut vertex = vertex.write();
vertex.curve.write().surface = surface.clone();
let mut surface_form = vertex.surface_form.write();
surface_form.position = Some(point.into());
surface_form.surface = surface.clone();
}
self.update_as_line_segment()
}
fn update_as_line_segment(&mut self) {
let points_surface = self.vertices.each_ref_ext().map(|vertex| {
vertex
.read()
.surface_form
.read()
.position
.expect("Can't infer line segment without surface position")
});
self.curve()
.write()
.update_as_line_from_points(points_surface);
for (vertex, position) in self.vertices.each_mut_ext().zip_ext([0., 1.])
{
vertex.write().position = Some([position].into());
}
self.infer_global_form();
}
fn infer_global_form(&mut self) -> Partial<GlobalEdge> {
self.global_form.write().curve =
self.curve().read().global_form.clone();
self.global_form.write().vertices =
self.vertices.each_ref_ext().map(|vertex| {
vertex.read().surface_form.read().global_form.clone()
});
self.global_form.clone()
}src/builder/shell.rs (line 87)
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
fn create_cube_from_edge_length(
edge_length: impl Into<Scalar>,
objects: &mut Service<Objects>,
) -> Self {
let edge_length = edge_length.into();
// Let's define some short-hands. We're going to need them a lot.
const Z: Scalar = Scalar::ZERO;
let h = edge_length / 2.;
let bottom_face = {
let surface =
objects.surfaces.xy_plane().translate([Z, Z, -h], objects);
let mut face = PartialFace::default();
face.update_exterior_as_polygon(
surface,
[[-h, -h], [h, -h], [h, h], [-h, h]],
);
face
};
let (side_faces, top_edges) = {
let side_surfaces = bottom_face
.exterior
.read()
.half_edges
.iter()
.map(|half_edge| {
let [a, b] =
half_edge.read().vertices.clone().map(|mut vertex| {
vertex
.write()
.surface_form
.write()
.infer_global_position()
});
let c = a + [Z, Z, edge_length];
let (surface, _) =
PartialSurface::plane_from_points([a, b, c]);
Partial::from_partial(surface)
})
.collect::<Vec<_>>();
let bottom_edges = bottom_face
.exterior
.read()
.half_edges
.iter()
.zip(&side_surfaces)
.map(|(half_edge, surface)| {
let global_edge = half_edge.read().global_form.clone();
let mut half_edge = PartialHalfEdge::default();
half_edge.curve().write().global_form =
global_edge.read().curve.clone();
for (vertex, global_form) in half_edge
.vertices
.iter_mut()
.zip(&global_edge.read().vertices)
{
vertex.write().surface_form.write().global_form =
global_form.clone();
}
half_edge.global_form = global_edge;
half_edge.update_as_line_segment_from_points(
surface.clone(),
[[Z, Z], [edge_length, Z]],
);
Partial::from_partial(half_edge)
})
.collect::<Vec<_>>();
let side_edges_up = bottom_edges
.clone()
.into_iter()
.zip(&side_surfaces)
.map(|(bottom, surface): (Partial<HalfEdge>, _)| {
let from_surface = {
let [_, from] = &bottom.read().vertices;
let from = from.read();
from.surface_form.clone()
};
let to_position = from_surface.read().position.unwrap()
+ [Z, edge_length];
let mut half_edge = PartialHalfEdge::default();
half_edge.curve().write().surface = surface.clone();
{
let [from, to] = &mut half_edge.vertices;
from.write().surface_form = from_surface;
let mut to = to.write();
let mut to_surface = to.surface_form.write();
to_surface.position = Some(to_position);
to_surface.surface = surface.clone();
}
half_edge.infer_global_form();
half_edge.update_as_line_segment();
Partial::from_partial(half_edge)
})
.collect::<Vec<_>>();
let side_edges_down = {
let mut sides_up_prev = side_edges_up.clone();
sides_up_prev.rotate_right(1);
bottom_edges
.clone()
.into_iter()
.zip(sides_up_prev)
.zip(&side_surfaces)
.map(
|((bottom, side_up_prev), surface): (
(_, Partial<HalfEdge>),
_,
)| {
let [_, from] =
side_up_prev.read().vertices.clone();
let [to, _] = bottom.read().vertices.clone();
let from_global = from
.read()
.surface_form
.read()
.global_form
.clone();
let to_surface = to.read().surface_form.clone();
let mut half_edge = PartialHalfEdge::default();
half_edge.curve().write().surface = surface.clone();
half_edge.curve().write().global_form =
side_up_prev
.read()
.curve()
.read()
.global_form
.clone();
{
let [from, to] = &mut half_edge.vertices;
let mut from = from.write();
let mut from_surface =
from.surface_form.write();
from_surface.position = Some(
to_surface.read().position.unwrap()
+ [Z, edge_length],
);
from_surface.surface = surface.clone();
from_surface.global_form = from_global;
to.write().surface_form = to_surface;
}
half_edge.infer_global_form();
half_edge.update_as_line_segment();
Partial::from_partial(half_edge)
},
)
.collect::<Vec<_>>()
};
let top_edges = side_edges_up
.clone()
.into_iter()
.zip(side_edges_down.clone())
.map(|(side_up, side_down): (_, Partial<HalfEdge>)| {
let [_, from] = side_up.read().vertices.clone();
let [to, _] = side_down.read().vertices.clone();
let from_surface = from.read().surface_form.clone();
let to_surface = to.read().surface_form.clone();
let mut half_edge = PartialHalfEdge::default();
half_edge.curve().write().surface =
from_surface.read().surface.clone();
half_edge.global_form.write().vertices = [
from_surface.read().global_form.clone(),
to_surface.read().global_form.clone(),
];
{
let [from, to] = &mut half_edge.vertices;
from.write().surface_form = from_surface;
to.write().surface_form = to_surface;
}
half_edge.update_as_line_segment();
Partial::from_partial(half_edge)
})
.collect::<Vec<_>>();
let side_faces = bottom_edges
.into_iter()
.zip(side_edges_up)
.zip(top_edges.clone())
.zip(side_edges_down)
.map(|(((bottom, side_up), top), side_down)| {
let mut cycle = PartialCycle::default();
cycle.half_edges.extend([bottom, side_up, top, side_down]);
PartialFace {
exterior: Partial::from_partial(cycle),
..Default::default()
}
})
.collect::<Vec<_>>();
(side_faces, top_edges)
};
let top_face = {
let surface = Partial::from(
objects.surfaces.xy_plane().translate([Z, Z, h], objects),
);
let mut top_edges = top_edges;
top_edges.reverse();
let surface_vertices = {
let points = [[-h, -h], [-h, h], [h, h], [h, -h]];
let mut edges = top_edges.iter();
let half_edges = array::from_fn(|_| edges.next().unwrap());
let [a, b, c, d] = points
.into_iter_fixed()
.zip(half_edges)
.collect::<[_; 4]>()
.map(|(point, edge)| {
let [vertex, _] = edge.read().vertices.clone();
let global_vertex = vertex
.read()
.surface_form
.read()
.global_form
.clone();
Partial::from_partial(PartialSurfaceVertex {
position: Some(point.into()),
surface: surface.clone(),
global_form: global_vertex,
})
});
[a.clone(), b, c, d, a]
};
let mut half_edges = Vec::new();
for (surface_vertices, edge) in surface_vertices
.as_slice()
.array_windows_ext()
.zip(top_edges)
{
let global_form = edge.read().global_form.clone();
let mut half_edge = PartialHalfEdge::default();
half_edge.curve().write().surface = surface.clone();
half_edge.curve().write().global_form =
global_form.read().curve.clone();
half_edge.global_form = global_form;
for (vertex, surface_form) in half_edge
.vertices
.each_mut_ext()
.zip_ext(surface_vertices.each_ref_ext())
{
vertex.write().surface_form = surface_form.clone();
}
half_edge.update_as_line_segment();
half_edges.push(Partial::from_partial(half_edge));
}
PartialFace {
exterior: Partial::from_partial(PartialCycle { half_edges }),
..Default::default()
}
};
PartialShell {
faces: [bottom_face]
.into_iter()
.chain(side_faces)
.chain([top_face])
.map(Partial::from_partial)
.collect(),
}
}sourcepub fn back(&self) -> &Partial<Vertex>
pub fn back(&self) -> &Partial<Vertex>
Access a reference to the half-edge’s back vertex
Examples found in repository?
src/builder/cycle.rs (line 102)
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
fn add_half_edge(&mut self) -> Partial<HalfEdge> {
let mut new_half_edge = Partial::<HalfEdge>::new();
let (first_half_edge, mut last_half_edge) =
match self.half_edges.first() {
Some(first_half_edge) => {
let first_half_edge = first_half_edge.clone();
let last_half_edge = self
.half_edges
.last()
.cloned()
.unwrap_or_else(|| first_half_edge.clone());
(first_half_edge, last_half_edge)
}
None => (new_half_edge.clone(), new_half_edge.clone()),
};
{
let shared_surface_vertex =
new_half_edge.read().back().read().surface_form.clone();
let mut last_half_edge = last_half_edge.write();
last_half_edge.front_mut().write().surface_form =
shared_surface_vertex;
last_half_edge.infer_global_form();
}
{
let shared_surface_vertex =
first_half_edge.read().back().read().surface_form.clone();
let shared_surface = shared_surface_vertex.read().surface.clone();
let mut new_half_edge = new_half_edge.write();
new_half_edge.front_mut().write().surface_form =
shared_surface_vertex;
new_half_edge.replace_surface(shared_surface);
new_half_edge.infer_global_form();
}
self.half_edges.push(new_half_edge.clone());
new_half_edge
}sourcepub fn back_mut(&mut self) -> &mut Partial<Vertex>
pub fn back_mut(&mut self) -> &mut Partial<Vertex>
Access a mutable reference to the half-edge’s back vertex
Examples found in repository?
src/builder/cycle.rs (line 136)
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
fn add_half_edge_from_point_to_start(
&mut self,
point: impl Into<Point<2>>,
) -> Partial<HalfEdge> {
let mut half_edge = self.add_half_edge();
half_edge
.write()
.back_mut()
.write()
.surface_form
.write()
.position = Some(point.into());
half_edge
}sourcepub fn front_mut(&mut self) -> &mut Partial<Vertex>
pub fn front_mut(&mut self) -> &mut Partial<Vertex>
Access a mutable reference to the half-edge’s front vertex
Examples found in repository?
src/builder/cycle.rs (line 106)
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
fn add_half_edge(&mut self) -> Partial<HalfEdge> {
let mut new_half_edge = Partial::<HalfEdge>::new();
let (first_half_edge, mut last_half_edge) =
match self.half_edges.first() {
Some(first_half_edge) => {
let first_half_edge = first_half_edge.clone();
let last_half_edge = self
.half_edges
.last()
.cloned()
.unwrap_or_else(|| first_half_edge.clone());
(first_half_edge, last_half_edge)
}
None => (new_half_edge.clone(), new_half_edge.clone()),
};
{
let shared_surface_vertex =
new_half_edge.read().back().read().surface_form.clone();
let mut last_half_edge = last_half_edge.write();
last_half_edge.front_mut().write().surface_form =
shared_surface_vertex;
last_half_edge.infer_global_form();
}
{
let shared_surface_vertex =
first_half_edge.read().back().read().surface_form.clone();
let shared_surface = shared_surface_vertex.read().surface.clone();
let mut new_half_edge = new_half_edge.write();
new_half_edge.front_mut().write().surface_form =
shared_surface_vertex;
new_half_edge.replace_surface(shared_surface);
new_half_edge.infer_global_form();
}
self.half_edges.push(new_half_edge.clone());
new_half_edge
}Trait Implementations§
source§impl Clone for PartialHalfEdge
impl Clone for PartialHalfEdge
source§fn clone(&self) -> PartialHalfEdge
fn clone(&self) -> PartialHalfEdge
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for PartialHalfEdge
impl Debug for PartialHalfEdge
source§impl Default for PartialHalfEdge
impl Default for PartialHalfEdge
source§impl HalfEdgeBuilder for PartialHalfEdge
impl HalfEdgeBuilder for PartialHalfEdge
source§fn replace_surface(&mut self, surface: impl Into<Partial<Surface>>)
fn replace_surface(&mut self, surface: impl Into<Partial<Surface>>)
Completely replace the surface in this half-edge’s object graph Read more
source§fn update_as_circle_from_radius(&mut self, radius: impl Into<Scalar>)
fn update_as_circle_from_radius(&mut self, radius: impl Into<Scalar>)
Update partial half-edge to be a circle, from the given radius
source§fn update_as_line_segment_from_points(
&mut self,
surface: impl Into<Partial<Surface>>,
points: [impl Into<Point<2>>; 2]
)
fn update_as_line_segment_from_points(
&mut self,
surface: impl Into<Partial<Surface>>,
points: [impl Into<Point<2>>; 2]
)
Update partial half-edge to be a line segment, from the given points
source§fn update_as_line_segment(&mut self)
fn update_as_line_segment(&mut self)
Update partial half-edge to be a line segment
source§fn infer_global_form(&mut self) -> Partial<GlobalEdge>
fn infer_global_form(&mut self) -> Partial<GlobalEdge>
Infer the global form of the half-edge Read more
source§impl PartialObject for PartialHalfEdge
impl PartialObject for PartialHalfEdge
Auto Trait Implementations§
impl !RefUnwindSafe for PartialHalfEdge
impl Send for PartialHalfEdge
impl Sync for PartialHalfEdge
impl Unpin for PartialHalfEdge
impl !UnwindSafe for PartialHalfEdge
Blanket Implementations§
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.