"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module CartesianGeometry
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.LongitudeLatitudeNumber = void 0;
const Geometry_1 = require("../Geometry");
const Angle_1 = require("./Angle");
/**
 * An `AngleAngleNumber` is a pair of angles (named `longitude` and `latitude`) and an additional number.
 * * This is directly intended to support `Ellipsoid` computations, with the two angles used as
 *    * `longitude` is "around the equator"
 *    * `latitude` is "equator to pole"
 *    * `h` is altitude above the `Ellipsoid surface.
 * * The structure may also be used for torus coordinates.
 * @public
 */
class LongitudeLatitudeNumber {
    _longitude;
    _latitude;
    _altitude;
    /** (property getter) longitude in radians */
    get longitudeRadians() { return this._longitude.radians; }
    /** (property getter) longitude in degrees */
    get longitudeDegrees() { return this._longitude.degrees; }
    /** (property getter) (reference to) longitude as a strongly typed `Angle` */
    get longitudeRef() { return this._longitude; }
    /** (property getter) (clone of)  longitude as a strongly typed `Angle` */
    get longitude() { return this._longitude.clone(); }
    /** (property getter) latitude in radians */
    get latitudeRadians() { return this._latitude.radians; }
    /** (property getter) latitude in degrees */
    get latitudeDegrees() { return this._latitude.degrees; }
    /** (property getter) (reference to) latitude as a strongly typed `Angle` */
    get latitudeRef() { return this._latitude; }
    /** (property getter) (clone of)  latitude as a strongly typed `Angle` */
    get latitude() { return this._latitude.clone(); }
    /** Get or set the altitude. */
    get altitude() { return this._altitude; }
    set altitude(value) { this._altitude = value; }
    /** Constructor: Capture angles and altitude */
    constructor(longitude, latitude, altitude) {
        this._longitude = longitude;
        this._latitude = latitude;
        this._altitude = altitude;
    }
    /** Create with all zero angles and altitude. */
    static createZero() { return new LongitudeLatitudeNumber(Angle_1.Angle.createDegrees(0), Angle_1.Angle.createDegrees(0), 0); }
    /** Create with strongly typed `Angle` inputs */
    static create(longitude, latitude, h = 0, result) {
        if (result) {
            result._latitude.setFrom(latitude);
            result._longitude.setFrom(longitude);
            result._altitude = h;
            return result;
        }
        return new LongitudeLatitudeNumber(longitude.clone(), latitude.clone(), h);
    }
    /** Create with angles in radians. */
    static createRadians(longitudeRadians, latitudeRadians, h = 0, result) {
        if (result) {
            result._longitude.setRadians(longitudeRadians);
            result._latitude.setRadians(latitudeRadians);
            result._altitude = h;
            return result;
        }
        return new LongitudeLatitudeNumber(Angle_1.Angle.createRadians(longitudeRadians), Angle_1.Angle.createRadians(latitudeRadians), h);
    }
    /** Create with angles in degrees. */
    static createDegrees(longitudeDegrees, latitudeDegrees, h = 0, result) {
        if (result) {
            result._longitude.setRadians(longitudeDegrees);
            result._latitude.setRadians(latitudeDegrees);
            result._altitude = h;
            return result;
        }
        return new LongitudeLatitudeNumber(Angle_1.Angle.createDegrees(longitudeDegrees), Angle_1.Angle.createDegrees(latitudeDegrees), h);
    }
    /**
     * Set content from a JSON object.
     * If the json object is undefined or unrecognized, always set a default value.
     *
     */
    setFromJSON(json) {
        if (json.latitude !== undefined) {
            this._latitude.setFromJSON(json.latitude);
        }
        else {
            this._latitude.setDegrees(0);
        }
        if (json.longitude !== undefined) {
            this._longitude.setFromJSON(json.longitude);
        }
        else {
            this._longitude.setDegrees(0);
        }
        if (json.h !== undefined && Number.isFinite(json.h)) {
            this._altitude = json.h;
        }
        else {
            this._altitude = 0;
        }
    }
    /** Return a json object with this object's contents.
     * * Tag names are: longitude, latitude, h
     */
    toJSON() {
        return { latitude: this._latitude.toJSON(), longitude: this._longitude.toJSON(), h: this._altitude };
    }
    /** Test for near equality */
    isAlmostEqual(other) {
        return this._latitude.isAlmostEqual(other._latitude)
            && this._longitude.isAlmostEqual(other._longitude)
            && Geometry_1.Geometry.isSameCoordinate(this._altitude, other._altitude);
    }
    /** Return a copy */
    clone() {
        return new LongitudeLatitudeNumber(this._longitude.clone(), this._latitude.clone(), this._altitude);
    }
}
exports.LongitudeLatitudeNumber = LongitudeLatitudeNumber;
//# sourceMappingURL=LongitudeLatitudeAltitude.js.map