Skip to main content

Color

Struct Color 

Source
pub struct Color { /* private fields */ }
Expand description

One named entry in the xkcd color hierarchy.

Carries every column from the upstream color_hierarchy.csv: xkcd / design / common name, hex, and RGB triples for each level, plus the family / kind / neutrality classification. The xkcd LAB triple is pre-computed at codegen time for nearest-neighbor lookup in Self::nearest_to.

Implementations§

Source§

impl Color

Source

pub const fn name(&self) -> &'static str

xkcd-survey name (~950 unique values, e.g. "burnt orange", "vermilion").

Source

pub const fn hex(&self) -> &'static str

xkcd hex string, e.g. "#bd6c48".

Source

pub const fn rgb(&self) -> [u8; 3]

xkcd RGB triple, e.g. [189, 108, 72]. The exact 8-bit value the xkcd survey reports for this name.

Source

pub const fn lab(&self) -> [f32; 3]

Pre-computed CIE LAB (D65 illuminant, 2° observer) for Self::rgb. Used internally by Self::nearest_to; exposed publicly so callers can implement their own distance metric (e.g. CIEDE2000) on top of the same cached values.

Source

pub const fn design_name(&self) -> &'static str

Coarser design-palette name (~250 unique, e.g. "russet brown").

Source

pub const fn design_hex(&self) -> &'static str

Hex string for the design-palette anchor color.

Source

pub const fn design_rgb(&self) -> [u8; 3]

RGB triple for the design-palette anchor color (the canonical 8-bit representation of Self::design_name). Differs from Self::rgb when the xkcd entry sits at the edge of its design-palette bucket.

Source

pub const fn common_name(&self) -> &'static str

Coarser still common name (~120 unique, e.g. "sienna"). The search-friendly default for indexing pipelines.

Source

pub const fn common_hex(&self) -> &'static str

Hex string for the common-name anchor color.

Source

pub const fn common_rgb(&self) -> [u8; 3]

RGB triple for the common-name anchor color.

Source

pub const fn family(&self) -> Family

Color family classification (26 values, e.g. Family::Yellow, Family::BlueGreen, [Family::Neutral]). Call Family::as_str for the original CSV string.

Source

pub const fn kind(&self) -> Kind

Color kind / texture classification (11 values, e.g. Kind::NeonColor, Kind::PainterlyNeutral). Call Kind::as_str for the original CSV string.

Source

pub const fn is_neutral(&self) -> bool

true if the entry is classified as a neutral (vs a chromatic color). Drives the color_or_neutral axis in the original Stitch Fix taxonomy.

Source

pub const fn all() -> &'static [&'static Color]

Every entry in the dataset, in CSV (alphabetical-by-name) order.

Source

pub fn nearest_to(rgb: [u8; 3]) -> &'static Color

Find the entry whose pre-computed LAB is closest to the given query RGB by Delta E 76 (squared Euclidean LAB).

Always returns an entry — COLORS is non-empty and verified at codegen time. The scan dispatches to a per-arch SIMD backend (NEON / AVX2 / SSE4.1 / WASM SIMD128) on every target that has one; other targets fall through to the scalar reference. Every backend is bit-identical — see [crate::nearest] for the dispatch contract and parity tests.

§When to use this method

Delta E 76 is the fast metric: against this crate’s well- clustered 949-entry xkcd palette it picks the same named entry as CIEDE2000 in the overwhelming majority of cases, at ~150× the throughput of Algorithm::Ciede2000Exact (the default returned by Algorithm::default). Reach for it when you’ve measured the slower default bottlenecking real workloads and can tolerate borderline misnamings near the gray / yellow boundary.

Source

pub fn nearest_to_ciede2000(rgb: [u8; 3]) -> &'static Color

Find the entry whose pre-computed LAB is closest to the given query RGB by CIEDE2000 — the modern perceptual gold-standard colour-difference formula.

CIEDE2000 corrects Delta E 76’s known biases (over-weighting yellows, under-weighting blues, hue-rotation in the saturated blue region) at the cost of atan2 / sin / cos / exp per pair plus branchy hue-wraparound logic.

§Implementation
  • With feature = "lut" (the default): O(1) cell lookup → small candidate scan via the pre-computed candidate-set LUT ([crate::nearest::ciede2000_lut]). Provably exact at u8 RGB resolution; ~few-hundred-ns/query.
  • Without feature = "lut": full-scan reference over all 949 palette entries (~71 µs/query). Same correctness guarantee, slower.

Both modes are scalar — CIEDE2000’s transcendentals don’t vectorise usefully (see [crate::nearest::ciede2000]).

Source

pub fn nearest_to_ciede2000_exact(rgb: [u8; 3]) -> &'static Color

Strict CIEDE2000 nearest-neighbor. Behaviorally equivalent to Self::nearest_to_ciede2000 — both are exact under both feature configurations (the LUT path is provably exact, the no-LUT path is full-scan). Retained as a distinct entry point for API stability; consumers picking between the two by name should prefer Self::nearest_to_ciede2000.

Source

pub fn nearest_to_cie94(rgb: [u8; 3]) -> &'static Color

Find the entry whose pre-computed LAB is closest to the given query RGB by CIE94 (Delta E 94, graphic-arts weighting).

CIE94 sits between Delta E 76 and CIEDE2000 in both perceptual accuracy and arithmetic cost. It uses no transcendentals beyond sqrt, so unlike CIEDE2000 the formula vectorises cleanly — SIMD backends are a planned follow-up that will mirror the Delta E 76 module structure.

CIE94 is asymmetric (the S_C / S_H scale factors depend on the reference’s chroma C₁); this implementation treats the palette entry as the reference and the query as the sample.

Trait Implementations§

Source§

impl Clone for Color

Source§

fn clone(&self) -> Color

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Color

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Color

Source§

fn eq(&self, other: &Color) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Color

Source§

impl StructuralPartialEq for Color

Auto Trait Implementations§

§

impl Freeze for Color

§

impl RefUnwindSafe for Color

§

impl Send for Color

§

impl Sync for Color

§

impl Unpin for Color

§

impl UnsafeUnpin for Color

§

impl UnwindSafe for Color

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.