fromAngle static method

MoonPhaseName fromAngle(
  1. double phaseAngle
)

Derives the phase name from a phase angle (radians, 0, 2π).

Convention used by MoonPainter: 0 = full moon, π = new moon.

Implementation

static MoonPhaseName fromAngle(double phaseAngle) {
  // Normalize to [0, 2π]
  double a = phaseAngle % (2 * pi);
  if (a < 0) a += 2 * pi;

  const eighth = pi / 8; // 22.5°

  if (a < eighth || a >= 15 * eighth) return MoonPhaseName.fullMoon;
  if (a < 3 * eighth) return MoonPhaseName.waningGibbous;
  if (a < 5 * eighth) return MoonPhaseName.lastQuarter;
  if (a < 7 * eighth) return MoonPhaseName.waningCrescent;
  if (a < 9 * eighth) return MoonPhaseName.newMoon;
  if (a < 11 * eighth) return MoonPhaseName.waxingCrescent;
  if (a < 13 * eighth) return MoonPhaseName.firstQuarter;
  return MoonPhaseName.waxingGibbous;
}