@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.
302 lines • 11.1 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 { AcGeBox3d, AcGePoint3d, AcGeVector3d } from '@mlightcad/geometry-engine';
import { AcDbCurve } from './AcDbCurve';
/**
* Represents a ray entity in AutoCAD.
*
* A ray is a 3D geometric object that extends infinitely in one direction from a base point.
* Rays are commonly used for construction lines, reference lines, and temporary geometry.
* Unlike lines, rays have no end point and extend to infinity.
*
* @example
* ```typescript
* // Create a ray from origin in the positive X direction
* const ray = new AcDbRay();
* ray.basePoint = new AcGePoint3d(0, 0, 0);
* ray.unitDir = new AcGeVector3d(1, 0, 0);
*
* // Access ray properties
* console.log(`Base point: ${ray.basePoint}`);
* console.log(`Unit direction: ${ray.unitDir}`);
* ```
*/
var AcDbRay = /** @class */ (function (_super) {
__extends(AcDbRay, _super);
/**
* Creates a new ray entity.
*
* This constructor initializes a ray with default values.
* The base point is at the origin and the unit direction is undefined.
*
* @example
* ```typescript
* const ray = new AcDbRay();
* ray.basePoint = new AcGePoint3d(5, 10, 0);
* ray.unitDir = new AcGeVector3d(0, 1, 0); // Positive Y direction
* ```
*/
function AcDbRay() {
var _this = _super.call(this) || this;
_this._basePoint = new AcGePoint3d();
_this._unitDir = new AcGeVector3d();
return _this;
}
Object.defineProperty(AcDbRay.prototype, "basePoint", {
/**
* Gets the base point of this ray.
*
* The base point is the starting point from which the ray extends infinitely.
*
* @returns The base point as a 3D point
*
* @example
* ```typescript
* const basePoint = ray.basePoint;
* console.log(`Ray base point: ${basePoint.x}, ${basePoint.y}, ${basePoint.z}`);
* ```
*/
get: function () {
return this._basePoint;
},
/**
* Sets the base point of this ray.
*
* @param value - The new base point
*
* @example
* ```typescript
* ray.basePoint = new AcGePoint3d(10, 20, 0);
* ```
*/
set: function (value) {
this._basePoint.copy(value);
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbRay.prototype, "unitDir", {
/**
* Gets the unit direction vector of this ray.
*
* The unit direction vector defines the direction in which the ray extends
* infinitely from the base point.
*
* @returns The unit direction vector
*
* @example
* ```typescript
* const unitDir = ray.unitDir;
* console.log(`Ray direction: ${unitDir.x}, ${unitDir.y}, ${unitDir.z}`);
* ```
*/
get: function () {
return this._unitDir;
},
/**
* Sets the unit direction vector of this ray.
*
* @param value - The new unit direction vector
*
* @example
* ```typescript
* ray.unitDir = new AcGeVector3d(0, 0, 1); // Positive Z direction
* ```
*/
set: function (value) {
this._unitDir.copy(value);
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbRay.prototype, "closed", {
/**
* Gets whether this ray is closed.
*
* Rays are always open entities, so this always returns false.
*
* @returns Always false for rays
*/
get: function () {
return false;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbRay.prototype, "geometricExtents", {
/**
* Gets the geometric extents (bounding box) of this ray.
*
* Since rays extend infinitely, this method returns a bounding box that
* encompasses a finite portion of the ray for practical purposes.
*
* @returns The bounding box that encompasses a portion of the ray
*
* @example
* ```typescript
* const extents = ray.geometricExtents;
* console.log(`Ray bounds: ${extents.minPoint} to ${extents.maxPoint}`);
* ```
*/
get: function () {
var extents = new AcGeBox3d();
extents.expandByPoint(this._unitDir.clone().multiplyScalar(10).add(this._basePoint));
extents.expandByPoint(this._unitDir.clone().multiplyScalar(-10).add(this._basePoint));
return extents;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbRay.prototype, "properties", {
/**
* Returns the full property definition for this ray entity, including
* general group and geometry group.
*
* The geometry group exposes editable start/end coordinates via
* {@link AcDbPropertyAccessor} so the property palette can update
* the ray in real-time.
*
* Each property is an {@link AcDbEntityRuntimeProperty}.
*/
get: function () {
var _this = this;
return {
type: this.type,
groups: [
this.getGeneralProperties(),
{
groupName: 'geometry',
properties: [
{
name: 'basePointX',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.basePoint.x; },
set: function (v) {
_this.basePoint.x = v;
}
}
},
{
name: 'basePointY',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.basePoint.y; },
set: function (v) {
_this.basePoint.y = v;
}
}
},
{
name: 'basePointZ',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.basePoint.z; },
set: function (v) {
_this.basePoint.z = v;
}
}
},
{
name: 'unitDirX',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.unitDir.x; },
set: function (v) {
_this.unitDir.x = v;
}
}
},
{
name: 'unitDirY',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.unitDir.y; },
set: function (v) {
_this.unitDir.y = v;
}
}
},
{
name: 'unitDirZ',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.unitDir.z; },
set: function (v) {
_this.unitDir.z = v;
}
}
}
]
}
]
};
},
enumerable: false,
configurable: true
});
/**
* Gets the grip points for this ray.
*
* Grip points are control points that can be used to modify the ray.
* For a ray, the grip point is the base point.
*
* @returns Array of grip points (base point)
*
* @example
* ```typescript
* const gripPoints = ray.subGetGripPoints();
* // gripPoints contains: [basePoint]
* ```
*/
AcDbRay.prototype.subGetGripPoints = function () {
var gripPoints = new Array();
gripPoints.push(this.basePoint);
return gripPoints;
};
/**
* Draws this ray using the specified renderer.
*
* This method renders the ray as a line segment extending from the base point
* in the direction of the unit vector. For practical purposes, the ray is
* drawn with a finite length.
*
* @param renderer - The renderer to use for drawing
* @returns The rendered ray entity, or undefined if drawing failed
*
* @example
* ```typescript
* const renderedRay = ray.draw(renderer);
* ```
*/
AcDbRay.prototype.draw = function (renderer) {
var points = [];
points.push(this.basePoint);
points.push(this._unitDir.clone().multiplyScalar(1000000).add(this._basePoint));
return renderer.lines(points, this.lineStyle);
};
/** The entity type name */
AcDbRay.typeName = 'Ray';
return AcDbRay;
}(AcDbCurve));
export { AcDbRay };
//# sourceMappingURL=AcDbRay.js.map