/**
 * Copyright (c) 2018 Bitbloq (BQ)
 *
 * License: MIT
 *
 * long description for the file
 *
 * @summary short description for the file
 * @author David García <https://github.com/empoalp>, Alberto Valero <https://github.com/avalero>
 *
 * Created at     : 2018-10-05 20:26:49
 * Last modified  : 2018-11-14 08:46:30
 */
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    }
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var SphericalCoords = /** @class */ (function () {
    function SphericalCoords(r, phi, theta) {
        if (r === void 0) { r = 0; }
        if (phi === void 0) { phi = 0; }
        if (theta === void 0) { theta = 0; }
        this.radius = r;
        this.phi = phi;
        this.theta = theta;
    }
    Object.defineProperty(SphericalCoords.prototype, "sphericalGrads", {
        get: function () {
            var rads = this.spherical;
            return {
                radius: rads.radius,
                phi: (rads.phi * 180) / Math.PI,
                theta: (rads.theta * 180) / Math.PI,
            };
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SphericalCoords.prototype, "spherical", {
        get: function () {
            return { radius: this.radius, phi: this.phi, theta: this.theta };
        },
        enumerable: true,
        configurable: true
    });
    SphericalCoords.prototype.set = function (radius, phi, theta) {
        this.radius = radius;
        this.phi = phi;
        this.theta = theta;
        return this;
    };
    SphericalCoords.prototype.clone = function () {
        return this.copy(this);
    };
    SphericalCoords.prototype.copy = function (other) {
        this.radius = other.radius;
        this.phi = other.phi;
        this.theta = other.theta;
        return this;
    };
    SphericalCoords.prototype.makeSafe = function () {
        var EPS = 0.000001;
        this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
        return this;
    };
    SphericalCoords.prototype.setFromCartesianCoords = function (x, y, z) {
        throw Error('Error: No implemented in parent');
        return this;
    };
    SphericalCoords.prototype.setFromVector3 = function (v) {
        return this.setFromCartesianCoords(v.x, v.y, v.z);
    };
    return SphericalCoords;
}());
/* The polar angle (phi) is measured from the positive z-axis. The positive z-axis is up.
 * The azimuthal angle (theta) is measured from the positive x-axis.
 */
var SphericalCoordsXYZ = /** @class */ (function (_super) {
    __extends(SphericalCoordsXYZ, _super);
    function SphericalCoordsXYZ(r, phi, theta) {
        if (r === void 0) { r = 0; }
        if (phi === void 0) { phi = 0; }
        if (theta === void 0) { theta = 0; }
        return _super.call(this, r, phi, theta) || this;
    }
    SphericalCoordsXYZ.toCartesian = function (r, phi, theta) {
        var r_sinphi = r * Math.sin(phi);
        var x = Math.cos(theta) * r_sinphi;
        var y = Math.sin(theta) * r_sinphi;
        var z = r * Math.cos(phi);
        return { x: x, y: y, z: z };
    };
    Object.defineProperty(SphericalCoordsXYZ.prototype, "cartesian", {
        get: function () {
            return SphericalCoordsXYZ.toCartesian(this.radius, this.phi, this.theta);
        },
        enumerable: true,
        configurable: true
    });
    SphericalCoordsXYZ.prototype.setFromCartesianCoords = function (x, y, z) {
        this.radius = Math.sqrt(x * x + y * y + z * z);
        this.theta =
            x !== 0 ? Math.atan(y / x) : y > 0 ? Math.PI / 2 : -Math.PI / 2;
        this.phi = Math.acos(z / this.radius);
        return this;
    };
    return SphericalCoordsXYZ;
}(SphericalCoords));
export { SphericalCoordsXYZ };
//# sourceMappingURL=SphericalCoordinates.js.map