@mlightcad/data-model
Version:
The data-model package provides the core classes for interacting with AutoCAD's database and entities. This package mimics AutoCAD ObjectARX's AcDb (Database) classes and implements the drawing database structure that AutoCAD developers are familiar with.
500 lines • 17.4 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 { AcGeCircArc3d, AcGeVector3d } from '@mlightcad/geometry-engine';
import { AcDbCurve } from './AcDbCurve';
/**
* Represents an arc entity in AutoCAD.
*
* An arc is a 2D geometric object defined by its center point, radius, start angle,
* and end angle. Arcs are portions of circles that can be used to create curved
* line segments in drawings. The arc is always drawn in the plane defined by its normal vector.
*
* @example
* ```typescript
* // Create a 90-degree arc from 0 to π/2 radians
* const arc = new AcDbArc(
* new AcGePoint3d(0, 0, 0),
* 10,
* 0,
* Math.PI / 2
* );
*
* // Access arc properties
* console.log(`Center: ${arc.center}`);
* console.log(`Radius: ${arc.radius}`);
* console.log(`Start angle: ${arc.startAngle}`);
* console.log(`End angle: ${arc.endAngle}`);
* ```
*/
var AcDbArc = /** @class */ (function (_super) {
__extends(AcDbArc, _super);
/**
* Creates a new arc entity.
*
* This constructor creates an arc using the specified center point, radius,
* start angle, and end angle. The center point must be in World Coordinate
* System (WCS) coordinates. Angles are specified in radians.
*
* @param center - The center point of the arc in WCS coordinates
* @param radius - The radius of the arc (must be positive)
* @param startAngle - The starting angle in radians (0 to 2π)
* @param endAngle - The ending angle in radians (0 to 2π)
* @param normal - The normal vector defining the plane of the circle (defaults to Z-axis)
*
* @example
* ```typescript
* // Create a quarter circle arc (0 to 90 degrees)
* const quarterArc = new AcDbArc(
* new AcGePoint3d(0, 0, 0),
* 15,
* 0,
* Math.PI / 2
* );
*
* // Create a semicircle arc (0 to 180 degrees)
* const semicircle = new AcDbArc(
* new AcGePoint3d(10, 20, 0),
* 25,
* 0,
* Math.PI
* );
* ```
*/
function AcDbArc(center, radius, startAngle, endAngle, normal) {
if (normal === void 0) { normal = AcGeVector3d.Z_AXIS; }
var _this = _super.call(this) || this;
_this._geo = new AcGeCircArc3d(center, radius, startAngle, endAngle, normal, AcGeVector3d.X_AXIS);
return _this;
}
Object.defineProperty(AcDbArc.prototype, "center", {
/**
* Gets the center point of this arc.
*
* @returns The center point as a 3D point
*
* @example
* ```typescript
* const centerPoint = arc.center;
* console.log(`Arc center: ${centerPoint.x}, ${centerPoint.y}, ${centerPoint.z}`);
* ```
*/
get: function () {
return this._geo.center;
},
/**
* Sets the center point of this arc.
*
* @param value - The new center point
*
* @example
* ```typescript
* arc.center = new AcGePoint3d(5, 5, 0);
* ```
*/
set: function (value) {
this._geo.center = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbArc.prototype, "radius", {
/**
* Gets the radius of this arc.
*
* @returns The radius value
*
* @example
* ```typescript
* const radius = arc.radius;
* console.log(`Arc radius: ${radius}`);
* ```
*/
get: function () {
return this._geo.radius;
},
/**
* Sets the radius of this arc.
*
* @param value - The new radius value (must be positive)
*
* @example
* ```typescript
* arc.radius = 25;
* ```
*/
set: function (value) {
this._geo.radius = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbArc.prototype, "startAngle", {
/**
* Gets the start angle of this arc.
*
* @returns The start angle in radians
*
* @example
* ```typescript
* const startAngle = arc.startAngle;
* console.log(`Arc start angle: ${startAngle} radians (${startAngle * 180 / Math.PI} degrees)`);
* ```
*/
get: function () {
return this._geo.startAngle;
},
/**
* Sets the start angle of this arc.
*
* @param value - The new start angle in radians (0 to 2π)
*
* @example
* ```typescript
* arc.startAngle = Math.PI / 4; // 45 degrees
* ```
*/
set: function (value) {
this._geo.startAngle = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbArc.prototype, "endAngle", {
/**
* Gets the end angle of this arc.
*
* @returns The end angle in radians
*
* @example
* ```typescript
* const endAngle = arc.endAngle;
* console.log(`Arc end angle: ${endAngle} radians (${endAngle * 180 / Math.PI} degrees)`);
* ```
*/
get: function () {
return this._geo.endAngle;
},
/**
* Sets the end angle of this arc.
*
* @param value - The new end angle in radians (0 to 2π)
*
* @example
* ```typescript
* arc.endAngle = Math.PI; // 180 degrees
* ```
*/
set: function (value) {
this._geo.endAngle = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbArc.prototype, "normal", {
/**
* Gets the arc's unit normal vector in WCS coordinates.
*
* @returns The arc's unit normal vector
*
* @example
* ```typescript
* const normal = arc.normal;
* console.log(`Normal: ${normal.x}, ${normal.y}, ${normal.z}`);
* ```
*/
get: function () {
return this._geo.normal;
},
/**
* Sets the arc's unit normal vector in WCS coordinates.
*
* @param value - The new arc's unit normal vector
*
* @example
* ```typescript
* arc.normal = new AcGeVector3d(0, 0, 1);
* ```
*/
set: function (value) {
this._geo.normal = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbArc.prototype, "startPoint", {
/**
* Gets the start point of this arc.
*
* The start point is calculated based on the center, radius, and start angle.
*
* @returns The start point as a 3D point
*
* @example
* ```typescript
* const startPoint = arc.startPoint;
* console.log(`Arc start point: ${startPoint.x}, ${startPoint.y}, ${startPoint.z}`);
* ```
*/
get: function () {
return this._geo.startPoint;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbArc.prototype, "endPoint", {
/**
* Gets the end point of this arc.
*
* The end point is calculated based on the center, radius, and end angle.
*
* @returns The end point as a 3D point
*
* @example
* ```typescript
* const endPoint = arc.endPoint;
* console.log(`Arc end point: ${endPoint.x}, ${endPoint.y}, ${endPoint.z}`);
* ```
*/
get: function () {
return this._geo.endPoint;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbArc.prototype, "geometricExtents", {
/**
* Gets the geometric extents (bounding box) of this arc.
*
* @returns The bounding box that encompasses the entire arc
*
* @example
* ```typescript
* const extents = arc.geometricExtents;
* console.log(`Arc bounds: ${extents.minPoint} to ${extents.maxPoint}`);
* ```
*/
get: function () {
return this._geo.box;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbArc.prototype, "closed", {
/**
* Gets whether this arc is closed.
*
* An arc is considered closed if the start and end angles are the same
* (forming a complete circle).
*
* @returns True if the arc is closed (forms a complete circle), false otherwise
*/
get: function () {
return this._geo.closed;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbArc.prototype, "properties", {
/**
* Returns the full property definition for this arc entity, including
* general group and geometry group.
*
* The geometry group exposes editable properties via {@link AcDbPropertyAccessor}
* so the property palette can update the arc in real-time.
*
* Each property is an {@link AcDbEntityRuntimeProperty}.
*/
get: function () {
var _this = this;
return {
type: this.type,
groups: [
this.getGeneralProperties(),
{
groupName: 'geometry',
properties: [
// --- Cennter Point ---
{
name: 'centerX',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.center.x; },
set: function (v) {
_this.center.x = v;
}
}
},
{
name: 'centerY',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.center.y; },
set: function (v) {
_this.center.y = v;
}
}
},
{
name: 'centerZ',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.center.z; },
set: function (v) {
_this.center.z = v;
}
}
},
{
name: 'radius',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.radius; },
set: function (v) {
_this.radius = v;
}
}
},
{
name: 'startAngle',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.startAngle; },
set: function (v) {
_this.startAngle = v;
}
}
},
{
name: 'endAngle',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.endAngle; },
set: function (v) {
_this.endAngle = v;
}
}
},
{
name: 'normalX',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.normal.x; },
set: function (v) {
_this.normal.x = v;
}
}
},
{
name: 'normalY',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.normal.y; },
set: function (v) {
_this.normal.y = v;
}
}
},
{
name: 'normalZ',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.normal.z; },
set: function (v) {
_this.normal.z = v;
}
}
}
]
}
]
};
},
enumerable: false,
configurable: true
});
/**
* Gets the grip points for this arc.
*
* Grip points are control points that can be used to modify the arc.
* For an arc, the grip points are the center point, start point, and end point.
*
* @returns Array of grip points (center, start point, end point)
*
* @example
* ```typescript
* const gripPoints = arc.subGetGripPoints();
* // gripPoints contains: [center, startPoint, endPoint]
* ```
*/
AcDbArc.prototype.subGetGripPoints = function () {
var gripPoints = new Array();
gripPoints.push(this.center);
gripPoints.push(this.startPoint);
gripPoints.push(this.endPoint);
return gripPoints;
};
/**
* Transforms this arc by the specified matrix.
*
* This method applies a geometric transformation to the arc, updating
* the center point, radius, and angles according to the transformation matrix.
*
* @param matrix - The transformation matrix to apply
* @returns This arc after transformation
*
* @example
* ```typescript
* const translationMatrix = AcGeMatrix3d.translation(10, 0, 0);
* arc.transformBy(translationMatrix);
* // Arc is now translated 10 units in the X direction
* ```
*/
AcDbArc.prototype.transformBy = function (matrix) {
this._geo.transform(matrix);
return this;
};
/**
* Draws this arc using the specified renderer.
*
* This method renders the arc as a circular arc using the arc's
* current style properties.
*
* @param renderer - The renderer to use for drawing
* @returns The rendered arc entity, or undefined if drawing failed
*
* @example
* ```typescript
* const renderedArc = arc.draw(renderer);
* ```
*/
AcDbArc.prototype.draw = function (renderer) {
return renderer.circularArc(this._geo, this.lineStyle);
};
/** The entity type name */
AcDbArc.typeName = 'Arc';
return AcDbArc;
}(AcDbCurve));
export { AcDbArc };
//# sourceMappingURL=AcDbArc.js.map