var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var _this = this;
import Cylinder from '../Cylinder';
import ObjectsCommon from '../ObjectsCommon';
import * as THREE from 'three';
var r0 = 10;
var height = 15;
var r1 = 20;
var objParams = {
    r0: r0,
    r1: r1,
    height: height,
};
var operations = [];
var viewOptions = ObjectsCommon.createViewOptions();
/// CONSTRUCTOR TESTS
test('Cylinder - Constructor', function () {
    var obj = new Cylinder(objParams, operations, viewOptions);
    expect(obj.parameters).toEqual(objParams);
    expect(obj.operations).toEqual(operations);
    expect(obj.viewOptions).toEqual(viewOptions);
    expect(obj.lastJSON).toEqual(obj.toJSON());
    return obj.meshPromise.then(function (mesh) {
        expect(mesh).toBeInstanceOf(THREE.Mesh);
        expect(mesh.geometry).toBeInstanceOf(THREE.CylinderGeometry);
        expect(mesh.position).toEqual({ x: 0, y: 0, z: 0 });
        expect(mesh.rotation.x).toBeCloseTo(0);
        expect(mesh.rotation.y).toBeCloseTo(0);
        expect(mesh.rotation.z).toBeCloseTo(0);
    });
});
test('Cylinder - Constructor - Default Params - ViewOptions', function () {
    var obj = new Cylinder(objParams, operations);
    expect(obj.parameters).toEqual(objParams);
    expect(obj.operations).toEqual(operations);
    expect(obj.viewOptions).toEqual(viewOptions);
    expect(obj.lastJSON).toEqual(obj.toJSON());
    return obj.meshPromise.then(function (mesh) {
        expect(mesh).toBeInstanceOf(THREE.Mesh);
        expect(mesh.geometry).toBeInstanceOf(THREE.CylinderGeometry);
        expect(mesh.position).toEqual({ x: 0, y: 0, z: 0 });
        expect(mesh.rotation.x).toBeCloseTo(0);
        expect(mesh.rotation.y).toBeCloseTo(0);
        expect(mesh.rotation.z).toBeCloseTo(0);
    });
});
test('Cylinder - Constructor - Default Params - Operations - ViewOptions', function () {
    var obj = new Cylinder(objParams, operations);
    expect(obj.parameters).toEqual(objParams);
    expect(obj.operations).toEqual(operations);
    expect(obj.viewOptions).toEqual(viewOptions);
    expect(obj.lastJSON).toEqual(obj.toJSON());
    return obj.meshPromise.then(function (mesh) {
        expect(mesh).toBeInstanceOf(THREE.Mesh);
        expect(mesh.geometry).toBeInstanceOf(THREE.CylinderGeometry);
        expect(mesh.position).toEqual({ x: 0, y: 0, z: 0 });
        expect(mesh.rotation.x).toBeCloseTo(0);
        expect(mesh.rotation.y).toBeCloseTo(0);
        expect(mesh.rotation.z).toBeCloseTo(0);
    });
});
test('Cylinder - Constructor - Set Operations - Translation', function () {
    var x = 10;
    var y = 20;
    var z = 30;
    var operations = [ObjectsCommon.createTranslateOperation(x, y, z)];
    var obj = new Cylinder(objParams, operations);
    expect(obj.operations).toEqual(operations);
    expect(obj.lastJSON).toEqual(obj.toJSON());
    return obj.meshPromise.then(function (mesh) {
        expect(mesh).toBeInstanceOf(THREE.Mesh);
        expect(mesh.position).toEqual({ x: x, y: y, z: z });
        expect(mesh.rotation.x).toBeCloseTo(0);
        expect(mesh.rotation.y).toBeCloseTo(0);
        expect(mesh.rotation.z).toBeCloseTo(0);
    });
});
test('Cylinder - Constructor - Set Operations - Rotation', function () {
    var xangle = 45;
    var yangle = 35;
    var zangle = 15;
    var operations = [
        ObjectsCommon.createRotateOperation(xangle, yangle, zangle),
    ];
    var obj = new Cylinder(objParams, operations);
    expect(obj.operations).toEqual(operations);
    expect(obj.lastJSON).toEqual(obj.toJSON());
    return obj.meshPromise.then(function (mesh) {
        expect(mesh).toBeInstanceOf(THREE.Mesh);
        expect(mesh.position).toEqual({ x: 0, y: 0, z: 0 });
        expect(mesh.rotation.x).toBeCloseTo((Math.PI * xangle) / 180);
        expect(mesh.rotation.y).toBeCloseTo((Math.PI * yangle) / 180);
        expect(mesh.rotation.z).toBeCloseTo((Math.PI * zangle) / 180);
    });
});
test('Cylinder - Constructor - set Mesh', function () { return __awaiter(_this, void 0, void 0, function () {
    var objAux, meshAux, obj;
    return __generator(this, function (_a) {
        switch (_a.label) {
            case 0:
                objAux = new Cylinder(objParams);
                return [4 /*yield*/, objAux.getMeshAsync()];
            case 1:
                meshAux = _a.sent();
                obj = new Cylinder(objParams, operations, viewOptions, meshAux);
                return [2 /*return*/, obj.getMeshAsync().then(function (mesh) {
                        expect(mesh).toBe(meshAux);
                    })];
        }
    });
}); });
/// END TESTING CONSTRUCTOR
/// TESTING CUBE.CLONE
test('Cylinder - Clone - Parameters - Operations - viewOptions', function () { return __awaiter(_this, void 0, void 0, function () {
    var obj, spy, obj2, obj3;
    return __generator(this, function (_a) {
        obj = new Cylinder(objParams, operations, viewOptions);
        spy = jest.spyOn(obj.mesh, 'clone');
        obj2 = obj.clone();
        expect(obj.parameters).toEqual(obj2.parameters);
        expect(obj.operations).toEqual(obj2.operations);
        expect(obj.viewOptions).toEqual(obj2.viewOptions);
        // mesh clone should be called on this instance because obj has NOT been changed
        expect(spy).toBeCalledTimes(1);
        obj.operations = [ObjectsCommon.createTranslateOperation(0, 0, 0)];
        obj3 = obj.clone();
        // mesh clone should not be called on this instance because obj has been changed
        expect(spy).toBeCalledTimes(1);
        return [2 /*return*/];
    });
}); });
/// TEST NEW FROM JSON
test('Cylinder - newFromJSON', function () { return __awaiter(_this, void 0, void 0, function () {
    var obj, json, obj2;
    return __generator(this, function (_a) {
        obj = new Cylinder(objParams, operations, viewOptions);
        json = obj.toJSON();
        obj2 = Cylinder.newFromJSON(json);
        expect(obj.parameters).toEqual(obj2.parameters);
        expect(obj.operations).toEqual(obj2.operations);
        expect(obj.viewOptions).toEqual(obj2.viewOptions);
        return [2 /*return*/];
    });
}); });
//# sourceMappingURL=Cylinder.test.js.map