import { magvar } from "magvar";

Number.prototype.toRadians = function () {
  return ((this as number) * Math.PI) / 180;
};
Number.prototype.toDegrees = function () {
  return ((this as number) * 180) / Math.PI;
};
Number.prototype.reciprocalCourse = function () {
  let inv = (this as number) + 180;
  inv = inv >= 360 ? inv - 360 : inv;
  return inv;
};
Number.prototype.normaliseDegrees = function () {
  return (this as number) >= 360
    ? (this as number) - 360
    : (this as number) < 0
    ? (this as number) + 360
    : (this as number);
};
Number.prototype.toTrue = function (fix) {
  const _magvar = magvar(fix.latitude, fix.longitude); //Magvar is returned + for East
  return ((this as number) + _magvar).normaliseDegrees();
};
Number.prototype.toMetre = function () {
  return (this as number) * 1852.0;
};

String.prototype.parseAltitude = function () {
  return Number.parseInt(this.substring(0, 5));
};
