Skip to main content

ifc_style/colour/
rgb.rs

1//! Strict `IfcColourRgb` projection.
2
3use crate::error::StyleResult;
4use crate::view::Record;
5
6/// Borrowed projection of `IfcColourRgb`: a normalized red/green/blue colour.
7#[derive(Debug, Clone, Copy)]
8pub struct ColourRgb<'m, 's> {
9    record: Record<'m, 's>,
10}
11
12impl<'m, 's> ColourRgb<'m, 's> {
13    pub(crate) fn from_record(record: Record<'m, 's>) -> Self {
14        Self { record }
15    }
16
17    /// The `Name` attribute, when authored.
18    pub fn name(&self) -> StyleResult<Option<&'m str>> {
19        self.record.optional_text("Name")
20    }
21
22    /// The `Red` component, normalized to `[0, 1]`.
23    pub fn red(&self) -> StyleResult<f64> {
24        self.record.normalized("Red")
25    }
26
27    /// The `Green` component, normalized to `[0, 1]`.
28    pub fn green(&self) -> StyleResult<f64> {
29        self.record.normalized("Green")
30    }
31
32    /// The `Blue` component, normalized to `[0, 1]`.
33    pub fn blue(&self) -> StyleResult<f64> {
34        self.record.normalized("Blue")
35    }
36
37    /// The `[Red, Green, Blue]` components as one array.
38    pub fn channels(&self) -> StyleResult<[f64; 3]> {
39        Ok([self.red()?, self.green()?, self.blue()?])
40    }
41}