aest 0.1.0
Collection of C++ utility libraries
Loading...
Searching...
No Matches
aest::colors::ColorArithmetic< Derived > Struct Template Referenceexport

Mixin adding channel-wise arithmetic operators to a color type. More...

Private Member Functions

constexpr Derived & self () noexcept
 Access this object as the derived color type.

Arithmetic operators

constexpr Derived operator+ (const Derived &lhs, const Derived &rhs) noexcept
 Adds two colors together, channel by channel.
constexpr Derived operator- (const Derived &lhs, const Derived &rhs) noexcept
 Subtracts a color from another, channel by channel.
constexpr Derived operator* (const Derived &lhs, const Derived &rhs) noexcept
 Multiplies two colors, channel by channel.
constexpr Derived & operator+= (const Derived &other) noexcept
 Adds another color to this color in place.
constexpr Derived & operator-= (const Derived &other) noexcept
 Subtracts another color from this color in place.
constexpr Derived & operator*= (const Derived &other) noexcept
 Multiplies this color by another color in place.

Scalar operators

constexpr Derived operator* (const Derived &color, const float scalar) noexcept
 Scales the color channels of a color, keeping its alpha.
constexpr Derived operator* (const float scalar, const Derived &color) noexcept
 Scales the color channels of a color, keeping its alpha.
constexpr Derived operator/ (const Derived &color, const float scalar) noexcept
 Divides the color channels of a color, keeping its alpha.
constexpr Derived & operator*= (const float scalar) noexcept
 Scales the color channels of this color in place, keeping its alpha.
constexpr Derived & operator/= (const float scalar) noexcept
 Divides the color channels of this color in place, keeping its alpha.

Detailed Description

template<typename Derived>
struct aest::colors::ColorArithmetic< Derived >

Mixin adding channel-wise arithmetic operators to a color type.

Inherit it only in color spaces where adding and multiplying channel values is meaningful, such as LinSRGB. Every operator combines both operands on all four channels, alpha included: two half-transparent colors add up to an opaque one, and a - a is fully transparent. The results are built through the derived type's (ch1, ch2, ch3, alpha) constructor, so they are clamped like any other value of that type: LinSRGB channels stop at 0 but not at 1, and alpha stays in the 0-1 range.

The scalar operators are the exception: color * s and color / s scale the light, the three color channels, and keep alpha, as exposure or a light's intensity would.

Template Parameters
DerivedThe derived color class

Definition at line 250 of file Color.cppm.

Member Function Documentation

◆ operator*=() [1/2]

template<typename Derived>
Derived & aest::colors::ColorArithmetic< Derived >::operator*= ( const Derived & other)
inlineconstexprnoexcept

Multiplies this color by another color in place.

Parameters
[in]otherThe color to multiply by.
Returns
Reference to this color after modification.

Definition at line 309 of file Color.cppm.

◆ operator*=() [2/2]

template<typename Derived>
Derived & aest::colors::ColorArithmetic< Derived >::operator*= ( const float scalar)
inlineconstexprnoexcept

Scales the color channels of this color in place, keeping its alpha.

Parameters
[in]scalarThe factor applied to each color channel.
Returns
Reference to this color after modification.
Precondition
scalar is finite.

Definition at line 358 of file Color.cppm.

◆ operator+=()

template<typename Derived>
Derived & aest::colors::ColorArithmetic< Derived >::operator+= ( const Derived & other)
inlineconstexprnoexcept

Adds another color to this color in place.

Parameters
[in]otherThe color to add.
Returns
Reference to this color after modification.

Definition at line 295 of file Color.cppm.

◆ operator-=()

template<typename Derived>
Derived & aest::colors::ColorArithmetic< Derived >::operator-= ( const Derived & other)
inlineconstexprnoexcept

Subtracts another color from this color in place.

Parameters
[in]otherThe color to subtract.
Returns
Reference to this color after modification.

Definition at line 302 of file Color.cppm.

◆ operator/=()

template<typename Derived>
Derived & aest::colors::ColorArithmetic< Derived >::operator/= ( const float scalar)
inlineconstexprnoexcept

Divides the color channels of this color in place, keeping its alpha.

Parameters
[in]scalarThe divisor of each color channel.
Returns
Reference to this color after modification.
Precondition
scalar is finite and not 0.

Definition at line 366 of file Color.cppm.

◆ self()

template<typename Derived>
Derived & aest::colors::ColorArithmetic< Derived >::self ( )
inlineconstexprprivatenoexcept

Access this object as the derived color type.

Returns
Reference to the derived color.

Definition at line 374 of file Color.cppm.

◆ operator* [1/3]

template<typename Derived>
Derived operator* ( const Derived & color,
const float scalar )
friend

Scales the color channels of a color, keeping its alpha.

Parameters
[in]colorThe color to scale.
[in]scalarThe factor applied to each color channel.
Returns
A new Color with the scaled channels and the alpha of color.
Precondition
scalar is finite.

Definition at line 321 of file Color.cppm.

◆ operator* [2/3]

template<typename Derived>
Derived operator* ( const Derived & lhs,
const Derived & rhs )
friend

Multiplies two colors, channel by channel.

Parameters
[in]lhsThe left-hand color.
[in]rhsThe right-hand color.
Returns
A new Color containing the component-wise product.

Definition at line 284 of file Color.cppm.

◆ operator* [3/3]

template<typename Derived>
Derived operator* ( const float scalar,
const Derived & color )
friend

Scales the color channels of a color, keeping its alpha.

Parameters
[in]scalarThe factor applied to each color channel.
[in]colorThe color to scale.
Returns
A new Color with the scaled channels and the alpha of color.
Precondition
scalar is finite.

Definition at line 334 of file Color.cppm.

◆ operator+

template<typename Derived>
Derived operator+ ( const Derived & lhs,
const Derived & rhs )
friend

Adds two colors together, channel by channel.

Parameters
[in]lhsThe left-hand color.
[in]rhsThe right-hand color.
Returns
A new Color containing the component-wise sum.

Definition at line 260 of file Color.cppm.

◆ operator-

template<typename Derived>
Derived operator- ( const Derived & lhs,
const Derived & rhs )
friend

Subtracts a color from another, channel by channel.

Parameters
[in]lhsThe color to subtract from.
[in]rhsThe color to subtract.
Returns
A new Color containing the component-wise difference.

Definition at line 272 of file Color.cppm.

◆ operator/

template<typename Derived>
Derived operator/ ( const Derived & color,
const float scalar )
friend

Divides the color channels of a color, keeping its alpha.

Parameters
[in]colorThe color to divide.
[in]scalarThe divisor of each color channel.
Returns
A new Color with the divided channels and the alpha of color.
Precondition
scalar is finite and not 0.

Definition at line 346 of file Color.cppm.


The documentation for this struct was generated from the following file: