UNPKG

gs-json

Version:

gs-JSON is a domain agnostic unifying 3D file format for geometric and semantic modelling (hence the 'gs').

119 lines (98 loc) 5.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Plane = undefined; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _entity_obj = require("./entity_obj"); var _entity_point = require("./entity_point"); var _threex = require("./libs/threex/threex"); var threex = _interopRequireWildcard(_threex); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** * Class Plane. * A plane is displayed as two wires showing x and y axes. TODO * The wire has two vertices, the square face has four vertices. * A ray may be part of a group and may have attributes. */ var Plane = exports.Plane = function (_Obj) { _inherits(Plane, _Obj); function Plane() { _classCallCheck(this, Plane); return _possibleConstructorReturn(this, (Plane.__proto__ || Object.getPrototypeOf(Plane)).apply(this, arguments)); } _createClass(Plane, [{ key: "getObjType", /** * Get the object type: "plane". * @return Plane object type. */ value: function getObjType() { return 2 /* plane */; } /** * Get the origin of the plane. * @return Plane object type. */ }, { key: "getOrigin", value: function getOrigin() { return new _entity_point.Point(this._kernel, this._kernel.objGetOnePoint(this._id)); } /** * Get the x and y vectors of the plane. * @return Plane object type. */ }, { key: "getAxes", value: function getAxes() { var params = this._kernel.objGetParams(this._id); return [params[1], params[2], params[3]]; } /** * Returns the x and y vectors of this curve. The length of the x vector defines the radius of the circle. * @return The x and y vectors. */ }, { key: "getNormal", value: function getNormal() { return this._kernel.objGetParams(this._id)[3]; } /** * Sets the x and y vectors of this curve. The length of the x vector defines the radius of the circle. * @param x_vec Vector, the x axis * @param vec vector, in the plane */ }, { key: "setOrientation", value: function setOrientation(x_vec, vec) { // param are [type, x_vec, y_vec, z_vec, angles] var vecs = threex.makeXYZOrthogonal(x_vec, vec, false); var params = this._kernel.objGetParams(this._id); params[1] = vecs[0]; params[2] = vecs[1]; params[3] = vecs[2]; } /** * Get the 4 cartesian coefficient of a plan, especially usefull for distance calculations. * In 3 dimensions, a cartesian equation of a 2D plan is: a.x + b.y + c.z + d = 0 ; * @return Returns an array that contains the x, y, z coordinates of a point which belongs to * the plan as well as a normal vector * @return Array of real numbers: [a,b,c,d] (where a,b,c is a triplet set such as (a,b,c) !=== (0,0,0)) */ }, { key: "getCartesians", value: function getCartesians() { var origin_id = this._kernel.objGetOnePoint(this._id); var origin_xyz = this._kernel.pointGetPosition(origin_id); var z_vec = this._kernel.objGetParams(this._id)[3]; var d = -(origin_xyz[0] * z_vec[0] + origin_xyz[1] * z_vec[1] + origin_xyz[2] * z_vec[2]); return [z_vec[0], z_vec[1], z_vec[2], d]; } }]); return Plane; }(_entity_obj.Obj); //# sourceMappingURL=entity_obj_plane.js.map