clayNightSphereHue function
The night sphere hue rule after the candy rule: red-orange / amber
(clayNightSphereWarmBand) turns berry; green, teal and cyan
(clayNightSphereJewelBand) take the first jewel of
clayNightSphereJewels at least clayNightSphereBodyGap from
bodyHue and (given other, the other sphere's hue)
clayNightSphereGap from it — else the jewel that misses those gaps
by the least. Pure integer tenths.
Implementation
int clayNightSphereHue(int hue, int bodyHue, {int? other}) {
var h = _wrap(hue);
const warm = clayNightSphereWarmBand;
if (warm.contains(h)) h = clayNightSphereWarmTarget - (h - warm.lo) ~/ 5;
const band = clayNightSphereJewelBand;
if (!band.contains(h)) return h;
final depth = h - band.lo;
final span = band.hi - band.lo;
var best = -1;
var bestMargin = -3600;
for (final jewel in clayNightSphereJewels) {
final t = _spread(jewel, depth, span);
final bodyMargin = _hueDistance(t, bodyHue) - clayNightSphereBodyGap;
final otherMargin = other == null
? bodyMargin
: _hueDistance(t, other) - clayNightSphereGap;
final margin = bodyMargin < otherMargin ? bodyMargin : otherMargin;
if (margin >= 0) return t;
if (margin > bestMargin) {
best = t;
bestMargin = margin;
}
}
return best;
}