deltaLongitudeAbs function Null safety

double deltaLongitudeAbs(
  1. double longADeg,
  2. double longBDeg
)

Returns the shortest longitude angle distance (in degrees) between two points A and B with longitudes given by longADeg respectively longBDeg, both in degrees.

The result is always positive, in the range of 0..180 (both inclusive).

Implementation

double deltaLongitudeAbs(double longADeg, double longBDeg) {
  // Longitude calculations require a bit of care as it's expressed in the
  // range -180..180, so LongA=-179 and LongB=179 is just 2 degrees difference,
  // not 358 degrees.
  var diffLongDeg = (longADeg - longBDeg).abs();
  return diffLongDeg <= 180 ? diffLongDeg : 360 - diffLongDeg;
}