pub struct CubeCoord {
pub r: f64,
pub g: f64,
pub b: f64,
}Expand description
A position in the theme-relative color cube.
Each axis ranges from 0.0 to 1.0, representing a fractional position
between theme anchor colors:
- r: red axis — interpolates bg→red, green→yellow, blue→magenta, cyan→fg
- g: green axis — interpolates between the r-axis edge pairs
- b: blue axis — interpolates between the g-axis face results
Designers think in percentages: cube(60%, 20%, 0%) maps to
CubeCoord { r: 0.6, g: 0.2, b: 0.0 }.
Fields§
§r: f64Red axis fraction (0.0–1.0).
g: f64Green axis fraction (0.0–1.0).
b: f64Blue axis fraction (0.0–1.0).
Implementations§
Source§impl CubeCoord
impl CubeCoord
Sourcepub fn new(r: f64, g: f64, b: f64) -> Result<Self, String>
pub fn new(r: f64, g: f64, b: f64) -> Result<Self, String>
Creates a new cube coordinate with fractional values (0.0–1.0 per axis).
Returns an error if any component is outside the valid range.
Sourcepub fn from_percentages(r: f64, g: f64, b: f64) -> Result<Self, String>
pub fn from_percentages(r: f64, g: f64, b: f64) -> Result<Self, String>
Creates a cube coordinate from percentage values (0.0–100.0 per axis).
This is the natural syntax for style definitions: cube(60%, 20%, 0%)
maps to from_percentages(60.0, 20.0, 0.0).
Sourcepub fn quantize(&self, levels: u8) -> (u8, u8, u8)
pub fn quantize(&self, levels: u8) -> (u8, u8, u8)
Quantizes this coordinate to the nearest grid point for a given number of subdivisions per axis.
For the standard 256-color palette, levels = 6 (producing a 6×6×6 cube).
Returns the integer grid coordinates (r, g, b) each in 0..levels.
Sourcepub fn to_palette_index(&self, levels: u8) -> u8
pub fn to_palette_index(&self, levels: u8) -> u8
Returns the 256-color palette index for this coordinate.
Uses the standard formula: 16 + 36*r + 6*g + b where r, g, b
are quantized to 0..levels. The offset of 16 accounts for the base16
ANSI colors that occupy indices 0–15.
Trait Implementations§
impl Copy for CubeCoord
impl Eq for CubeCoord
impl StructuralPartialEq for CubeCoord
Auto Trait Implementations§
impl Freeze for CubeCoord
impl RefUnwindSafe for CubeCoord
impl Send for CubeCoord
impl Sync for CubeCoord
impl Unpin for CubeCoord
impl UnsafeUnpin for CubeCoord
impl UnwindSafe for CubeCoord
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.