detAtan2Deg function

double detAtan2Deg(
  1. double y,
  2. double x
)

atan2(y, x) in degrees, in [0, 360) (0 when both are 0). Deterministic; used to read a colour's OKLCH hue (e.g. for names).

Implementation

double detAtan2Deg(double y, double x) {
  if (x == 0 && y == 0) return 0;
  final ax = x < 0 ? -x : x;
  final ay = y < 0 ? -y : y;
  // Angle in the first octant pair, radians.
  final a = ay <= ax ? _atanUnit(ay / ax) : detPi / 2 - _atanUnit(ax / ay);
  var r = a;
  if (x < 0) r = detPi - r;
  if (y < 0) r = -r;
  var deg = r * (180.0 / detPi);
  if (deg < 0) deg += 360.0;
  if (deg >= 360.0) deg -= 360.0;
  return deg;
}