getBounds static method

List<Line> getBounds(
  1. double L
)

For a given lightness, return a list of 6 lines in slope-intercept form that represent the bounds in CIELUV, stepping over which will push a value out of the RGB gamut

Implementation

static List<Line> getBounds(double L) {
  List<Line> result = [];

  double sub1 = math.pow(L + 16, 3) / 1560896;
  double sub2 = sub1 > epsilon ? sub1 : L / kappa;

  for (int c = 0; c < 3; c++) {
    double m1 = m[c][0];
    double m2 = m[c][1];
    double m3 = m[c][2];

    for (int t = 0; t < 2; t++) {
      double top1 = (284517 * m1 - 94839 * m3) * sub2;
      double top2 = (838422 * m3 + 769860 * m2 + 731718 * m1) * L * sub2 -
          769860 * t * L;
      double bottom = (632260 * m3 - 126452 * m2) * sub2 + 126452 * t;

      result.add(Line(
        slope: top1 / bottom,
        intercept: top2 / bottom,
      ));
    }
  }

  return result;
}