import * as validate from '@mmit/validate';
import { degToRadian, decimal2sexagesimal, round } from './convert.js';

// tslint:disable-next-line:no-any
function isLatLng(object) {
    return typeof object === 'object' && object instanceof LatLng;
}
/**
 * Coordinates in Degrees
 *
 *      const latlng = new LatLng(10.000002,12.00001);
 */
class LatLng {
    _latitude;
    _longitude;
    constructor(latitude, longitude) {
        validate.inclusiveBetween(latitude, -90.0, 90.0, () => `"Latitude must be between -90 and 90 degrees but was ${latitude}"`);
        validate.inclusiveBetween(longitude, -180.0, 180.0, () => `"Longitude must be between -180 and 180 degrees but was ${latitude}"`);
        this._latitude = latitude;
        this._longitude = longitude;
    }
    set latitude(value) {
        validate.inclusiveBetween(value, -90.0, 90.0, () => `"Latitude must be between -90 and 90 degrees but was ${value}"`);
        this._latitude = value;
    }
    get latitude() {
        return this._latitude;
    }
    set longitude(value) {
        validate.inclusiveBetween(value, -180.0, 180.0, () => `"Longitude must be between -180 and 180 degrees but was ${value}"`);
        this._longitude = value;
    }
    get longitude() {
        return this._longitude;
    }
    /**
     * Konvertiert in Google-Maps Koordinaten (Benennung)
     */
    toGMaps() {
        return { lat: this.latitude, lng: this.longitude };
    }
    get latitudeInRad() {
        return degToRadian(this.latitude);
    }
    get longitudeInRad() {
        return degToRadian(this.longitude);
    }
    toString() {
        return (`LatLng(latitude:${this.latitude.toFixed(6)}, ` +
            `longitude:${this.longitude.toFixed(6)})`);
    }
    /**
     * Converts lat/long values into sexagesimal
     *
     *     final LatLng p1 = new LatLng(51.519475, -19.37555556);
     *
     *     // Shows: 51° 31' 10.11" N, 19° 22' 32.00" W
     *     print(p1..toSexagesimal());
     */
    toSexagesimal() {
        const latDirection = this.latitude >= 0 ? 'N' : 'S';
        const lonDirection = this.longitude >= 0 ? 'O' : 'W';
        return `${decimal2sexagesimal(this.latitude)} ${latDirection}, ${decimal2sexagesimal(this.longitude)} ${lonDirection}`;
    }
    round({ decimals } = { decimals: 6 }) {
        return new LatLng(round(this.latitude, { decimals }), round(this.longitude, { decimals }));
    }
    isEqual(other) {
        if (isLatLng(other)) {
            return this.latitude === other.latitude && this.longitude === other.longitude;
        }
        return false;
    }
    isNotEqual(other) {
        return !this.isEqual(other);
    }
}

export { LatLng, isLatLng };
//# sourceMappingURL=LatLng.js.map
