Skip to main content

rscad_csg_bsp/
metadata.rs

1use nalgebra::{Point3, SVector};
2use slotmap::new_key_type;
3
4use crate::Number;
5
6// ── SlotMap keys ───────────────────────────────────────────────
7
8new_key_type! {
9    /// Key identifying a primitive solid in a [`CsgFactory`].
10    pub struct PrimitiveKey;
11    /// Key identifying a logical face of a primitive solid.
12    pub struct FaceKey;
13    /// Key identifying a logical edge of a primitive solid.
14    pub struct EdgeKey;
15}
16
17// ── Primitive kind ─────────────────────────────────────────────
18
19/// The kind of geometric primitive that was created.
20#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
21pub enum PrimitiveKind {
22    Cube,
23    Cuboid,
24    Cylinder,
25    Cone,
26    Torus,
27    Rhomboid,
28    Sphere,
29}
30
31// ── Metadata structs ───────────────────────────────────────────
32
33/// Metadata for a primitive solid registered in a [`CsgFactory`].
34#[derive(Clone, Debug)]
35pub struct PrimitiveMeta {
36    pub kind: PrimitiveKind,
37    pub face_keys: Vec<FaceKey>,
38    pub edge_keys: Vec<EdgeKey>,
39    /// Optional RGBA color (linear, 0.0–1.0) for this primitive.
40    pub color: Option<[f32; 4]>,
41}
42
43/// Metadata for a logical face of a primitive solid.
44#[derive(Clone, Debug)]
45pub struct FaceMeta<T: Number> {
46    pub primitive_key: PrimitiveKey,
47    pub normal: SVector<T, 3>,
48    pub label: String,
49}
50
51/// Metadata for a logical edge of a primitive solid.
52#[derive(Clone, Debug)]
53pub struct EdgeMeta<T: Number> {
54    pub primitive_key: PrimitiveKey,
55    pub vertices: (Point3<T>, Point3<T>),
56    pub face_keys: [FaceKey; 2],
57}