lunar function

({double gamma, double jmax, double mag, double rho, double sdPartial, double sdPenumbral, double sdTotal, double sigma, int type}) lunar(
  1. double year
)

Lunar eclipse nearest decimal year.

Returns eclipse type, jmax, gamma, rho, sigma, magnitude, and semidurations (total, partial, penumbral) in days.

Implementation

({int type, double jmax, double gamma, double rho, double sigma, double mag,
    double sdTotal, double sdPartial, double sdPenumbral})
    lunar(double year) {
  final r = _g(_snap(year, 0.5), moonphase.meanFull(year), -0.4065, 0.1727);
  if (!r.eclipse) {
    return (type: none, jmax: 0, gamma: 0, rho: 0, sigma: 0, mag: 0,
        sdTotal: 0, sdPartial: 0, sdPenumbral: 0);
  }
  final rho = 1.2848 + r.u;
  final sigma = 0.7403 - r.u;
  final aGamma = r.gamma.abs();
  var mag = (1.0128 - r.u - aGamma) / 0.545;
  int eclType;
  if (mag > 1) {
    eclType = total;
  } else if (mag > 0) {
    eclType = umbral;
  } else {
    mag = (1.5573 + r.u - aGamma) / 0.545;
    if (mag < 0) {
      return (type: none, jmax: r.jmax, gamma: r.gamma, rho: rho, sigma: sigma,
          mag: 0, sdTotal: 0, sdPartial: 0, sdPenumbral: 0);
    }
    eclType = penumbral;
  }

  final p = 1.0128 - r.u;
  final t = 0.4678 - r.u;
  final n = 0.5458 + 0.04 * math.cos(r.mPrime);
  final g2 = r.gamma * r.gamma;
  final sdTotal = eclType == total
      ? math.sqrt(t * t - g2) / n / 24
      : 0.0;
  final sdPartial = (eclType == total || eclType == umbral)
      ? math.sqrt(p * p - g2) / n / 24
      : 0.0;
  final h = 1.5573 + r.u;
  final sdPenumbral = math.sqrt(h * h - g2) / n / 24;

  return (type: eclType, jmax: r.jmax, gamma: r.gamma, rho: rho, sigma: sigma,
      mag: mag, sdTotal: sdTotal, sdPartial: sdPartial, sdPenumbral: sdPenumbral);
}