gs-json
Version:
gs-JSON is a domain agnostic unifying 3D file format for geometric and semantic modelling (hence the 'gs').
650 lines (564 loc) • 21 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Face = exports.Wire = exports.Edge = exports.Vertex = 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 _topo = require("./topo");
var _enums = require("./enums");
var _entity_point = require("./entity_point");
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; }
/**
* Vertex class.
*/
var Vertex = exports.Vertex = function (_Topo) {
_inherits(Vertex, _Topo);
function Vertex() {
_classCallCheck(this, Vertex);
return _possibleConstructorReturn(this, (Vertex.__proto__ || Object.getPrototypeOf(Vertex)).apply(this, arguments));
}
_createClass(Vertex, [{
key: "getGeomType",
/**
* Get the geometry type: "vertices".
* This method overrides the method in the Topo class.
* @return The topo type.
*/
value: function getGeomType() {
return _enums.EGeomType.vertices;
}
/**
* Get a compact string representation of the geometry path for this topological component, dtsrting with
* the obj ID.
* @return The geometry path str.
*/
}, {
key: "getTopoPathStr",
value: function getTopoPathStr() {
var w_or_f = ["w", "f"][this._path.tt];
return "o" + this.getObjID() + ":" + w_or_f + this._path.ti + ":v" + this._path.si;
}
/**
* Get the centroid of this topo. This is used for attaching labels.
* @return The xyz of the centroid.
*/
}, {
key: "getLabelCentroid",
value: function getLabelCentroid() {
return this.getPoint().getPosition();
}
/**
* Get the point associated with this vertex.
* @return The point object.
*/
}, {
key: "getPoint",
value: function getPoint() {
var id = this._kernel.vertexGetPoint(this._path);
return new _entity_point.Point(this._kernel, id);
}
/**
* Get the edge for which this is the start vertex.
* @return The edge object.
*/
}, {
key: "getEdge",
value: function getEdge() {
var path = this._kernel.vertexGetEdge(this._path);
return new Edge(this._kernel, path);
}
/**
* Get the wire or face to which this vertex belongs.
* @return The wire or face object.
*/
}, {
key: "getWireOrFace",
value: function getWireOrFace() {
var path = this._kernel.vertexGetTopo(this._path);
if (path.tt === 0) {
return new Wire(this._kernel, path);
} else {
return new Face(this._kernel, path);
}
}
/**
* Find the next vertex in the sequence of vertices in the wire or face.
* @return The next vertex object.
*/
}, {
key: "next",
value: function next() {
var path = this._kernel.vertexNext(this._path);
if (path === null) {
return null;
}
return new Vertex(this._kernel, path);
}
/**
* Find the previous vertex in the sequence of vertices in the wire or face.
* @return The previous vertex object.
*/
}, {
key: "previous",
value: function previous() {
var path = this._kernel.vertexPrevious(this._path);
if (path === null) {
return null;
}
return new Vertex(this._kernel, path);
}
/**
* Within the parent object, find all vertices with the same point.
* Returns an array containing two sub-arrays.
* 1) The wire vertices, and 2) the face vertices.
* @return An array containing the two sub-arrays of vertices.
*/
}, {
key: "verticesSharedPoint",
value: function verticesSharedPoint() {
var _this2 = this;
var paths = this._kernel.geomFindVerticesSharedPoint(this._path);
return [paths[0].map(function (path) {
return new Vertex(_this2._kernel, path);
}), paths[1].map(function (path) {
return new Vertex(_this2._kernel, path);
})];
}
/**
* Within the parent object, find all vertices with the same point position.
* Returns an array containing two sub-arrays.
* 1) The wire vertices, and 2) the face vertices.
* @return An array containing the two sub-arrays of vertices.
*/
}, {
key: "verticesSamePosition",
value: function verticesSamePosition() {
var _this3 = this;
var paths = this._kernel.geomFindVerticesSamePosition(this._path);
return [paths[0].map(function (path) {
return new Vertex(_this3._kernel, path);
}), paths[1].map(function (path) {
return new Vertex(_this3._kernel, path);
})];
}
}]);
return Vertex;
}(_topo.Topo);
/**
* Edge class.
*/
var Edge = exports.Edge = function (_Topo2) {
_inherits(Edge, _Topo2);
function Edge() {
_classCallCheck(this, Edge);
return _possibleConstructorReturn(this, (Edge.__proto__ || Object.getPrototypeOf(Edge)).apply(this, arguments));
}
_createClass(Edge, [{
key: "getGeomType",
/**
* Get the geometry type: "edges".
* This method overrides the method in the Topo class.
* @return The topo type.
*/
value: function getGeomType() {
return _enums.EGeomType.edges;
}
/**
* Get a compact string representation of the geometry path for this topological component, dtsrting with
* the obj ID.
* @return The geometry path str.
*/
}, {
key: "getTopoPathStr",
value: function getTopoPathStr() {
var w_or_f = ["w", "f"][this._path.tt];
return "o" + this.getObjID() + ":" + w_or_f + this._path.ti + ":e" + this._path.si;
}
/**
* Get the centroid of this topo. This is used for attaching labels.
* @return The xyz of the centroid.
*/
}, {
key: "getLabelCentroid",
value: function getLabelCentroid() {
var xyzs = this.getVertices().map(function (v) {
return v.getPoint().getPosition();
});
var centroid = [0, 0, 0];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = xyzs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var xyz = _step.value;
centroid[0] += xyz[0];
centroid[1] += xyz[1];
centroid[2] += xyz[2];
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return [centroid[0] / 2, centroid[1] / 2, centroid[2] / 2];
}
/**
* Get the two vertices for this edge.
* @return An array of two edges.
*/
}, {
key: "getVertices",
value: function getVertices() {
var _this5 = this;
var paths = this._kernel.edgeGetVertices(this._path);
return paths.map(function (path) {
return new Vertex(_this5._kernel, path);
});
}
/**
* Get the wire or face to which this edge belongs.
* @return The wire or face.
*/
}, {
key: "getWireOrFace",
value: function getWireOrFace() {
var path = this._kernel.edgeGetTopo(this._path);
if (path.tt === 0) {
return new Wire(this._kernel, path);
} else {
return new Face(this._kernel, path);
}
}
/**
* Find the next edge in the sequence of edges in the wire or face.
* @return The next edge object.
*/
}, {
key: "next",
value: function next() {
var path = this._kernel.edgeNext(this._path);
if (path === null) {
return null;
}
return new Edge(this._kernel, path);
}
/**
* Find the previous edge in the sequence of edges in the wire or face.
* @return The previous edge object.
*/
}, {
key: "previous",
value: function previous() {
var path = this._kernel.edgePrevious(this._path);
if (path === null) {
return null;
}
return new Edge(this._kernel, path);
}
/**
* Within the parent object, find all edges with the same two points as this edge.
* The order of the points is ignored.
* Returns an array containing two sub-arrays.
* 1) The wire edges, and 2) the face edges.
* @return An array containing the two sub-arrays of edges.
*/
}, {
key: "edgesSharedPoints",
value: function edgesSharedPoints() {
var _this6 = this;
var paths = this._kernel.geomFindEdgesSharedPoints(this._path);
return [paths[0].map(function (path) {
return new Edge(_this6._kernel, path);
}), paths[1].map(function (path) {
return new Edge(_this6._kernel, path);
})];
}
}]);
return Edge;
}(_topo.Topo);
/**
* Wire class
*/
var Wire = exports.Wire = function (_Topo3) {
_inherits(Wire, _Topo3);
function Wire() {
_classCallCheck(this, Wire);
return _possibleConstructorReturn(this, (Wire.__proto__ || Object.getPrototypeOf(Wire)).apply(this, arguments));
}
_createClass(Wire, [{
key: "getGeomType",
/**
* Get the geometry type: "wires".
* This method overrides the method in the Topo class.
* @return The topo type.
*/
value: function getGeomType() {
return _enums.EGeomType.wires;
}
/**
* Get a compact string representation of the geometry path for this topological component, dtsrting with
* the obj ID.
* @return The geometry path str.
*/
}, {
key: "getTopoPathStr",
value: function getTopoPathStr() {
return "o" + this.getObjID() + ":w" + this._path.ti;
}
/**
* Get the centroid of this topo. This is used for attaching labels.
* @return The xyz of the centroid.
*/
}, {
key: "getLabelCentroid",
value: function getLabelCentroid() {
var xyzs = this.getVertices().map(function (v) {
return v.getPoint().getPosition();
});
var centroid = [0, 0, 0];
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = xyzs[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var xyz = _step2.value;
centroid[0] += xyz[0];
centroid[1] += xyz[1];
centroid[2] += xyz[2];
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
var num_vertices = xyzs.length;
return [centroid[0] / num_vertices, centroid[1] / num_vertices, centroid[2] / num_vertices];
}
/**
* Get the vertices for this wire.
* @return An array of vertices.
*/
}, {
key: "getVertices",
value: function getVertices() {
var _this8 = this;
var paths = this._kernel.topoGetVertices(this._path);
return paths.map(function (path) {
return new Vertex(_this8._kernel, path);
});
}
/**
* Get the edges for this wire.
* @return An array of edges.
*/
}, {
key: "getEdges",
value: function getEdges() {
var _this9 = this;
var paths = this._kernel.topoGetEdges(this._path);
return paths.map(function (path) {
return new Edge(_this9._kernel, path);
});
}
/**
* Get the number of vertices in this wire.
* @return The number of vertices.
*/
}, {
key: "numVertices",
value: function numVertices() {
return this._kernel.topoNumVertices(this._path);
}
/**
* Get the number of edges in this wire.
* @return The number of edges.
*/
}, {
key: "numEdges",
value: function numEdges() {
return this._kernel.topoNumEdges(this._path);
}
/**
* Return true if this wire is closed.
* @return boolean
*/
}, {
key: "isClosed",
value: function isClosed() {
return this._kernel.topoIsClosed(this._path);
}
/**
* Within the parent object, find all wires that share at least n points.
* @return An array of wires.
*/
}, {
key: "wiresSharedPoints",
value: function wiresSharedPoints(num_shared_points) {
var _this10 = this;
var paths = this._kernel.geomFindTopoSharedPoints(this._path);
return paths.map(function (path) {
return new Wire(_this10._kernel, path);
});
}
}]);
return Wire;
}(_topo.Topo);
/**
* Face class
*/
var Face = exports.Face = function (_Topo4) {
_inherits(Face, _Topo4);
function Face() {
_classCallCheck(this, Face);
return _possibleConstructorReturn(this, (Face.__proto__ || Object.getPrototypeOf(Face)).apply(this, arguments));
}
_createClass(Face, [{
key: "getGeomType",
/**
* Get the geometry type: "faces".
* This method overrides the method in the Topo class.
* @return The topo type.
*/
value: function getGeomType() {
return _enums.EGeomType.faces;
}
/**
* Get a compact string representation of the geometry path for this topological component, dtsrting with
* the obj ID.
* @return The geometry path str.
*/
}, {
key: "getTopoPathStr",
value: function getTopoPathStr() {
return "o" + this.getObjID() + ":f" + this._path.ti;
}
/**
* Get the centroid of this topo. This is used for attaching labels.
* @return The xyz of the centroid.
*/
}, {
key: "getLabelCentroid",
value: function getLabelCentroid() {
var xyzs = this.getVertices().map(function (v) {
return v.getPoint().getPosition();
});
var centroid = [0, 0, 0];
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = xyzs[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var xyz = _step3.value;
centroid[0] += xyz[0];
centroid[1] += xyz[1];
centroid[2] += xyz[2];
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
var num_vertices = xyzs.length;
return [centroid[0] / num_vertices, centroid[1] / num_vertices, centroid[2] / num_vertices];
}
/**
* Get the vertices for this wire.
* @return An array of vertices.
*/
}, {
key: "getVertices",
value: function getVertices() {
var _this12 = this;
var paths = this._kernel.topoGetVertices(this._path);
return paths.map(function (path) {
return new Vertex(_this12._kernel, path);
});
}
/**
* Get the edges for this wire.
* @return An array of edges.
*/
}, {
key: "getEdges",
value: function getEdges() {
var _this13 = this;
var paths = this._kernel.topoGetEdges(this._path);
return paths.map(function (path) {
return new Edge(_this13._kernel, path);
});
}
/**
* Get the number of vertices in this face.
* This is the same as numEdges().
* @return The number of vertices.
*/
}, {
key: "numVertices",
value: function numVertices() {
return this._kernel.topoNumVertices(this._path);
}
/**
* Get the number of edged in this face.
* This is the same as numVertices().
* @return The number of edges.
*/
}, {
key: "numEdges",
value: function numEdges() {
return this._kernel.topoNumEdges(this._path);
}
/**
* Return true, since a face is always closed.
* @return boolean
*/
}, {
key: "isClosed",
value: function isClosed() {
return true;
}
/**
* Within the parent object, find all faces that share at least n points.
* @return An array of faces.
*/
}, {
key: "facesSharedPoints",
value: function facesSharedPoints(num_shared_points) {
var _this14 = this;
var paths = this._kernel.geomFindTopoSharedPoints(this._path);
return paths.map(function (path) {
return new Face(_this14._kernel, path);
});
}
}]);
return Face;
}(_topo.Topo);
//# sourceMappingURL=topo_sub.js.map