UNPKG

gs-json

Version:

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

215 lines (182 loc) 7.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Circle = 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); var _conics = require("./libs/conics/conics"); var math_conics = _interopRequireWildcard(_conics); var _utils = require("./_utils"); var util = _interopRequireWildcard(_utils); 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 Circle. */ var Circle = exports.Circle = function (_Obj) { _inherits(Circle, _Obj); function Circle() { _classCallCheck(this, Circle); return _possibleConstructorReturn(this, (Circle.__proto__ || Object.getPrototypeOf(Circle)).apply(this, arguments)); } _createClass(Circle, [{ key: "getObjType", /** * Get the object type: "circle". * @return Circle object. */ value: function getObjType() { return 3 /* circle */; } /** * Get the origin of the ellipse. * @return Point object. */ }, { key: "getOrigin", value: function getOrigin() { return new _entity_point.Point(this._kernel, this._kernel.objGetOnePoint(this._id)); } /** * Returns the x and y vectors of this curve. The length of the x vector defines the radius of the circle. * @return An array of three XYZ vectors. */ }, { 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 XYZ vector */ }, { 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 XYZ vector, the x axis * @param vec XYZ 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]; } /** * Returns the Alpha and Beta angles of this curve. * @return The Alpha and Beta angles. */ }, { key: "getAngles", value: function getAngles() { return this._kernel.objGetParams(this._id)[4]; } /** * Returns the Alpha and Beta angles of this curve. * @return The Alpha and Beta angles. */ }, { key: "setAngles", value: function setAngles(angles) { // make sure the angles are ok angles = util.checkCircleAngles(angles); this._kernel.objGetParams(this._id)[4] = angles; } /** * Returns the radius of this circle (the length of the x vector). * @return Tthe radius. */ }, { key: "getRadius", value: function getRadius() { return threex.lengthXYZ(this._kernel.objGetParams(this._id)[1]); } /** * Set the radius of this circle (the length of the x vector). * @return The old radius. */ }, { key: "setRadius", value: function setRadius(radius) { var x_vec = this._kernel.objGetParams(this._id)[3]; var old_radius = threex.lengthXYZ(x_vec); this._kernel.objGetParams(this._id)[3] = threex.setLengthXYZ(x_vec, radius); return old_radius; } /** * Checks if the circle is closed. * @return True if the polyline is closed. */ }, { key: "isClosed", value: function isClosed() { var angles = this._kernel.objGetParams(this._id)[4]; if (angles === undefined) { return true; } if (angles[1] - angles[0] === 360) { return true; } return false; } /** * Get the length of the circle or arc. * @return The length. */ }, { key: "length", value: function length() { return math_conics.circleLength(this); } /** * Get the t parameter on the circle or arc. * @return A point entity. */ }, { key: "evalParam", value: function evalParam(t) { var xyz = math_conics.circleEvaluate(this, t); return this._kernel.getGeom().addPoint(xyz); } /** * Project a point onto the circle or arc, and return the t parameter. * @return t parameter value. */ }, { key: "evalPoint", value: function evalPoint(point) { return math_conics.circleEvaluatePoint(this, point); } /** * Get a set of equidistant points along the circle or arc. * @return An array of points. */ }, { key: "equiPoints", value: function equiPoints(num_points) { var length = math_conics.circleLength(this); var xyzs = []; for (var i = 0; i < num_points; i++) { xyzs.push(math_conics.circleEvaluate(this, i / (num_points - 1))); } return this._kernel.getGeom().addPoints(xyzs); } }]); return Circle; }(_entity_obj.Obj); //# sourceMappingURL=entity_obj_circle.js.map