"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 Views
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.Camera = void 0;
const core_bentley_1 = require("@itwin/core-bentley");
const core_geometry_1 = require("@itwin/core-geometry");
/** The current position (eyepoint), lens angle, and focus distance of a camera.
 * @see [Views]($docs/learning/frontend/Views.md)
 * @public
 */
class Camera {
    lens;
    focusDist;
    eye;
    static isValidLensAngle(val) {
        return val.radians > (Math.PI / 8.0) && val.radians < Math.PI;
    }
    static validateLensAngle(val) {
        if (!this.isValidLensAngle(val))
            val.setRadians(Math.PI / 2.0);
    }
    invalidateFocus() { this.focusDist = 0.0; }
    get isFocusValid() { return this.focusDist > 0.0 && this.focusDist < 1.0e14; }
    getFocusDistance() { return this.focusDist; }
    setFocusDistance(dist) { this.focusDist = dist; }
    get isLensValid() { return Camera.isValidLensAngle(this.lens); }
    validateLens() { Camera.validateLensAngle(this.lens); }
    getLensAngle() { return this.lens; }
    setLensAngle(angle) { this.lens.setFrom(angle); }
    getEyePoint() { return this.eye; }
    setEyePoint(pt) { this.eye.setFrom(pt); }
    get isValid() { return this.isLensValid && this.isFocusValid; }
    equals(other) {
        return Math.abs(this.lens.radians - other.lens.radians) < .01 &&
            Math.abs(this.focusDist - other.focusDist) < .1 &&
            this.eye.isAlmostEqual(other.eye);
    }
    clone() { return new Camera(this); }
    setFrom(rhs) {
        this.lens.setFrom(rhs.lens);
        this.focusDist = rhs.focusDist;
        this.eye.setFrom(rhs.eye);
    }
    /** Construct a Camera
     * @param props The properties of the new camera. If undefined, create a camera with eye at {0,0,0}, 90 degree lens, 1 meter focus distance.
     */
    constructor(props) {
        if (props !== undefined) {
            this.lens = core_geometry_1.Angle.fromJSON(props.lens);
            this.focusDist = core_bentley_1.JsonUtils.asDouble(props.focusDist);
            this.eye = core_geometry_1.Point3d.fromJSON(props.eye);
            return;
        }
        this.lens = core_geometry_1.Angle.createRadians(Math.PI / 2.0);
        this.focusDist = 1;
        this.eye = new core_geometry_1.Point3d();
    }
}
exports.Camera = Camera;
//# sourceMappingURL=Camera.js.map