convertPlaneAngle function Null safety

double convertPlaneAngle(
  1. PlaneAngle from,
  2. PlaneAngle to,
  3. double value
)

Convert Plane Angle. It may lose some decimals in the proccess.

from, to and value can NOT be null, otherwise an AssertionError is thrown

Basic usage:

main() {
  final angle = convertPlaneAngle(
    PlaneAngle.degree, // from
    PlaneAngle.minuteOfArc, // to
    1, // value
  );
  print(angle); // 60
}

Read the documentation for more information

Implementation

double convertPlaneAngle(PlaneAngle from, PlaneAngle to, double value) {
  verify(from, to, value);
  if (from == to) return value;
  if (from == PlaneAngle.degree) {
    switch (to) {
      case PlaneAngle.gradian:
        return value * 200 / 180;
      case PlaneAngle.milliradian:
        return value * (1000 * pi) / 180;
      case PlaneAngle.radian:
        return value * 60;
      case PlaneAngle.minuteOfArc:
        return value * (pi / 180);
      case PlaneAngle.secondOfArc:
        return value * 3600;
      default:
        return value;
    }
  } else {
    final degree = PlaneAngle.degree;
    switch (from) {
      case PlaneAngle.gradian:
        return convertPlaneAngle(degree, to, value * 200 / 180);
      case PlaneAngle.milliradian:
        return convertPlaneAngle(degree, to, value * (1000 * pi) / 180);
      case PlaneAngle.radian:
        return convertPlaneAngle(degree, to, value * 60);
      case PlaneAngle.minuteOfArc:
        return convertPlaneAngle(degree, to, value * (pi / 180));
      case PlaneAngle.secondOfArc:
        return convertPlaneAngle(degree, to, value * 3600);
      default:
        return value;
    }
  }
}