@mlightcad/geometry-engine
Version:
The geometry-engine package provides comprehensive geometric entities, mathematical operations, and transformations for 2D and 3D space. This package mimics AutoCAD ObjectARX's AcGe (Geometry) classes and provides the mathematical foundation for CAD opera
141 lines • 4.43 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { AcGeBox2d, AcGePoint2d } from '../math';
import { AcGeCurve2d } from './AcGeCurve2d';
/**
* The class representing one closed loop created by connected edges, which can be line, circular arc,
* ellipse arc, or spline.
*/
var AcGeLoop2d = /** @class */ (function (_super) {
__extends(AcGeLoop2d, _super);
/**
* Create one loop by connected curves
* @param curves Input one array of connected curves
*/
function AcGeLoop2d(curves) {
if (curves === void 0) { curves = []; }
var _this = _super.call(this) || this;
_this._curves = curves;
return _this;
}
Object.defineProperty(AcGeLoop2d.prototype, "curves", {
get: function () {
return this._curves;
},
enumerable: false,
configurable: true
});
/**
* Append an edge to this loop
* @param curve
*/
AcGeLoop2d.prototype.add = function (curve) {
this._curves.push(curve);
this._boundingBoxNeedsUpdate = true;
};
Object.defineProperty(AcGeLoop2d.prototype, "numberOfEdges", {
/**
* The number of edges in this loop
*/
get: function () {
return this._curves.length;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcGeLoop2d.prototype, "startPoint", {
/**
* Start point of this polyline
*/
get: function () {
if (this._curves.length > 0) {
var temp = this._curves[0].startPoint;
return new AcGePoint2d(temp.x, temp.y);
}
throw new Error('Start point does not exist in an empty loop.');
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcGeLoop2d.prototype, "endPoint", {
/**
* End point of this polyline
*/
get: function () {
return this.startPoint;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcGeLoop2d.prototype, "length", {
/**
* @inheritdoc
*/
get: function () {
var length = 0;
this._curves.forEach(function (curve) {
length += curve.length;
});
return length;
},
enumerable: false,
configurable: true
});
/**
* @inheritdoc
*/
AcGeLoop2d.prototype.calculateBoundingBox = function () {
var points = this.getPoints(100);
var box2d = new AcGeBox2d();
box2d.setFromPoints(points);
return box2d;
};
/**
* @inheritdoc
*/
AcGeLoop2d.prototype.transform = function (_matrix) {
// TODO: implement it
this._boundingBoxNeedsUpdate = true;
return this;
};
Object.defineProperty(AcGeLoop2d.prototype, "closed", {
/**
* @inheritdoc
*/
get: function () {
return true;
},
enumerable: false,
configurable: true
});
/**
* Return boundary points of this area
* @param numPoints Input the nubmer of points returned for arc segmentation
* @returns Return points
*/
AcGeLoop2d.prototype.getPoints = function (numPoints) {
var points = [];
this.curves.forEach(function (curve) {
curve.getPoints(numPoints).forEach(function (point) {
points.push(new AcGePoint2d(point.x, point.y));
});
});
return points;
};
return AcGeLoop2d;
}(AcGeCurve2d));
export { AcGeLoop2d };
//# sourceMappingURL=AcGeLoop2d.js.map