gs-json
Version:
gs-JSON is a domain agnostic unifying 3D file format for geometric and semantic modelling (hence the 'gs').
177 lines (149 loc) • 5.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Point = 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 _enums = require("./enums");
var _topo_sub = require("./topo_sub");
var _entity = require("./entity");
var _groups = require("./groups");
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 Point.
* A point with x, y, z coordinates.
* A point may be part of a group and may have attributes.
*/
var Point = exports.Point = function (_Ent) {
_inherits(Point, _Ent);
function Point() {
_classCallCheck(this, Point);
return _possibleConstructorReturn(this, (Point.__proto__ || Object.getPrototypeOf(Point)).apply(this, arguments));
}
_createClass(Point, [{
key: "exists",
/**
* Check if this entity exists in the model. (i.e has it been deleted?)
* @return The entity ID number.
*/
value: function exists() {
return this._kernel.geomHasPoint(this._id);
}
/**
* Get the geometry type for this entity.
* This method overrides the method in the Ent class.
* @return The geometry type.
*/
}, {
key: "getGeomType",
value: function getGeomType() {
return _enums.EGeomType.points;
}
/**
* Set the cartesian x,y,z coordinates of a point.
* @param xyz Cartesian coordinates
* @return Arrays of pre-defined coordinates
*/
}, {
key: "setPosition",
value: function setPosition(xyz) {
return this._kernel.pointSetPosition(this._id, xyz);
}
/**
* Get the cartesian x, y, z coordinates of a point.
* @return Returns an array that contains the x, y, z coordinates
*/
}, {
key: "getPosition",
value: function getPosition() {
return this._kernel.pointGetPosition(this._id);
}
/**
* Get all the vertices linked to a point or a set of points.
* @return Returns the array of vertices.
*/
}, {
key: "getVertices",
value: function getVertices() {
var _this2 = this;
var paths = this._kernel.pointGetVertices(this._id);
return paths.map(function (path) {
return new _topo_sub.Vertex(_this2._kernel, path);
});
}
/**
* Get the label of this point.
* @return The xyz of the centroid.
*/
}, {
key: "getLabel",
value: function getLabel() {
return "p" + this._id;
}
/**
* Get the label centroid of this points.
* @return The xyz of the label.
*/
}, {
key: "getLabelCentroid",
value: function getLabelCentroid() {
return this.getPosition();
}
/**
* Make a copy of this entity.
* This method must be overridden by the sub-classes.
* @return The geometry type.
*/
}, {
key: "copy",
value: function copy(copy_attribs) {
return new Point(this._kernel, this._kernel.geomCopyPoint(this._id, copy_attribs));
}
/**
* Transform the points for this object.
* @param matrix The xform matrix.
*/
}, {
key: "xform",
value: function xform(matrix) {
return this._kernel.pointXform(this._id, matrix);
}
// Groups -------------------------------------------------------------------------------------
/**
* Get the group names for all the groups for which this entity is a member.
* @return The array of group names.
*/
}, {
key: "getGroups",
value: function getGroups() {
var _this3 = this;
return this._kernel.pointGetGroups(this._id).map(function (v) {
return new _groups.Group(_this3._kernel, v);
});
}
/**
* Add this entity to a group.
* @param name The group name.
* @return True if the entity was added, False is the entity was already in the group.
*/
}, {
key: "addToGroup",
value: function addToGroup(group) {
return this._kernel.groupAddPoint(group.getName(), this._id);
}
// toString -------------------------------------------------------------------------------------
/**
* Create s string representation of this point.
* @return String
*/
}, {
key: "toString",
value: function toString() {
return "Point:[" + this.getPosition() + "]";
}
}]);
return Point;
}(_entity.Ent);
//# sourceMappingURL=entity_point.js.map