operator < method

bool operator <(
  1. Color other
)

Color Less Than Operator

Returns true if this Color is "darker" than other according to method computeLuminance.

bool operator <(Color other) => computeLuminance() < other.computeLuminance();

computeLuminance:

"Returns a brightness value between 0 for darkest and 1 for lightest. Represents the relative luminance of the color.
This value is computationally expensive to calculate. *See https://en.wikipedia.org/wiki/Relative_luminance.*"

Nitty Gritty

To compute luminance of a color, each component (first divided by 255 or 0xFF) is linearized as such:

if (component <= 0.03928)
  return component / 12.92;
return math.pow((component + 0.055) / 1.055, 2.4) as double;

Then each component contributes itself as a different percentage of the output luminance as such:

return 0.2126 * R + 0.7152 * G + 0.0722 * B;

Implementation

// ignore: lines_longer_than_80_chars
///     bool operator <(Color other) => computeLuminance() < other.computeLuminance();
///
/// ### [computeLuminance]:
/// "Returns a brightness value between 0 for darkest and 1 for lightest.
/// Represents the relative luminance of the color. \
/// **This value is computationally expensive to calculate.**
/// *See https://en.wikipedia.org/wiki/Relative_luminance.*"
///
/// ### Nitty Gritty
/// To compute luminance of a color, each component (first divided by `255`
/// or `0xFF`) is linearized as such:
///
///     if (component <= 0.03928)
///       return component / 12.92;
///     return math.pow((component + 0.055) / 1.055, 2.4) as double;
///
/// Then each component contributes itself as a different percentage of the
/// output luminance as such:
///
///     return 0.2126 * R + 0.7152 * G + 0.0722 * B;
bool operator <(Color other) => computeLuminance() < other.computeLuminance();