Skip to content

Commit

Permalink
Fix remaining capitalization issues
Browse files Browse the repository at this point in the history
  • Loading branch information
raphlinus committed Nov 5, 2024
1 parent b694ace commit a755f9e
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 53 deletions.
4 changes: 2 additions & 2 deletions color/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<CS: ColorSpace> OpaqueColor<CS> {

/// Scale the chroma by the given amount.
///
/// See [`Colorspace::scale_chroma`] for more details.
/// See [`ColorSpace::scale_chroma`] for more details.
#[must_use]
pub fn scale_chroma(self, scale: f32) -> Self {
Self::new(CS::scale_chroma(self.components, scale))
Expand Down Expand Up @@ -252,7 +252,7 @@ impl<CS: ColorSpace> AlphaColor<CS> {

/// Scale the chroma by the given amount.
///
/// See [`Colorspace::scale_chroma`] for more details.
/// See [`ColorSpace::scale_chroma`] for more details.
#[must_use]
pub fn scale_chroma(self, scale: f32) -> Self {
let (opaque, alpha) = split_alpha(self.components);
Expand Down
16 changes: 8 additions & 8 deletions color/src/colorspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use core::f32;

use crate::{matmul, tagged::ColorspaceTag};
use crate::{matmul, tagged::ColorSpaceTag};

#[cfg(all(not(feature = "std"), not(test)))]
use crate::floatfuncs::FloatFuncs;
Expand Down Expand Up @@ -36,7 +36,7 @@ pub trait ColorSpace: Clone + Copy + 'static {
const LAYOUT: ColorSpaceLayout = ColorSpaceLayout::Rectangular;

/// The tag corresponding to this color space, if a matching tag exists.
const TAG: Option<ColorspaceTag> = None;
const TAG: Option<ColorSpaceTag> = None;

/// Convert an opaque color to linear sRGB.
///
Expand Down Expand Up @@ -101,7 +101,7 @@ pub struct LinearSrgb;
impl ColorSpace for LinearSrgb {
const IS_LINEAR: bool = true;

const TAG: Option<ColorspaceTag> = Some(ColorspaceTag::LinearSrgb);
const TAG: Option<ColorSpaceTag> = Some(ColorSpaceTag::LinearSrgb);

fn to_linear_srgb(src: [f32; 3]) -> [f32; 3] {
src
Expand Down Expand Up @@ -145,7 +145,7 @@ fn lin_to_srgb(x: f32) -> f32 {
}

impl ColorSpace for Srgb {
const TAG: Option<ColorspaceTag> = Some(ColorspaceTag::Srgb);
const TAG: Option<ColorSpaceTag> = Some(ColorSpaceTag::Srgb);

fn to_linear_srgb(src: [f32; 3]) -> [f32; 3] {
src.map(srgb_to_lin)
Expand All @@ -160,7 +160,7 @@ impl ColorSpace for Srgb {
pub struct DisplayP3;

impl ColorSpace for DisplayP3 {
const TAG: Option<ColorspaceTag> = Some(ColorspaceTag::DisplayP3);
const TAG: Option<ColorSpaceTag> = Some(ColorSpaceTag::DisplayP3);

fn to_linear_srgb(src: [f32; 3]) -> [f32; 3] {
const LINEAR_DISPLAYP3_TO_SRGB: [[f32; 3]; 3] = [
Expand All @@ -187,7 +187,7 @@ pub struct XyzD65;
impl ColorSpace for XyzD65 {
const IS_LINEAR: bool = true;

const TAG: Option<ColorspaceTag> = Some(ColorspaceTag::XyzD65);
const TAG: Option<ColorSpaceTag> = Some(ColorSpaceTag::XyzD65);

fn to_linear_srgb(src: [f32; 3]) -> [f32; 3] {
const XYZ_TO_LINEAR_SRGB: [[f32; 3]; 3] = [
Expand Down Expand Up @@ -239,7 +239,7 @@ const OKLAB_LMS_TO_LAB: [[f32; 3]; 3] = [
];

impl ColorSpace for Oklab {
const TAG: Option<ColorspaceTag> = Some(ColorspaceTag::Oklab);
const TAG: Option<ColorSpaceTag> = Some(ColorSpaceTag::Oklab);

fn to_linear_srgb(src: [f32; 3]) -> [f32; 3] {
let lms = matmul(&OKLAB_LAB_TO_LMS, src).map(|x| x * x * x);
Expand All @@ -260,7 +260,7 @@ impl ColorSpace for Oklab {
pub struct Oklch;

impl ColorSpace for Oklch {
const TAG: Option<ColorspaceTag> = Some(ColorspaceTag::Oklch);
const TAG: Option<ColorSpaceTag> = Some(ColorSpaceTag::Oklch);

const LAYOUT: ColorSpaceLayout = ColorSpaceLayout::HueThird;

Expand Down
14 changes: 7 additions & 7 deletions color/src/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
use crate::{
color::{add_alpha, fixup_hues_for_interpolate, split_alpha},
AlphaColor, Bitset, ColorSpace, ColorSpaceLayout, ColorspaceTag, HueDirection, TaggedColor,
AlphaColor, Bitset, ColorSpace, ColorSpaceLayout, ColorSpaceTag, HueDirection, TaggedColor,
};

#[derive(Clone, Copy, Debug)]
pub struct CssColor {
pub cs: ColorspaceTag,
pub cs: ColorSpaceTag,
/// A bitmask of missing components.
pub missing: Bitset,
pub components: [f32; 4],
Expand All @@ -26,7 +26,7 @@ pub struct Interpolator {
alpha1: f32,
delta_premul: [f32; 3],
alpha2: f32,
cs: ColorspaceTag,
cs: ColorSpaceTag,
missing: Bitset,
}

Expand Down Expand Up @@ -58,7 +58,7 @@ impl CssColor {
}

#[must_use]
pub fn convert(self, cs: ColorspaceTag) -> Self {
pub fn convert(self, cs: ColorSpaceTag) -> Self {
if self.cs == cs {
// Note: §12 suggests that changing powerless to missing happens
// even when the color is already in the interpolation color space,
Expand Down Expand Up @@ -105,7 +105,7 @@ impl CssColor {

/// Scale the chroma by the given amount.
///
/// See [`Colorspace::scale_chroma`] for more details.
/// See [`ColorSpace::scale_chroma`] for more details.
#[must_use]
pub fn scale_chroma(self, scale: f32) -> Self {
let (opaque, alpha) = split_alpha(self.components);
Expand Down Expand Up @@ -157,7 +157,7 @@ impl CssColor {
pub fn interpolate(
self,
other: Self,
cs: ColorspaceTag,
cs: ColorSpaceTag,
direction: HueDirection,
) -> Interpolator {
let mut a = self.convert(cs);
Expand Down Expand Up @@ -199,7 +199,7 @@ impl CssColor {
/// Blending semi-transparent colors will reduce contrast, and that
/// should also be taken into account.
pub fn relative_luminance(self) -> f32 {
let rgb = self.convert(ColorspaceTag::LinearSrgb).components;
let rgb = self.convert(ColorSpaceTag::LinearSrgb).components;
0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2]
}
}
Expand Down
4 changes: 2 additions & 2 deletions color/src/gradient.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 the Color Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::{ColorSpace, ColorspaceTag, CssColor, HueDirection, Interpolator, Oklab, PremulColor};
use crate::{ColorSpace, ColorSpaceTag, CssColor, HueDirection, Interpolator, Oklab, PremulColor};

#[expect(missing_debug_implementations, reason = "it's an iterator")]
pub struct GradientIter<CS: ColorSpace> {
Expand All @@ -19,7 +19,7 @@ pub struct GradientIter<CS: ColorSpace> {
pub fn gradient<CS: ColorSpace>(
mut color0: CssColor,
mut color1: CssColor,
interp_cs: ColorspaceTag,
interp_cs: ColorSpaceTag,
direction: HueDirection,
tolerance: f32,
) -> GradientIter<CS> {
Expand Down
2 changes: 1 addition & 1 deletion color/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub use colorspace::{
pub use css::{CssColor, Interpolator};
pub use gradient::{gradient, GradientIter};
pub use parse::{parse_color, Error};
pub use tagged::{ColorspaceTag, TaggedColor};
pub use tagged::{ColorSpaceTag, TaggedColor};

const fn u8_to_f32(x: u32) -> f32 {
x as f32 * (1.0 / 255.0)
Expand Down
22 changes: 11 additions & 11 deletions color/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use core::f64;
use core::str::FromStr;

use crate::{AlphaColor, Bitset, ColorspaceTag, CssColor, Srgb, TaggedColor};
use crate::{AlphaColor, Bitset, ColorSpaceTag, CssColor, Srgb, TaggedColor};

// TODO: proper error type, maybe include string offset
pub type Error = &'static str;
Expand All @@ -30,7 +30,7 @@ enum Value<'a> {
clippy::cast_possible_truncation,
reason = "deliberate choice of f32 for colors"
)]
fn color_from_components(components: [Option<f64>; 4], cs: ColorspaceTag) -> CssColor {
fn color_from_components(components: [Option<f64>; 4], cs: ColorSpaceTag) -> CssColor {
let mut missing = Bitset::default();
for (i, component) in components.iter().enumerate() {
if component.is_none() {
Expand Down Expand Up @@ -285,7 +285,7 @@ impl<'a> Parser<'a> {
if !self.ch(b')') {
return Err("expected closing parenthesis");
}
Ok(color_from_components([r, g, b, alpha], ColorspaceTag::Srgb))
Ok(color_from_components([r, g, b, alpha], ColorSpaceTag::Srgb))
}

fn optional_alpha(&mut self) -> Result<Option<f64>, Error> {
Expand All @@ -311,7 +311,7 @@ impl<'a> Parser<'a> {
}
Ok(color_from_components(
[l, a, b, alpha],
ColorspaceTag::Oklab,
ColorSpaceTag::Oklab,
))
}

Expand All @@ -328,7 +328,7 @@ impl<'a> Parser<'a> {
}
Ok(color_from_components(
[l, c, h, alpha],
ColorspaceTag::Oklch,
ColorSpaceTag::Oklch,
))
}

Expand All @@ -341,10 +341,10 @@ impl<'a> Parser<'a> {
return Err("expected identifier for colorspace");
};
let cs = match id {
"srgb" => ColorspaceTag::Srgb,
"srgb-linear" => ColorspaceTag::LinearSrgb,
"display-p3" => ColorspaceTag::DisplayP3,
"xyz" | "xyz-d65" => ColorspaceTag::XyzD65,
"srgb" => ColorSpaceTag::Srgb,
"srgb-linear" => ColorSpaceTag::LinearSrgb,
"display-p3" => ColorSpaceTag::DisplayP3,
"xyz" | "xyz-d65" => ColorSpaceTag::XyzD65,
_ => return Err("unknown colorspace"),
};
let r = self.scaled_component(1., 0.01)?;
Expand Down Expand Up @@ -377,7 +377,7 @@ pub fn parse_color(s: &str) -> Result<CssColor, Error> {
"rgb" | "rgba" => parser.rgb(),
"oklab" => parser.oklab(),
"oklch" => parser.oklch(),
"transparent" => Ok(color_from_components([Some(0.); 4], ColorspaceTag::Srgb)),
"transparent" => Ok(color_from_components([Some(0.); 4], ColorSpaceTag::Srgb)),
"color" => parser.color(),
_ => Err("unknown identifier"),
}
Expand Down Expand Up @@ -425,7 +425,7 @@ const fn color_from_4bit_hex(components: [u8; 8]) -> AlphaColor<Srgb> {
AlphaColor::from_rgba8(r0 << 4 | r1, g0 << 4 | g1, b0 << 4 | b1, a0 << 4 | a1)
}

impl FromStr for ColorspaceTag {
impl FromStr for ColorSpaceTag {
type Err = &'static str;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Expand Down
18 changes: 9 additions & 9 deletions color/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use core::fmt::{Formatter, Result};

use crate::{ColorspaceTag, CssColor};
use crate::{ColorSpaceTag, CssColor};

fn write_scaled_component(
color: &CssColor,
Expand Down Expand Up @@ -57,7 +57,7 @@ fn write_color_function(color: &CssColor, name: &str, f: &mut Formatter<'_>) ->
impl core::fmt::Display for CssColor {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match self.cs {
ColorspaceTag::Srgb => {
ColorSpaceTag::Srgb => {
// A case can be made this isn't the best serialization in general,
// because CSS parsing of out-of-gamut components will clamp.
let opt_a = if self.components[3] < 1.0 { "a" } else { "" };
Expand All @@ -74,13 +74,13 @@ impl core::fmt::Display for CssColor {
}
write!(f, ")")
}
ColorspaceTag::LinearSrgb => write_color_function(self, "srgb-linear", f),
ColorspaceTag::DisplayP3 => write_color_function(self, "display-p3", f),
ColorspaceTag::XyzD65 => write_color_function(self, "xyz", f),
ColorspaceTag::Lab => write_modern_function(self, "lab", f),
ColorspaceTag::Lch => write_modern_function(self, "lch", f),
ColorspaceTag::Oklab => write_modern_function(self, "oklab", f),
ColorspaceTag::Oklch => write_modern_function(self, "oklch", f),
ColorSpaceTag::LinearSrgb => write_color_function(self, "srgb-linear", f),
ColorSpaceTag::DisplayP3 => write_color_function(self, "display-p3", f),
ColorSpaceTag::XyzD65 => write_color_function(self, "xyz", f),
ColorSpaceTag::Lab => write_modern_function(self, "lab", f),
ColorSpaceTag::Lch => write_modern_function(self, "lch", f),
ColorSpaceTag::Oklab => write_modern_function(self, "oklab", f),
ColorSpaceTag::Oklch => write_modern_function(self, "oklch", f),
_ => todo!(),
}
}
Expand Down
Loading

0 comments on commit a755f9e

Please sign in to comment.