use derive_more::derive::From;
use nalgebra as na;
use crate::{common::Unit, scad_display::ScadDisplay};
pub type RGB = na::Vector3<Unit>;
pub type RGBA = na::Vector4<Unit>;
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Angle {
Deg(Unit),
Rad(Unit),
}
impl Angle {
pub const fn deg(&self) -> Unit {
match *self {
Self::Deg(d) => d,
Self::Rad(r) => r.to_degrees(),
}
}
}
impl ScadDisplay for Angle {
fn repr_scad(&self) -> String {
self.deg().repr_scad()
}
}
#[derive(Clone, Debug, PartialEq, From)]
pub enum ScadColor {
RGB(RGB),
RGBA(RGBA),
Name(String),
}
impl ScadDisplay for RGBA {
fn repr_scad(&self) -> String {
format!(
"[{}, {}, {}, {}]",
self[0].repr_scad(),
self[1].repr_scad(),
self[2].repr_scad(),
self[3].repr_scad()
)
}
}
impl ScadColor {
pub const fn name(&self) -> &'static str {
match *self {
Self::Name(_) => "",
_ => "c",
}
}
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum RoundSize {
Radius(Unit),
Diameter(Unit),
}
impl RoundSize {
pub const fn name(&self) -> &'static str {
match *self {
Self::Radius(_) => "r",
Self::Diameter(_) => "d",
}
}
}
impl ScadDisplay for RoundSize {
fn repr_scad(&self) -> String {
match self {
Self::Radius(r) => r.repr_scad(),
Self::Diameter(d) => d.repr_scad(),
}
}
}
impl ScadDisplay for ScadColor {
fn repr_scad(&self) -> String {
match self {
Self::RGB(rgb) => rgb.repr_scad(),
Self::RGBA(rgba) => rgba.repr_scad(),
Self::Name(name) => format!("\"{name}\""), }
}
}