@mlightcad/geometry-engine 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,13 +1,176 @@
1
- # Geometry Engine
1
+ # @mlightcad/geometry-engine
2
2
 
3
- The 2d and 3d geometry library.
3
+ 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 operations.
4
4
 
5
- # Implementation
5
+ ## Overview
6
6
 
7
- One of goals of this library is to depends on zero external library. So we copy code from some libraries. For exmaple, we copy classes `Box3`、`Matrix3`, `Matrix4`, `Plane`, `Vector2`, and `Vector3` from [THREE.js](https://threejs.org/docs/).
7
+ This package consists of two main categories of classes:
8
8
 
9
- ## TODO
9
+ - **Math Classes**: Focus on mathematical operations that underpin geometric calculations, including vectors, matrices, transformations, and linear algebra operations
10
+ - **Geometry Classes**: Focus on complex geometric entities and their operations, including lines, curves, surfaces, and intersections
10
11
 
11
- ### Cache
12
- - Cache bounding box of all geometries
13
- - Cache start point and end point of curve
12
+ Most math classes are adapted from [THREE.js](https://threejs.org/docs/index.html) with modified class names to match AutoCAD ObjectARX conventions.
13
+
14
+ ## Key Features
15
+
16
+ - **2D and 3D Geometry**: Support for both 2D and 3D geometric operations
17
+ - **Mathematical Foundation**: Comprehensive vector and matrix operations
18
+ - **Curve and Surface Support**: Advanced geometric entities including splines and NURBS
19
+ - **Transformation Utilities**: Matrix-based transformations for 2D and 3D space
20
+ - **Intersection Calculations**: Tools for computing geometric intersections
21
+ - **Performance Optimized**: Efficient mathematical operations for real-time CAD applications
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install @mlightcad/geometry-engine
27
+ ```
28
+
29
+ ## Key Classes
30
+
31
+ ### Math Classes (2D and 3D)
32
+
33
+ #### Points and Vectors
34
+ - **AcGePoint2d, AcGePoint3d**: Represent 2D and 3D points in space
35
+ - **AcGeVector2d, AcGeVector3d**: Represent 2D and 3D vectors with magnitude and direction
36
+
37
+ #### Transformations
38
+ - **AcGeMatrix2d, AcGeMatrix3d**: 2D and 3D transformation matrices
39
+ - **AcGeQuaternion**: Quaternion-based 3D rotations
40
+ - **AcGeEuler**: Euler angle representations for 3D rotations
41
+
42
+ #### Mathematical Utilities
43
+ - **AcGeBox2d, AcGeBox3d**: Bounding boxes in 2D and 3D space
44
+ - **AcGePlane**: 3D plane representations
45
+ - **AcGeTol**: Tolerance settings for geometric comparisons
46
+
47
+ ### Geometry Classes
48
+
49
+ #### Basic Geometric Entities
50
+ - **AcGeLine2d, AcGeLine3d**: Lines in 2D and 3D space
51
+ - **AcGeCurve2d, AcGeCurve3d**: Abstract base classes for curves
52
+ - **AcGeCircArc2d, AcGeCircArc3d**: Circular arcs in 2D and 3D
53
+ - **AcGeEllipseArc2d, AcGeEllipseArc3d**: Elliptical arcs
54
+
55
+ #### Complex Geometric Entities
56
+ - **AcGePolyline2d**: 2D polyline with multiple segments
57
+ - **AcGeSpline3d**: 3D spline curves
58
+ - **AcGeShape2d, AcGeShape3d**: Complex geometric shapes
59
+ - **AcGeArea2d**: 2D area calculations
60
+ - **AcGeLoop2d**: 2D loop representations
61
+
62
+ #### Utility Classes
63
+ - **AcGeGeometryUtil**: Utility functions for geometric operations
64
+ - **AcGeMathUtil**: Mathematical utility functions
65
+ - **AcGeConstants**: Geometric constants and settings
66
+
67
+ ## Usage Examples
68
+
69
+ ### Basic Point and Vector Operations
70
+ ```typescript
71
+ import { AcGePoint3d, AcGeVector3d, AcGeMatrix3d } from '@mlightcad/geometry-engine';
72
+
73
+ // Create points and vectors
74
+ const point1 = new AcGePoint3d(0, 0, 0);
75
+ const point2 = new AcGePoint3d(10, 10, 10);
76
+ const vector = new AcGeVector3d(1, 0, 0);
77
+
78
+ // Calculate distance between points
79
+ const distance = point1.distanceTo(point2);
80
+
81
+ // Transform a point
82
+ const matrix = AcGeMatrix3d.translation(5, 5, 5);
83
+ const transformedPoint = point1.transformBy(matrix);
84
+ ```
85
+
86
+ ### Line and Curve Operations
87
+ ```typescript
88
+ import { AcGeLine3d, AcGeCircArc3d, AcGePoint3d } from '@mlightcad/geometry-engine';
89
+
90
+ // Create a line
91
+ const startPoint = new AcGePoint3d(0, 0, 0);
92
+ const endPoint = new AcGePoint3d(10, 0, 0);
93
+ const line = new AcGeLine3d(startPoint, endPoint);
94
+
95
+ // Create a circular arc
96
+ const center = new AcGePoint3d(0, 0, 0);
97
+ const radius = 5;
98
+ const startAngle = 0;
99
+ const endAngle = Math.PI / 2;
100
+ const arc = new AcGeCircArc3d(center, radius, startAngle, endAngle);
101
+
102
+ // Get points along the curve
103
+ const param = 0.5;
104
+ const pointOnLine = line.evalPoint(param);
105
+ const pointOnArc = arc.evalPoint(param);
106
+ ```
107
+
108
+ ### Matrix Transformations
109
+ ```typescript
110
+ import { AcGeMatrix3d, AcGePoint3d } from '@mlightcad/geometry-engine';
111
+
112
+ // Create transformation matrices
113
+ const translation = AcGeMatrix3d.translation(10, 20, 30);
114
+ const rotation = AcGeMatrix3d.rotation(Math.PI / 4, AcGeVector3d.kZAxis);
115
+ const scale = AcGeMatrix3d.scaling(2, 2, 2);
116
+
117
+ // Combine transformations
118
+ const combined = translation.multiply(rotation).multiply(scale);
119
+
120
+ // Apply transformation to a point
121
+ const point = new AcGePoint3d(1, 1, 1);
122
+ const transformed = point.transformBy(combined);
123
+ ```
124
+
125
+ ### Polyline Operations
126
+ ```typescript
127
+ import { AcGePolyline2d, AcGePoint2d } from '@mlightcad/geometry-engine';
128
+
129
+ // Create a polyline
130
+ const polyline = new AcGePolyline2d();
131
+ polyline.addVertexAt(0, new AcGePoint2d(0, 0));
132
+ polyline.addVertexAt(1, new AcGePoint2d(10, 0));
133
+ polyline.addVertexAt(2, new AcGePoint2d(10, 10));
134
+ polyline.addVertexAt(3, new AcGePoint2d(0, 10));
135
+
136
+ // Close the polyline
137
+ polyline.setClosed(true);
138
+
139
+ // Get polyline properties
140
+ const length = polyline.length();
141
+ const area = polyline.area();
142
+ const isClosed = polyline.isClosed();
143
+ ```
144
+
145
+ ### Geometric Utilities
146
+ ```typescript
147
+ import { AcGeGeometryUtil, AcGePoint3d, AcGeVector3d } from '@mlightcad/geometry-engine';
148
+
149
+ // Calculate intersection between lines
150
+ const line1 = new AcGeLine3d(new AcGePoint3d(0, 0, 0), new AcGeVector3d(1, 0, 0));
151
+ const line2 = new AcGeLine3d(new AcGePoint3d(0, 0, 0), new AcGeVector3d(0, 1, 0));
152
+
153
+ const intersection = AcGeGeometryUtil.intersect(line1, line2);
154
+
155
+ // Check if points are collinear
156
+ const points = [
157
+ new AcGePoint3d(0, 0, 0),
158
+ new AcGePoint3d(1, 1, 1),
159
+ new AcGePoint3d(2, 2, 2)
160
+ ];
161
+
162
+ const areCollinear = AcGeGeometryUtil.areCollinear(points);
163
+ ```
164
+
165
+ ## Dependencies
166
+
167
+ - **@mlightcad/common**: For common utilities (peer dependency)
168
+ - **lodash-es**: For utility functions (peer dependency)
169
+
170
+ ## API Documentation
171
+
172
+ For detailed API documentation, visit the [RealDWG-Web documentation](https://mlight-lee.github.io/realdwg-web/).
173
+
174
+ ## Contributing
175
+
176
+ This package is part of the RealDWG-Web monorepo. Please refer to the main project README for contribution guidelines.