clayEqualsHue function

int clayEqualsHue(
  1. int hue,
  2. int opHue, {
  3. int? pivot,
  4. int? nightBodyHue,
})

The full = hue rule after the scheme draw: the candy band (clayEqualsBand, leaving on the side of pivot, or the other side when that lands within clayEqualsOpGap of opHue), the dull band (clayEqualsDullHue) and grape for a red = beside a green operator (clayGrapeEquals). Pure integer tenths.

Implementation

int clayEqualsHue(int hue, int opHue, {int? pivot, int? nightBodyHue}) {
  int candyFrom(int p) => clayCandyHue(
    hue,
    clayEqualsBand,
    clayEqualsTargets,
    p,
    maxPush: clayEqualsPush,
  );
  var candy = candyFrom(pivot ?? _wrap(hue));
  if (clayEqualsBand.contains(_wrap(hue)) &&
      _hueDistance(candy, opHue) < clayEqualsOpGap) {
    // Leaving on that side would land beside the operator: the other.
    final (lo, hi) = clayEqualsTargets;
    candy = candyFrom(
      _hueDistance(candy, lo) < _hueDistance(candy, hi) ? hi : lo,
    );
  }
  final h = clayEqualsDullHue(candy, opHue, nightBodyHue: nightBodyHue);
  final red = _wrap(h - clayRedEqualsBand.lo);
  final span = clayRedEqualsBand.hi - clayRedEqualsBand.lo;
  if (clayGreenOperatorBand.contains(_wrap(opHue)) && red <= span) {
    return _spread(clayGrapeEquals, red, span);
  }
  return h;
}