Skip to main content

dynamics_spatial/
color.rs

1//! Defines RGBA color representation, used for geometric visualization.
2
3use nalgebra::Vector4;
4
5#[derive(Debug, Clone, Copy, PartialEq)]
6/// RGBA color representation.
7pub struct Color(pub(crate) Vector4<f64>);
8
9impl Color {
10    /// Creates a new `Color` from RGBA components.
11    #[must_use]
12    pub fn new(r: f64, g: f64, b: f64, a: f64) -> Self {
13        Self(Vector4::new(r, g, b, a))
14    }
15
16    /// Black color with full opacity.
17    #[must_use]
18    pub fn black() -> Self {
19        Self(Vector4::new(0.0, 0.0, 0.0, 1.0))
20    }
21
22    /// White color with full opacity.
23    #[must_use]
24    pub fn white() -> Self {
25        Self(Vector4::new(1.0, 1.0, 1.0, 1.0))
26    }
27
28    /// Transparent "black" color.
29    #[must_use]
30    pub fn transparent() -> Self {
31        Self(Vector4::new(0.0, 0.0, 0.0, 0.0))
32    }
33
34    #[must_use]
35    pub fn as_slice(&self) -> &[f64; 4] {
36        self.0.as_slice().try_into().unwrap()
37    }
38}