mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-26 17:15:52 +00:00
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:
parent
d45dc11a8a
commit
10f8bb9eed
@ -266,8 +266,9 @@ mod tests {
|
|||||||
edges: vec![ab, bc, cd, da],
|
edges: vec![ab, bc, cd, da],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let surface = shape.surfaces().add(Surface::x_y_plane());
|
||||||
let face = Face::Face {
|
let face = Face::Face {
|
||||||
surface: Surface::x_y_plane(),
|
surface,
|
||||||
cycles: vec![abcd],
|
cycles: vec![abcd],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -129,10 +129,14 @@ mod tests {
|
|||||||
edges: vec![ab, bc, ca],
|
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 {
|
let abc = Face::Face {
|
||||||
surface: Surface::Swept(Swept::plane_from_points(
|
surface,
|
||||||
[a, b, c].map(|vertex| vertex.point()),
|
|
||||||
)),
|
|
||||||
cycles: vec![cycles],
|
cycles: vec![cycles],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,9 +65,11 @@ pub fn transform_face(
|
|||||||
cycles_trans.push(shape.cycles().add(Cycle { edges }));
|
cycles_trans.push(shape.cycles().add(Cycle { edges }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let surface = shape.surfaces().add(surface.transform(transform));
|
||||||
|
|
||||||
Face::Face {
|
Face::Face {
|
||||||
cycles: cycles_trans,
|
cycles: cycles_trans,
|
||||||
surface: surface.transform(transform),
|
surface,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Face::Triangles(mut triangles) => {
|
Face::Triangles(mut triangles) => {
|
||||||
|
@ -2,6 +2,7 @@ pub mod cycles;
|
|||||||
pub mod edges;
|
pub mod edges;
|
||||||
pub mod faces;
|
pub mod faces;
|
||||||
pub mod handle;
|
pub mod handle;
|
||||||
|
pub mod surfaces;
|
||||||
pub mod vertices;
|
pub mod vertices;
|
||||||
|
|
||||||
use crate::math::Scalar;
|
use crate::math::Scalar;
|
||||||
@ -10,7 +11,7 @@ use super::topology::{edges::Cycle, faces::Face, vertices::Vertex};
|
|||||||
|
|
||||||
use self::{
|
use self::{
|
||||||
cycles::Cycles, edges::Edges, faces::Faces, handle::Storage,
|
cycles::Cycles, edges::Edges, faces::Faces, handle::Storage,
|
||||||
vertices::Vertices,
|
surfaces::Surfaces, vertices::Vertices,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The boundary representation of a shape
|
/// The boundary representation of a shape
|
||||||
@ -56,6 +57,11 @@ impl Shape {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Access the shape's surfaces
|
||||||
|
pub fn surfaces(&mut self) -> Surfaces {
|
||||||
|
Surfaces
|
||||||
|
}
|
||||||
|
|
||||||
/// Access the shape's vertices
|
/// Access the shape's vertices
|
||||||
pub fn vertices(&mut self) -> Vertices {
|
pub fn vertices(&mut self) -> Vertices {
|
||||||
Vertices {
|
Vertices {
|
||||||
|
13
src/kernel/shape/surfaces.rs
Normal file
13
src/kernel/shape/surfaces.rs
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
@ -26,10 +26,8 @@ impl ToShape for fj::Circle {
|
|||||||
shape.cycles().add(Cycle { edges: vec![edge] });
|
shape.cycles().add(Cycle { edges: vec![edge] });
|
||||||
|
|
||||||
let cycles = shape.cycles().all().collect();
|
let cycles = shape.cycles().all().collect();
|
||||||
shape.faces().add(Face::Face {
|
let surface = shape.surfaces().add(Surface::x_y_plane());
|
||||||
cycles,
|
shape.faces().add(Face::Face { cycles, surface });
|
||||||
surface: Surface::x_y_plane(),
|
|
||||||
});
|
|
||||||
|
|
||||||
shape
|
shape
|
||||||
}
|
}
|
||||||
|
@ -47,9 +47,10 @@ impl ToShape for fj::Sketch {
|
|||||||
shape.cycles().add(Cycle { edges });
|
shape.cycles().add(Cycle { edges });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let surface = shape.surfaces().add(Surface::x_y_plane());
|
||||||
let face = Face::Face {
|
let face = Face::Face {
|
||||||
cycles: shape.cycles().all().collect(),
|
cycles: shape.cycles().all().collect(),
|
||||||
surface: Surface::x_y_plane(),
|
surface,
|
||||||
};
|
};
|
||||||
shape.faces().add(face);
|
shape.faces().add(face);
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ pub enum Face {
|
|||||||
/// surface.
|
/// surface.
|
||||||
Face {
|
Face {
|
||||||
/// The surface that defines this face
|
/// The surface that defines this face
|
||||||
surface: Surface,
|
surface: Handle<Surface>,
|
||||||
|
|
||||||
/// The cycles that bound the face
|
/// The cycles that bound the face
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user