use fj_math::Vector;
use crate::{
geometry::{curve::GlobalPath, surface::SurfaceGeometry},
storage::{Handle, Store},
};
use super::{
Cycle, Face, GlobalEdge, HalfEdge, Shell, Sketch, Solid, Surface, Vertex,
};
#[derive(Debug, Default)]
pub struct Objects {
pub cycles: Store<Cycle>,
pub faces: Store<Face>,
pub global_edges: Store<GlobalEdge>,
pub half_edges: Store<HalfEdge>,
pub shells: Store<Shell>,
pub sketches: Store<Sketch>,
pub solids: Store<Solid>,
pub surfaces: Surfaces,
pub vertices: Store<Vertex>,
}
impl Objects {
pub fn new() -> Self {
Self::default()
}
}
#[derive(Debug)]
pub struct Surfaces {
store: Store<Surface>,
xy_plane: Handle<Surface>,
xz_plane: Handle<Surface>,
yz_plane: Handle<Surface>,
}
impl Surfaces {
pub fn reserve(&self) -> Handle<Surface> {
self.store.reserve()
}
pub fn insert(&mut self, handle: Handle<Surface>, surface: Surface) {
self.store.insert(handle, surface);
}
pub fn xy_plane(&self) -> Handle<Surface> {
self.xy_plane.clone()
}
pub fn xz_plane(&self) -> Handle<Surface> {
self.xz_plane.clone()
}
pub fn yz_plane(&self) -> Handle<Surface> {
self.yz_plane.clone()
}
}
impl Default for Surfaces {
fn default() -> Self {
let mut store: Store<Surface> = Store::new();
let xy_plane = store.reserve();
store.insert(
xy_plane.clone(),
Surface::new(SurfaceGeometry {
u: GlobalPath::x_axis(),
v: Vector::unit_y(),
}),
);
let xz_plane = store.reserve();
store.insert(
xz_plane.clone(),
Surface::new(SurfaceGeometry {
u: GlobalPath::x_axis(),
v: Vector::unit_z(),
}),
);
let yz_plane = store.reserve();
store.insert(
yz_plane.clone(),
Surface::new(SurfaceGeometry {
u: GlobalPath::y_axis(),
v: Vector::unit_z(),
}),
);
Self {
store,
xy_plane,
xz_plane,
yz_plane,
}
}
}