diff --git a/CHANGELOG.md b/CHANGELOG.md index 3923026..af240ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ This release has an [MSRV][] of 1.82. * `AlphaColor`, `OpaqueColor`, and `PremulColor` now impl `PartialEq`. ([#76][], [#86][] by [@waywardmonkeys][]) * `HueDirection` now impls `PartialEq`. ([#79][] by [@waywardmonkeys][]) * `ColorSpaceTag` and `HueDirection` now have bytemuck support. ([#81][] by [@waywardmonkeys][]) +* `AlphaColor`, `DynamicColor`, `OpaqueColor`, and `PremulColor` now default to an opaque white. ([#85][] by [@waywardmonkeys][]) ### Changed @@ -62,6 +63,7 @@ This is the initial release. [#79]: https://github.com/linebender/color/pull/79 [#80]: https://github.com/linebender/color/pull/80 [#81]: https://github.com/linebender/color/pull/81 +[#85]: https://github.com/linebender/color/pull/85 [#86]: https://github.com/linebender/color/pull/86 [Unreleased]: https://github.com/linebender/color/compare/v0.1.0...HEAD diff --git a/color/src/color.rs b/color/src/color.rs index 2e7e350..ed70c22 100644 --- a/color/src/color.rs +++ b/color/src/color.rs @@ -21,6 +21,9 @@ use crate::floatfuncs::FloatFuncs; /// major motivation for including these is to enable weighted sums, including /// for spline interpolation. For cylindrical color spaces, hue fixup should /// be applied before interpolation. +/// +/// The default value is an opaque white. We don't recommend relying upon this +/// default. #[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[repr(transparent)] @@ -37,6 +40,9 @@ pub struct OpaqueColor { /// /// A color in a color space known at compile time, with an alpha channel. /// +/// The default value is an opaque white. We don't recommend relying upon this +/// default. +/// /// See [`OpaqueColor`] for a discussion of arithmetic traits and interpolation. #[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] @@ -60,6 +66,9 @@ pub struct AlphaColor { /// the hue channel is not premultiplied. If it were, interpolation would /// give undesirable results. /// +/// The default value is an opaque white. We don't recommend relying upon this +/// default. +/// /// See [`OpaqueColor`] for a discussion of arithmetic traits and interpolation. #[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] @@ -637,6 +646,26 @@ impl PremulColor { } } +// Defaults + +impl Default for AlphaColor { + fn default() -> Self { + Self::WHITE + } +} + +impl Default for OpaqueColor { + fn default() -> Self { + Self::WHITE + } +} + +impl Default for PremulColor { + fn default() -> Self { + Self::WHITE + } +} + // Lossless conversion traits. impl From> for AlphaColor { diff --git a/color/src/dynamic.rs b/color/src/dynamic.rs index 69389f7..daadcf1 100644 --- a/color/src/dynamic.rs +++ b/color/src/dynamic.rs @@ -6,6 +6,7 @@ use crate::{ color::{add_alpha, fixup_hues_for_interpolate, split_alpha}, AlphaColor, ColorSpace, ColorSpaceLayout, ColorSpaceTag, HueDirection, LinearSrgb, Missing, + Srgb, }; use core::hash::{Hash, Hasher}; @@ -25,6 +26,9 @@ use core::hash::{Hash, Hasher}; /// When manipulating components directly, setting them nonzero when the /// corresponding missing flag is set may yield unexpected results. /// +/// The default value is an opaque white in the [sRGB](Srgb) color space with +/// no missing components. We don't recommend relying upon this default. +/// /// [Oklch]: crate::Oklch #[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] @@ -365,6 +369,12 @@ impl DynamicColor { } } +impl Default for DynamicColor { + fn default() -> Self { + Self::from_alpha_color(AlphaColor::::default()) + } +} + impl Hash for DynamicColor { /// The hash is computed from the bit representation of the component values. /// That makes it suitable for use as a cache key or memoization, but does not