@mlightcad/geometry-engine 2.0.0 → 2.0.1
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/dist/geometry-engine.js +761 -517
- package/dist/geometry-engine.umd.cjs +1 -1
- package/lib/geometry/AcGeCatmullRomCurve3d.d.ts +146 -0
- package/lib/geometry/AcGeCatmullRomCurve3d.d.ts.map +1 -0
- package/lib/geometry/AcGeCatmullRomCurve3d.js +358 -0
- package/lib/geometry/AcGeCatmullRomCurve3d.js.map +1 -0
- package/lib/geometry/AcGeNurbsCurve.d.ts +69 -0
- package/lib/geometry/AcGeNurbsCurve.d.ts.map +1 -0
- package/lib/geometry/AcGeNurbsCurve.js +166 -0
- package/lib/geometry/AcGeNurbsCurve.js.map +1 -0
- package/lib/geometry/AcGeSpline3d.d.ts +13 -54
- package/lib/geometry/AcGeSpline3d.d.ts.map +1 -1
- package/lib/geometry/AcGeSpline3d.js +52 -181
- package/lib/geometry/AcGeSpline3d.js.map +1 -1
- package/lib/geometry/index.d.ts +2 -0
- package/lib/geometry/index.d.ts.map +1 -1
- package/lib/geometry/index.js +2 -0
- package/lib/geometry/index.js.map +1 -1
- package/lib/util/AcGeSplineUtil.d.ts +36 -0
- package/lib/util/AcGeSplineUtil.d.ts.map +1 -0
- package/lib/util/AcGeSplineUtil.js +491 -0
- package/lib/util/AcGeSplineUtil.js.map +1 -0
- package/package.json +1 -1
@@ -0,0 +1,358 @@
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
2
|
+
var extendStatics = function (d, b) {
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
6
|
+
return extendStatics(d, b);
|
7
|
+
};
|
8
|
+
return function (d, b) {
|
9
|
+
if (typeof b !== "function" && b !== null)
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
11
|
+
extendStatics(d, b);
|
12
|
+
function __() { this.constructor = d; }
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
14
|
+
};
|
15
|
+
})();
|
16
|
+
import { AcGeBox3d, AcGePoint3d, AcGeVector3d } from '../math';
|
17
|
+
import { AcGeCurve3d } from './AcGeCurve3d';
|
18
|
+
/**
|
19
|
+
* Internal class for computing cubic polynomial coefficients
|
20
|
+
* Based on an optimized c++ solution in
|
21
|
+
* - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
|
22
|
+
* - http://ideone.com/NoEbVM
|
23
|
+
*/
|
24
|
+
var CubicPoly = /** @class */ (function () {
|
25
|
+
function CubicPoly() {
|
26
|
+
this.c0 = 0;
|
27
|
+
this.c1 = 0;
|
28
|
+
this.c2 = 0;
|
29
|
+
this.c3 = 0;
|
30
|
+
}
|
31
|
+
/**
|
32
|
+
* Compute coefficients for a cubic polynomial
|
33
|
+
* p(s) = c0 + c1*s + c2*s^2 + c3*s^3
|
34
|
+
* such that
|
35
|
+
* p(0) = x0, p(1) = x1
|
36
|
+
* and
|
37
|
+
* p'(0) = t0, p'(1) = t1.
|
38
|
+
*/
|
39
|
+
CubicPoly.prototype.init = function (x0, x1, t0, t1) {
|
40
|
+
this.c0 = x0;
|
41
|
+
this.c1 = t0;
|
42
|
+
this.c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
|
43
|
+
this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
|
44
|
+
};
|
45
|
+
/**
|
46
|
+
* Initialize for Catmull-Rom interpolation
|
47
|
+
*/
|
48
|
+
CubicPoly.prototype.initCatmullRom = function (x0, x1, x2, x3, tension) {
|
49
|
+
this.init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
|
50
|
+
};
|
51
|
+
/**
|
52
|
+
* Initialize for non-uniform Catmull-Rom interpolation
|
53
|
+
*/
|
54
|
+
CubicPoly.prototype.initNonuniformCatmullRom = function (x0, x1, x2, x3, dt0, dt1, dt2) {
|
55
|
+
// compute tangents when parameterized in [t1,t2]
|
56
|
+
var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
|
57
|
+
var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2;
|
58
|
+
// rescale tangents for parametrization in [0,1]
|
59
|
+
t1 *= dt1;
|
60
|
+
t2 *= dt1;
|
61
|
+
this.init(x1, x2, t1, t2);
|
62
|
+
};
|
63
|
+
/**
|
64
|
+
* Calculate the polynomial value at parameter t
|
65
|
+
*/
|
66
|
+
CubicPoly.prototype.calc = function (t) {
|
67
|
+
var t2 = t * t;
|
68
|
+
var t3 = t2 * t;
|
69
|
+
return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
|
70
|
+
};
|
71
|
+
return CubicPoly;
|
72
|
+
}());
|
73
|
+
/**
|
74
|
+
* A curve representing a Catmull-Rom spline.
|
75
|
+
*
|
76
|
+
* ```js
|
77
|
+
* //Create a closed wavey loop
|
78
|
+
* const curve = new AcGeCatmullRomCurve3d( [
|
79
|
+
* new AcGePoint3d( -10, 0, 10 ),
|
80
|
+
* new AcGePoint3d( -5, 5, 5 ),
|
81
|
+
* new AcGePoint3d( 0, 0, 0 ),
|
82
|
+
* new AcGePoint3d( 5, -5, 5 ),
|
83
|
+
* new AcGePoint3d( 10, 0, 10 )
|
84
|
+
* ], true ); // true for closed curve
|
85
|
+
*
|
86
|
+
* const points = curve.getPoints( 50 );
|
87
|
+
*
|
88
|
+
* // Convert to NURBS curve
|
89
|
+
* const nurbsCurve = curve.toNurbsCurve();
|
90
|
+
* ```
|
91
|
+
*/
|
92
|
+
var AcGeCatmullRomCurve3d = /** @class */ (function (_super) {
|
93
|
+
__extends(AcGeCatmullRomCurve3d, _super);
|
94
|
+
/**
|
95
|
+
* Constructs a new Catmull-Rom curve.
|
96
|
+
*
|
97
|
+
* @param points - An array of 3D points defining the curve.
|
98
|
+
* @param closed - Whether the curve is closed or not.
|
99
|
+
* @param curveType - The curve type.
|
100
|
+
* @param tension - Tension of the curve.
|
101
|
+
*/
|
102
|
+
function AcGeCatmullRomCurve3d(points, closed, curveType, tension) {
|
103
|
+
if (points === void 0) { points = []; }
|
104
|
+
if (closed === void 0) { closed = false; }
|
105
|
+
if (curveType === void 0) { curveType = 'centripetal'; }
|
106
|
+
if (tension === void 0) { tension = 0.5; }
|
107
|
+
var _this = _super.call(this) || this;
|
108
|
+
/**
|
109
|
+
* This flag can be used for type testing.
|
110
|
+
*/
|
111
|
+
_this.isCatmullRomCurve3d = true;
|
112
|
+
/**
|
113
|
+
* The curve type identifier
|
114
|
+
*/
|
115
|
+
_this.type = 'CatmullRomCurve3d';
|
116
|
+
// Internal computation objects
|
117
|
+
_this._tmp = new AcGeVector3d();
|
118
|
+
_this._px = new CubicPoly();
|
119
|
+
_this._py = new CubicPoly();
|
120
|
+
_this._pz = new CubicPoly();
|
121
|
+
_this._points = points.map(function (p) { return new AcGePoint3d(p); });
|
122
|
+
_this._closed = closed;
|
123
|
+
_this._curveType = curveType;
|
124
|
+
_this._tension = tension;
|
125
|
+
return _this;
|
126
|
+
}
|
127
|
+
Object.defineProperty(AcGeCatmullRomCurve3d.prototype, "points", {
|
128
|
+
/**
|
129
|
+
* An array of 3D points defining the curve.
|
130
|
+
*/
|
131
|
+
get: function () {
|
132
|
+
return this._points;
|
133
|
+
},
|
134
|
+
enumerable: false,
|
135
|
+
configurable: true
|
136
|
+
});
|
137
|
+
Object.defineProperty(AcGeCatmullRomCurve3d.prototype, "closed", {
|
138
|
+
/**
|
139
|
+
* Whether the curve is closed or not.
|
140
|
+
*/
|
141
|
+
get: function () {
|
142
|
+
return this._closed;
|
143
|
+
},
|
144
|
+
enumerable: false,
|
145
|
+
configurable: true
|
146
|
+
});
|
147
|
+
Object.defineProperty(AcGeCatmullRomCurve3d.prototype, "curveType", {
|
148
|
+
/**
|
149
|
+
* The curve type.
|
150
|
+
*/
|
151
|
+
get: function () {
|
152
|
+
return this._curveType;
|
153
|
+
},
|
154
|
+
enumerable: false,
|
155
|
+
configurable: true
|
156
|
+
});
|
157
|
+
Object.defineProperty(AcGeCatmullRomCurve3d.prototype, "tension", {
|
158
|
+
/**
|
159
|
+
* Tension of the curve.
|
160
|
+
*/
|
161
|
+
get: function () {
|
162
|
+
return this._tension;
|
163
|
+
},
|
164
|
+
enumerable: false,
|
165
|
+
configurable: true
|
166
|
+
});
|
167
|
+
Object.defineProperty(AcGeCatmullRomCurve3d.prototype, "startPoint", {
|
168
|
+
/**
|
169
|
+
* Start point of this curve.
|
170
|
+
*/
|
171
|
+
get: function () {
|
172
|
+
return this._points.length > 0 ? this._points[0] : new AcGePoint3d();
|
173
|
+
},
|
174
|
+
enumerable: false,
|
175
|
+
configurable: true
|
176
|
+
});
|
177
|
+
Object.defineProperty(AcGeCatmullRomCurve3d.prototype, "endPoint", {
|
178
|
+
/**
|
179
|
+
* End point of this curve.
|
180
|
+
*/
|
181
|
+
get: function () {
|
182
|
+
return this._points.length > 0
|
183
|
+
? this._points[this._points.length - 1]
|
184
|
+
: new AcGePoint3d();
|
185
|
+
},
|
186
|
+
enumerable: false,
|
187
|
+
configurable: true
|
188
|
+
});
|
189
|
+
Object.defineProperty(AcGeCatmullRomCurve3d.prototype, "length", {
|
190
|
+
/**
|
191
|
+
* Length of this curve (approximated).
|
192
|
+
*/
|
193
|
+
get: function () {
|
194
|
+
if (this._points.length < 2)
|
195
|
+
return 0;
|
196
|
+
var totalLength = 0;
|
197
|
+
for (var i = 1; i < this._points.length; i++) {
|
198
|
+
totalLength += this._points[i - 1].distanceTo(this._points[i]);
|
199
|
+
}
|
200
|
+
if (this._closed && this._points.length > 2) {
|
201
|
+
totalLength += this._points[this._points.length - 1].distanceTo(this._points[0]);
|
202
|
+
}
|
203
|
+
return totalLength;
|
204
|
+
},
|
205
|
+
enumerable: false,
|
206
|
+
configurable: true
|
207
|
+
});
|
208
|
+
/**
|
209
|
+
* Returns a point on the curve.
|
210
|
+
*
|
211
|
+
* @param t - A interpolation factor representing a position on the curve. Must be in the range `[0,1]`.
|
212
|
+
* @param optionalTarget - The optional target vector the result is written to.
|
213
|
+
* @return The position on the curve.
|
214
|
+
*/
|
215
|
+
AcGeCatmullRomCurve3d.prototype.getPoint = function (t, optionalTarget) {
|
216
|
+
if (optionalTarget === void 0) { optionalTarget = new AcGePoint3d(); }
|
217
|
+
var point = optionalTarget;
|
218
|
+
var points = this._points;
|
219
|
+
var l = points.length;
|
220
|
+
if (l === 0) {
|
221
|
+
return point.set(0, 0, 0);
|
222
|
+
}
|
223
|
+
if (l === 1) {
|
224
|
+
return point.copy(points[0]);
|
225
|
+
}
|
226
|
+
var p = (l - (this._closed ? 0 : 1)) * t;
|
227
|
+
var intPoint = Math.floor(p);
|
228
|
+
var weight = p - intPoint;
|
229
|
+
if (this._closed) {
|
230
|
+
intPoint +=
|
231
|
+
intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
|
232
|
+
}
|
233
|
+
else if (weight === 0 && intPoint === l - 1) {
|
234
|
+
intPoint = l - 2;
|
235
|
+
weight = 1;
|
236
|
+
}
|
237
|
+
var p0, p3; // 4 points (p1 & p2 defined below)
|
238
|
+
if (this._closed || intPoint > 0) {
|
239
|
+
p0 = points[(intPoint - 1) % l];
|
240
|
+
}
|
241
|
+
else {
|
242
|
+
// extrapolate first point
|
243
|
+
this._tmp.subVectors(points[0], points[1]).add(points[0]);
|
244
|
+
p0 = new AcGePoint3d(this._tmp.x, this._tmp.y, this._tmp.z);
|
245
|
+
}
|
246
|
+
var p1 = points[intPoint % l];
|
247
|
+
var p2 = points[(intPoint + 1) % l];
|
248
|
+
if (this._closed || intPoint + 2 < l) {
|
249
|
+
p3 = points[(intPoint + 2) % l];
|
250
|
+
}
|
251
|
+
else {
|
252
|
+
// extrapolate last point
|
253
|
+
this._tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
|
254
|
+
p3 = new AcGePoint3d(this._tmp.x, this._tmp.y, this._tmp.z);
|
255
|
+
}
|
256
|
+
if (this._curveType === 'centripetal' || this._curveType === 'chordal') {
|
257
|
+
// init Centripetal / Chordal Catmull-Rom
|
258
|
+
var pow = this._curveType === 'chordal' ? 0.5 : 0.25;
|
259
|
+
var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
|
260
|
+
var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
|
261
|
+
var dt2 = Math.pow(p2.distanceToSquared(p3), pow);
|
262
|
+
// safety check for repeated points
|
263
|
+
if (dt1 < 1e-4)
|
264
|
+
dt1 = 1.0;
|
265
|
+
if (dt0 < 1e-4)
|
266
|
+
dt0 = dt1;
|
267
|
+
if (dt2 < 1e-4)
|
268
|
+
dt2 = dt1;
|
269
|
+
this._px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
|
270
|
+
this._py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
|
271
|
+
this._pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
|
272
|
+
}
|
273
|
+
else if (this._curveType === 'catmullrom') {
|
274
|
+
this._px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this._tension);
|
275
|
+
this._py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this._tension);
|
276
|
+
this._pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this._tension);
|
277
|
+
}
|
278
|
+
point.set(this._px.calc(weight), this._py.calc(weight), this._pz.calc(weight));
|
279
|
+
return point;
|
280
|
+
};
|
281
|
+
/**
|
282
|
+
* Get an array of points along the curve
|
283
|
+
* @param divisions - Number of divisions to create
|
284
|
+
* @returns Array of points along the curve
|
285
|
+
*/
|
286
|
+
AcGeCatmullRomCurve3d.prototype.getPoints = function (divisions) {
|
287
|
+
var points = [];
|
288
|
+
for (var d = 0; d <= divisions; d++) {
|
289
|
+
points.push(this.getPoint(d / divisions));
|
290
|
+
}
|
291
|
+
return points;
|
292
|
+
};
|
293
|
+
/**
|
294
|
+
* Set the points defining the curve
|
295
|
+
* @param points - Array of points
|
296
|
+
*/
|
297
|
+
AcGeCatmullRomCurve3d.prototype.setPoints = function (points) {
|
298
|
+
this._points = points.map(function (p) { return new AcGePoint3d(p); });
|
299
|
+
this._boundingBoxNeedsUpdate = true;
|
300
|
+
};
|
301
|
+
/**
|
302
|
+
* Set whether the curve is closed
|
303
|
+
* @param closed - Whether the curve should be closed
|
304
|
+
*/
|
305
|
+
AcGeCatmullRomCurve3d.prototype.setClosed = function (closed) {
|
306
|
+
if (this._closed === closed) {
|
307
|
+
return;
|
308
|
+
}
|
309
|
+
this._closed = closed;
|
310
|
+
this._boundingBoxNeedsUpdate = true;
|
311
|
+
};
|
312
|
+
/**
|
313
|
+
* Set the curve type
|
314
|
+
* @param curveType - The curve type
|
315
|
+
*/
|
316
|
+
AcGeCatmullRomCurve3d.prototype.setCurveType = function (curveType) {
|
317
|
+
this._curveType = curveType;
|
318
|
+
};
|
319
|
+
/**
|
320
|
+
* Set the tension of the curve
|
321
|
+
* @param tension - The tension value
|
322
|
+
*/
|
323
|
+
AcGeCatmullRomCurve3d.prototype.setTension = function (tension) {
|
324
|
+
this._tension = tension;
|
325
|
+
};
|
326
|
+
/**
|
327
|
+
* Transforms the curve by applying the input matrix.
|
328
|
+
* @param matrix Input transformation matrix
|
329
|
+
* @return Return this curve
|
330
|
+
*/
|
331
|
+
AcGeCatmullRomCurve3d.prototype.transform = function (matrix) {
|
332
|
+
this._points = this._points.map(function (point) {
|
333
|
+
var transformedPoint = new AcGePoint3d();
|
334
|
+
transformedPoint.copy(point);
|
335
|
+
transformedPoint.applyMatrix3d(matrix);
|
336
|
+
return transformedPoint;
|
337
|
+
});
|
338
|
+
this._boundingBoxNeedsUpdate = true;
|
339
|
+
return this;
|
340
|
+
};
|
341
|
+
/**
|
342
|
+
* Calculate the bounding box of this curve.
|
343
|
+
* @return The bounding box
|
344
|
+
*/
|
345
|
+
AcGeCatmullRomCurve3d.prototype.calculateBoundingBox = function () {
|
346
|
+
if (this._points.length === 0) {
|
347
|
+
return new AcGeBox3d();
|
348
|
+
}
|
349
|
+
var box = new AcGeBox3d();
|
350
|
+
this._points.forEach(function (point) {
|
351
|
+
box.expandByPoint(point);
|
352
|
+
});
|
353
|
+
return box;
|
354
|
+
};
|
355
|
+
return AcGeCatmullRomCurve3d;
|
356
|
+
}(AcGeCurve3d));
|
357
|
+
export { AcGeCatmullRomCurve3d };
|
358
|
+
//# sourceMappingURL=AcGeCatmullRomCurve3d.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"AcGeCatmullRomCurve3d.js","sourceRoot":"","sources":["../../src/geometry/AcGeCatmullRomCurve3d.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EACL,SAAS,EAET,WAAW,EAEX,YAAY,EACb,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAgB3C;;;;;GAKG;AACH;IAAA;QACU,OAAE,GAAG,CAAC,CAAA;QACN,OAAE,GAAG,CAAC,CAAA;QACN,OAAE,GAAG,CAAC,CAAA;QACN,OAAE,GAAG,CAAC,CAAA;IA6DhB,CAAC;IA3DC;;;;;;;OAOG;IACK,wBAAI,GAAZ,UAAa,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,EAAU;QACzD,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;QACZ,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;QACZ,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,CAAA;QACxC,IAAI,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA;IACrC,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AG,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;QAC1B,CAAC,CAAC,CAAA;QACF,OAAO,GAAG,CAAA;IACZ,CAAC;IACH,4BAAC;AAAD,CAAC,AAlSD,CAA2C,WAAW,GAkSrD"}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import { AcGePoint3dLike } from '../math';
|
2
|
+
/**
|
3
|
+
* Type for NURBS knot parameterization
|
4
|
+
*/
|
5
|
+
export type AcGeKnotParameterizationType = 'Uniform' | 'Chord' | 'SqrtChord';
|
6
|
+
/**
|
7
|
+
* A NURBS curve implementation that can be used by other curve classes
|
8
|
+
*/
|
9
|
+
export declare class AcGeNurbsCurve {
|
10
|
+
private _degree;
|
11
|
+
private _knots;
|
12
|
+
private _controlPoints;
|
13
|
+
private _weights;
|
14
|
+
constructor(degree: number, knots: number[], controlPoints: AcGePoint3dLike[], weights?: number[]);
|
15
|
+
/**
|
16
|
+
* Get the degree of the NURBS curve
|
17
|
+
*/
|
18
|
+
degree(): number;
|
19
|
+
/**
|
20
|
+
* Get the knot vector
|
21
|
+
*/
|
22
|
+
knots(): number[];
|
23
|
+
/**
|
24
|
+
* Get the control points
|
25
|
+
*/
|
26
|
+
controlPoints(): AcGePoint3dLike[];
|
27
|
+
/**
|
28
|
+
* Get the weights
|
29
|
+
*/
|
30
|
+
weights(): number[];
|
31
|
+
/**
|
32
|
+
* Calculate a point on the curve at parameter u
|
33
|
+
*/
|
34
|
+
point(u: number): number[];
|
35
|
+
/**
|
36
|
+
* Calculate curve length using numerical integration
|
37
|
+
*/
|
38
|
+
length(): number;
|
39
|
+
/**
|
40
|
+
* Create a NURBS curve from control points and knots
|
41
|
+
*/
|
42
|
+
static byKnotsControlPointsWeights(degree: number, knots: number[], controlPoints: AcGePoint3dLike[], weights?: number[]): AcGeNurbsCurve;
|
43
|
+
/**
|
44
|
+
* Create a NURBS curve from fit points using interpolation
|
45
|
+
*/
|
46
|
+
static byPoints(points: number[][], degree: number, parameterization?: AcGeKnotParameterizationType): AcGeNurbsCurve;
|
47
|
+
/**
|
48
|
+
* Get the valid parameter range for this curve
|
49
|
+
*/
|
50
|
+
getParameterRange(): {
|
51
|
+
start: number;
|
52
|
+
end: number;
|
53
|
+
};
|
54
|
+
/**
|
55
|
+
* Get points along the curve
|
56
|
+
* @param divisions - Number of divisions to create
|
57
|
+
* @returns Array of points along the curve
|
58
|
+
*/
|
59
|
+
getPoints(divisions: number): number[][];
|
60
|
+
/**
|
61
|
+
* Check if the curve is closed by comparing start and end points
|
62
|
+
*/
|
63
|
+
isClosed(tolerance?: number): boolean;
|
64
|
+
/**
|
65
|
+
* Create a closed NURBS curve using Catmull-Rom interpolation for smooth closure
|
66
|
+
*/
|
67
|
+
static createClosedCurve(points: AcGePoint3dLike[], degree: number, parameterization?: AcGeKnotParameterizationType): AcGeNurbsCurve;
|
68
|
+
}
|
69
|
+
//# sourceMappingURL=AcGeNurbsCurve.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"AcGeNurbsCurve.d.ts","sourceRoot":"","sources":["../../src/geometry/AcGeNurbsCurve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAUzC;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,SAAS,GAAG,OAAO,GAAG,WAAW,CAAA;AAE5E;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,cAAc,CAAmB;IACzC,OAAO,CAAC,QAAQ,CAAU;gBAGxB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EAAE,EACf,aAAa,EAAE,eAAe,EAAE,EAChC,OAAO,CAAC,EAAE,MAAM,EAAE;IAUpB;;OAEG;IACH,MAAM,IAAI,MAAM;IAIhB;;OAEG;IACH,KAAK,IAAI,MAAM,EAAE;IAIjB;;OAEG;IACH,aAAa,IAAI,eAAe,EAAE;IAIlC;;OAEG;IACH,OAAO,IAAI,MAAM,EAAE;IAInB;;OAEG;IACH,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE;IAY1B;;OAEG;IACH,MAAM,IAAI,MAAM;IAWhB;;OAEG;IACH,MAAM,CAAC,2BAA2B,CAChC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EAAE,EACf,aAAa,EAAE,eAAe,EAAE,EAChC,OAAO,CAAC,EAAE,MAAM,EAAE,GACjB,cAAc;IAIjB;;OAEG;IACH,MAAM,CAAC,QAAQ,CACb,MAAM,EAAE,MAAM,EAAE,EAAE,EAClB,MAAM,EAAE,MAAM,EACd,gBAAgB,GAAE,4BAAwC,GACzD,cAAc;IAuBjB;;OAEG;IACH,iBAAiB,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE;IAMnD;;;;OAIG;IACH,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE;IAYxC;;OAEG;IACH,QAAQ,CAAC,SAAS,GAAE,MAAa,GAAG,OAAO;IAY3C;;OAEG;IACH,MAAM,CAAC,iBAAiB,CACtB,MAAM,EAAE,eAAe,EAAE,EACzB,MAAM,EAAE,MAAM,EACd,gBAAgB,GAAE,4BAAsC,GACvD,cAAc;CAuBlB"}
|
@@ -0,0 +1,166 @@
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
3
|
+
if (!m) return o;
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
5
|
+
try {
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
7
|
+
}
|
8
|
+
catch (error) { e = { error: error }; }
|
9
|
+
finally {
|
10
|
+
try {
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
12
|
+
}
|
13
|
+
finally { if (e) throw e.error; }
|
14
|
+
}
|
15
|
+
return ar;
|
16
|
+
};
|
17
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
18
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
19
|
+
if (ar || !(i in from)) {
|
20
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
21
|
+
ar[i] = from[i];
|
22
|
+
}
|
23
|
+
}
|
24
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
25
|
+
};
|
26
|
+
import { calculateCurveLength, evaluateNurbsPoint, generateChordKnots, generateSqrtChordKnots, generateUniformKnots } from '../util';
|
27
|
+
import { AcGeCatmullRomCurve3d } from './AcGeCatmullRomCurve3d';
|
28
|
+
/**
|
29
|
+
* A NURBS curve implementation that can be used by other curve classes
|
30
|
+
*/
|
31
|
+
var AcGeNurbsCurve = /** @class */ (function () {
|
32
|
+
function AcGeNurbsCurve(degree, knots, controlPoints, weights) {
|
33
|
+
this._degree = degree;
|
34
|
+
this._knots = __spreadArray([], __read(knots), false);
|
35
|
+
this._controlPoints = controlPoints.map(function (p) { return ({ x: p.x, y: p.y, z: p.z }); });
|
36
|
+
this._weights = weights
|
37
|
+
? __spreadArray([], __read(weights), false) : new Array(controlPoints.length).fill(1.0);
|
38
|
+
}
|
39
|
+
/**
|
40
|
+
* Get the degree of the NURBS curve
|
41
|
+
*/
|
42
|
+
AcGeNurbsCurve.prototype.degree = function () {
|
43
|
+
return this._degree;
|
44
|
+
};
|
45
|
+
/**
|
46
|
+
* Get the knot vector
|
47
|
+
*/
|
48
|
+
AcGeNurbsCurve.prototype.knots = function () {
|
49
|
+
return __spreadArray([], __read(this._knots), false);
|
50
|
+
};
|
51
|
+
/**
|
52
|
+
* Get the control points
|
53
|
+
*/
|
54
|
+
AcGeNurbsCurve.prototype.controlPoints = function () {
|
55
|
+
return this._controlPoints.map(function (p) { return ({ x: p.x, y: p.y, z: p.z }); });
|
56
|
+
};
|
57
|
+
/**
|
58
|
+
* Get the weights
|
59
|
+
*/
|
60
|
+
AcGeNurbsCurve.prototype.weights = function () {
|
61
|
+
return __spreadArray([], __read(this._weights), false);
|
62
|
+
};
|
63
|
+
/**
|
64
|
+
* Calculate a point on the curve at parameter u
|
65
|
+
*/
|
66
|
+
AcGeNurbsCurve.prototype.point = function (u) {
|
67
|
+
// Convert AcGePoint3dLike[] to number[][] for utility functions
|
68
|
+
var controlPointsArray = this._controlPoints.map(function (p) { return [p.x, p.y, p.z]; });
|
69
|
+
return evaluateNurbsPoint(u, this._degree, this._knots, controlPointsArray, this._weights);
|
70
|
+
};
|
71
|
+
/**
|
72
|
+
* Calculate curve length using numerical integration
|
73
|
+
*/
|
74
|
+
AcGeNurbsCurve.prototype.length = function () {
|
75
|
+
// Convert AcGePoint3dLike[] to number[][] for utility functions
|
76
|
+
var controlPointsArray = this._controlPoints.map(function (p) { return [p.x, p.y, p.z]; });
|
77
|
+
return calculateCurveLength(this._degree, this._knots, controlPointsArray, this._weights);
|
78
|
+
};
|
79
|
+
/**
|
80
|
+
* Create a NURBS curve from control points and knots
|
81
|
+
*/
|
82
|
+
AcGeNurbsCurve.byKnotsControlPointsWeights = function (degree, knots, controlPoints, weights) {
|
83
|
+
return new AcGeNurbsCurve(degree, knots, controlPoints, weights);
|
84
|
+
};
|
85
|
+
/**
|
86
|
+
* Create a NURBS curve from fit points using interpolation
|
87
|
+
*/
|
88
|
+
AcGeNurbsCurve.byPoints = function (points, degree, parameterization) {
|
89
|
+
if (parameterization === void 0) { parameterization = 'Uniform'; }
|
90
|
+
// Generate knots based on parameterization type
|
91
|
+
var knots;
|
92
|
+
switch (parameterization) {
|
93
|
+
case 'Chord':
|
94
|
+
knots = generateChordKnots(degree, points);
|
95
|
+
break;
|
96
|
+
case 'SqrtChord':
|
97
|
+
knots = generateSqrtChordKnots(degree, points);
|
98
|
+
break;
|
99
|
+
case 'Uniform':
|
100
|
+
default:
|
101
|
+
knots = generateUniformKnots(degree, points.length);
|
102
|
+
break;
|
103
|
+
}
|
104
|
+
// Convert number[][] to AcGePoint3dLike[] for control points
|
105
|
+
var controlPoints = points.map(function (p) { return ({ x: p[0], y: p[1], z: p[2] }); });
|
106
|
+
var weights = new Array(controlPoints.length).fill(1.0);
|
107
|
+
return new AcGeNurbsCurve(degree, knots, controlPoints, weights);
|
108
|
+
};
|
109
|
+
/**
|
110
|
+
* Get the valid parameter range for this curve
|
111
|
+
*/
|
112
|
+
AcGeNurbsCurve.prototype.getParameterRange = function () {
|
113
|
+
var startParam = this._knots[this._degree];
|
114
|
+
var endParam = this._knots[this._knots.length - this._degree - 1];
|
115
|
+
return { start: startParam, end: endParam };
|
116
|
+
};
|
117
|
+
/**
|
118
|
+
* Get points along the curve
|
119
|
+
* @param divisions - Number of divisions to create
|
120
|
+
* @returns Array of points along the curve
|
121
|
+
*/
|
122
|
+
AcGeNurbsCurve.prototype.getPoints = function (divisions) {
|
123
|
+
var points = [];
|
124
|
+
var _a = this.getParameterRange(), start = _a.start, end = _a.end;
|
125
|
+
for (var i = 0; i <= divisions; i++) {
|
126
|
+
var t = start + (end - start) * (i / divisions);
|
127
|
+
points.push(this.point(t));
|
128
|
+
}
|
129
|
+
return points;
|
130
|
+
};
|
131
|
+
/**
|
132
|
+
* Check if the curve is closed by comparing start and end points
|
133
|
+
*/
|
134
|
+
AcGeNurbsCurve.prototype.isClosed = function (tolerance) {
|
135
|
+
if (tolerance === void 0) { tolerance = 1e-6; }
|
136
|
+
var _a = this.getParameterRange(), start = _a.start, end = _a.end;
|
137
|
+
var startPoint = this.point(start);
|
138
|
+
var endPoint = this.point(end);
|
139
|
+
var dx = startPoint[0] - endPoint[0];
|
140
|
+
var dy = startPoint[1] - endPoint[1];
|
141
|
+
var dz = startPoint[2] - endPoint[2];
|
142
|
+
return Math.sqrt(dx * dx + dy * dy + dz * dz) < tolerance;
|
143
|
+
};
|
144
|
+
/**
|
145
|
+
* Create a closed NURBS curve using Catmull-Rom interpolation for smooth closure
|
146
|
+
*/
|
147
|
+
AcGeNurbsCurve.createClosedCurve = function (points, degree, parameterization) {
|
148
|
+
if (parameterization === void 0) { parameterization = 'Chord'; }
|
149
|
+
if (points.length < 4) {
|
150
|
+
throw new Error('At least 4 points are required for a closed NURBS curve');
|
151
|
+
}
|
152
|
+
// Create a closed Catmull-Rom curve
|
153
|
+
var catmullRomCurve = new AcGeCatmullRomCurve3d(points, true, 'centripetal');
|
154
|
+
// Get points along the curve for NURBS interpolation
|
155
|
+
// Use more divisions for smoother curve
|
156
|
+
var divisions = Math.max(50, points.length * 2);
|
157
|
+
var curvePoints = catmullRomCurve.getPoints(divisions);
|
158
|
+
// Convert AcGePoint3d[] back to number[][]
|
159
|
+
var nurbsPoints = curvePoints.map(function (point) { return [point.x, point.y, point.z]; });
|
160
|
+
// Create NURBS curve from the interpolated points
|
161
|
+
return AcGeNurbsCurve.byPoints(nurbsPoints, degree, parameterization);
|
162
|
+
};
|
163
|
+
return AcGeNurbsCurve;
|
164
|
+
}());
|
165
|
+
export { AcGeNurbsCurve };
|
166
|
+
//# sourceMappingURL=AcGeNurbsCurve.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"AcGeNurbsCurve.js","sourceRoot":"","sources":["../../src/geometry/AcGeNurbsCurve.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACrB,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAO/D;;GAEG;AACH;IAME,wBACE,MAAc,EACd,KAAe,EACf,aAAgC,EAChC,OAAkB;QAElB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QACrB,IAAI,CAAC,MAAM,4BAAO,KAAK,SAAC,CAAA;QACxB,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAA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