Add API for adding surfaces to Shape

The surfaces aren't actually stored yet, as that is not necessary right
now. Going through this API paves the way for future additions though.
This commit is contained in:
Hanno Braun 2022-03-08 14:59:40 +01:00
parent d45dc11a8a
commit 10f8bb9eed
8 changed files with 37 additions and 12 deletions

View File

@ -266,8 +266,9 @@ mod tests {
edges: vec![ab, bc, cd, da],
});
let surface = shape.surfaces().add(Surface::x_y_plane());
let face = Face::Face {
surface: Surface::x_y_plane(),
surface,
cycles: vec![abcd],
};

View File

@ -129,10 +129,14 @@ mod tests {
edges: vec![ab, bc, ca],
});
let surface =
shape
.surfaces()
.add(Surface::Swept(Swept::plane_from_points(
[a, b, c].map(|vertex| vertex.point()),
)));
let abc = Face::Face {
surface: Surface::Swept(Swept::plane_from_points(
[a, b, c].map(|vertex| vertex.point()),
)),
surface,
cycles: vec![cycles],
};

View File

@ -65,9 +65,11 @@ pub fn transform_face(
cycles_trans.push(shape.cycles().add(Cycle { edges }));
}
let surface = shape.surfaces().add(surface.transform(transform));
Face::Face {
cycles: cycles_trans,
surface: surface.transform(transform),
surface,
}
}
Face::Triangles(mut triangles) => {

View File

@ -2,6 +2,7 @@ pub mod cycles;
pub mod edges;
pub mod faces;
pub mod handle;
pub mod surfaces;
pub mod vertices;
use crate::math::Scalar;
@ -10,7 +11,7 @@ use super::topology::{edges::Cycle, faces::Face, vertices::Vertex};
use self::{
cycles::Cycles, edges::Edges, faces::Faces, handle::Storage,
vertices::Vertices,
surfaces::Surfaces, vertices::Vertices,
};
/// The boundary representation of a shape
@ -56,6 +57,11 @@ impl Shape {
self
}
/// Access the shape's surfaces
pub fn surfaces(&mut self) -> Surfaces {
Surfaces
}
/// Access the shape's vertices
pub fn vertices(&mut self) -> Vertices {
Vertices {

View File

@ -0,0 +1,13 @@
use crate::kernel::geometry::Surface;
use super::handle::{Handle, Storage};
/// API to access the surfaces of a shape
pub struct Surfaces;
impl Surfaces {
/// Add a surface to the shape
pub fn add(&mut self, surface: Surface) -> Handle<Surface> {
Storage::new(surface).handle()
}
}

View File

@ -26,10 +26,8 @@ impl ToShape for fj::Circle {
shape.cycles().add(Cycle { edges: vec![edge] });
let cycles = shape.cycles().all().collect();
shape.faces().add(Face::Face {
cycles,
surface: Surface::x_y_plane(),
});
let surface = shape.surfaces().add(Surface::x_y_plane());
shape.faces().add(Face::Face { cycles, surface });
shape
}

View File

@ -47,9 +47,10 @@ impl ToShape for fj::Sketch {
shape.cycles().add(Cycle { edges });
};
let surface = shape.surfaces().add(Surface::x_y_plane());
let face = Face::Face {
cycles: shape.cycles().all().collect(),
surface: Surface::x_y_plane(),
surface,
};
shape.faces().add(face);

View File

@ -26,7 +26,7 @@ pub enum Face {
/// surface.
Face {
/// The surface that defines this face
surface: Surface,
surface: Handle<Surface>,
/// The cycles that bound the face
///