pub struct Surfaces { /* private fields */ }Expand description
Store for Surfaces
Implementations§
source§impl Surfaces
impl Surfaces
sourcepub fn insert(&mut self, handle: Handle<Surface>, surface: Surface)
pub fn insert(&mut self, handle: Handle<Surface>, surface: Surface)
Insert a Surface into the store
sourcepub fn xy_plane(&self) -> Handle<Surface>
pub fn xy_plane(&self) -> Handle<Surface>
Access the xy-plane
Examples found in repository?
src/builder/shell.rs (line 42)
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(),
}
}Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Surfaces
impl Send for Surfaces
impl Sync for Surfaces
impl Unpin for Surfaces
impl !UnwindSafe for Surfaces
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.