findMaxChromaPoint static method

List<double> findMaxChromaPoint(
  1. double a,
  2. double b
)

Finds the point of maximum chroma for a given hue direction in Oklab space.

The maximum chroma point (cusp) represents the point of maximum colorfulness for a given hue direction in the sRGB gamut. This is fundamental for determining valid color boundaries.

Based on Björn Ottosson's gamut clipping algorithm.

Reference: Björn Ottosson - "Gamut clipping" https://bottosson.github.io/posts/gamutclipping/

Parameters:

  • a: The a-axis component (normalized, from cos(hue))
  • b: The b-axis component (normalized, from sin(hue))

Returns: lightness, chroma coordinates of the maximum chroma point

Implementation

static List<double> findMaxChromaPoint(double a, double b) {
  // Check intersections with RGB cube boundaries (0,0,0) to (1,1,1)
  final intersections = <List<double>>[];

  // Check each RGB plane boundary (R=0, R=1, G=0, G=1, B=0, B=1)
  for (int plane = 0; plane < 6; plane++) {
    final intersection = _intersectGamutBoundary(a, b, plane);
    if (intersection != null) {
      intersections.add(intersection);
    }
  }

  // Find the intersection with maximum chroma
  double maxChroma = 0.0;
  double maxL = 0.0;

  for (final intersection in intersections) {
    final intersectionL = intersection[0];
    final intersectionC = intersection[1];

    if (intersectionC > maxChroma &&
        intersectionL >= 0.0 &&
        intersectionL <= 1.0) {
      maxChroma = intersectionC;
      maxL = intersectionL;
    }
  }

  return [maxL, maxChroma];
}