/**
 * 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-16 12:59:38
 * Last modified  : 2018-11-28 16:45:48
 */
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 __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
/**
 * 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-02 19:16:51
 * Last modified  : 2018-10-16 12:51:01
 */
import * as THREE from 'three';
import ObjectsCommon from './ObjectsCommon';
import PrimitiveObject from './PrimitiveObject';
import isEqual from 'lodash.isequal';
var Prism = /** @class */ (function (_super) {
    __extends(Prism, _super);
    function Prism(parameters, operations, viewOptions, mesh) {
        if (operations === void 0) { operations = []; }
        if (viewOptions === void 0) { viewOptions = ObjectsCommon.createViewOptions(); }
        if (mesh === void 0) { mesh = undefined; }
        var _this = this;
        var vO = __assign({}, ObjectsCommon.createViewOptions(), viewOptions);
        _this = _super.call(this, vO, operations) || this;
        _this.type = Prism.typeName;
        _this.setParameters(parameters);
        _this.lastJSON = _this.toJSON();
        if (mesh) {
            _this.setMesh(mesh);
        }
        else {
            _this.meshPromise = _this.computeMeshAsync();
        }
        return _this;
    }
    Prism.newFromJSON = function (object) {
        if (object.type != Prism.typeName)
            throw new Error('Not Prism Object');
        return new Prism(object.parameters, object.operations, object.viewOptions);
    };
    Prism.prototype.clone = function () {
        if (isEqual(this.lastJSON, this.toJSON())) {
            var obj = new Prism(this.parameters, this.operations, this.viewOptions, this.mesh.clone());
            return obj;
        }
        else {
            var obj = new Prism(this.parameters, this.operations, this.viewOptions);
            return obj;
        }
    };
    Prism.prototype.getGeometry = function () {
        var _a = this.parameters, sides = _a.sides, length = _a.length, height = _a.height;
        sides = Math.max(3, sides);
        (length = Math.max(1, length)), (height = Math.max(1, height));
        this._meshUpdateRequired = false;
        var radius = length / (2 * Math.sin(Math.PI / sides));
        return new THREE.CylinderGeometry(Number(radius), Number(radius), Number(height), Number(sides)).rotateX(Math.PI / 2);
    };
    Prism.prototype.getBufferGeometry = function () {
        var _a = this.parameters, sides = _a.sides, length = _a.length, height = _a.height;
        sides = Math.max(3, sides);
        (length = Math.max(1, length)), (height = Math.max(1, height));
        this._meshUpdateRequired = false;
        var radius = length / (2 * Math.sin(Math.PI / sides));
        return new THREE.CylinderBufferGeometry(Number(radius), Number(radius), Number(height), Number(sides)).rotateX(Math.PI / 2);
    };
    Prism.typeName = 'Prism';
    return Prism;
}(PrimitiveObject));
export default Prism;
//# sourceMappingURL=Prism.js.map