@mlightcad/data-model 1.1.4 → 1.1.6

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.
@@ -1234,6 +1234,23 @@ class Hn {
1234
1234
  }, this.onError = () => {
1235
1235
  };
1236
1236
  }
1237
+ /**
1238
+ * Schedules a task to be executed asynchronously.
1239
+ *
1240
+ * This method uses requestAnimationFrame in browser environments or setTimeout
1241
+ * in Node.js environments to schedule the task.
1242
+ *
1243
+ * @param callback - The callback function to schedule
1244
+ * @returns Promise that resolves with the result of the callback
1245
+ */
1246
+ scheduleTask(t) {
1247
+ return new Promise((e, s) => {
1248
+ const n = () => {
1249
+ Promise.resolve(t()).then(e).catch(s);
1250
+ };
1251
+ typeof window < "u" && typeof window.requestAnimationFrame == "function" ? window.requestAnimationFrame(n) : setTimeout(n, 0);
1252
+ });
1253
+ }
1237
1254
  /**
1238
1255
  * Adds a task to the execution queue.
1239
1256
  *
@@ -1269,15 +1286,9 @@ class Hn {
1269
1286
  for (let n = 0; n < e; n++) {
1270
1287
  const i = this.tasks[n];
1271
1288
  try {
1272
- s = await new Promise((a, o) => {
1273
- setTimeout(async () => {
1274
- try {
1275
- const c = await i.run(s);
1276
- this.onProgress((n + 1) / e, i), a(c);
1277
- } catch (c) {
1278
- o(c);
1279
- }
1280
- }, 0);
1289
+ s = await this.scheduleTask(async () => {
1290
+ const a = await i.run(s);
1291
+ return this.onProgress((n + 1) / e, i), a;
1281
1292
  });
1282
1293
  } catch (a) {
1283
1294
  this.onError(a, n, i);
@@ -1544,16 +1555,22 @@ class Yn {
1544
1555
  * in Node.js environments to schedule the task.
1545
1556
  *
1546
1557
  * @param callback - The callback function to schedule
1558
+ * @returns Promise that resolves when the task completes
1547
1559
  *
1548
1560
  * @example
1549
1561
  * ```typescript
1550
- * batchProcessor.scheduleTask(() => {
1562
+ * await batchProcessor.scheduleTask(async () => {
1551
1563
  * // Task to be executed asynchronously
1552
1564
  * });
1553
1565
  * ```
1554
1566
  */
1555
1567
  scheduleTask(t) {
1556
- typeof window < "u" && typeof window.requestAnimationFrame == "function" ? window.requestAnimationFrame(t) : setTimeout(t, 0);
1568
+ return new Promise((e, s) => {
1569
+ const n = () => {
1570
+ Promise.resolve(t()).then(e).catch(s);
1571
+ };
1572
+ typeof window < "u" && typeof window.requestAnimationFrame == "function" ? window.requestAnimationFrame(n) : setTimeout(n, 0);
1573
+ });
1557
1574
  }
1558
1575
  /**
1559
1576
  * Processes items in chunks using the provided callback function.
@@ -1578,7 +1595,7 @@ class Yn {
1578
1595
  let e = 0;
1579
1596
  const s = async () => {
1580
1597
  const n = e, i = Math.min(e + this._chunkSize, this._count);
1581
- await t(n, i), e = i, e < this._count && this.scheduleTask(s);
1598
+ await t(n, i), e = i, e < this._count && await this.scheduleTask(s);
1582
1599
  };
1583
1600
  await s();
1584
1601
  }
@@ -9194,28 +9211,29 @@ class ut {
9194
9211
  }
9195
9212
  }
9196
9213
  class Ut extends Ee {
9197
- constructor(t, e, s, n) {
9214
+ constructor(t, e, s, n, i) {
9198
9215
  super();
9199
- const i = +(t !== void 0) + +(e !== void 0) + +(s !== void 0) + +(n !== void 0);
9200
- if (i < 2 || i > 4)
9216
+ const a = arguments.length;
9217
+ if (a < 2 || a > 5)
9201
9218
  throw ot.ILLEGAL_PARAMETERS;
9202
- const a = 3;
9203
- if (this._closed = n || !1, Array.isArray(e)) {
9204
- if (this._controlPoints = t, i >= 4 && (this._closed = n), this._controlPoints.length < 4)
9219
+ if (this._degree = 3, this._closed = !1, Array.isArray(e)) {
9220
+ this._controlPoints = t;
9221
+ let o, c = 3, l = !1;
9222
+ if (a >= 3 && (Array.isArray(s) ? (o = s, a >= 4 && (c = n || 3), a >= 5 && (l = i)) : s !== void 0 && (c = s || 3, a >= 4 && (l = n))), s === void 0 && a >= 4 && (c = n || 3, a >= 5 && (l = i)), this._degree = c, this._closed = l, this._controlPoints.length < this._degree + 1)
9205
9223
  throw ot.ILLEGAL_PARAMETERS;
9206
9224
  this._nurbsCurve = ut.byKnotsControlPointsWeights(
9207
- a,
9225
+ this._degree,
9208
9226
  e,
9209
9227
  this._controlPoints,
9210
- s
9228
+ o
9211
9229
  );
9212
9230
  } else {
9213
- if (this._fitPoints = t, this._knotParameterization = e, i >= 3 && (this._closed = s), this._fitPoints.length < 4)
9231
+ if (this._fitPoints = t, this._knotParameterization = e, a >= 3 && (this._degree = s || 3), a >= 4 && (this._closed = n), this._fitPoints.length < this._degree + 1)
9214
9232
  throw ot.ILLEGAL_PARAMETERS;
9215
9233
  const o = this.toNurbsPoints(this._fitPoints);
9216
9234
  this._nurbsCurve = ut.byPoints(
9217
9235
  o,
9218
- a,
9236
+ this._degree,
9219
9237
  this._knotParameterization
9220
9238
  ), this._controlPoints = this._nurbsCurve.controlPoints();
9221
9239
  }
@@ -9229,14 +9247,14 @@ class Ut extends Ee {
9229
9247
  if (this._closed)
9230
9248
  this._nurbsCurve = ut.createClosedCurve(
9231
9249
  this._fitPoints,
9232
- 3,
9250
+ this._degree,
9233
9251
  this._knotParameterization
9234
9252
  );
9235
9253
  else {
9236
9254
  const t = this.toNurbsPoints(this._fitPoints);
9237
9255
  this._nurbsCurve = ut.byPoints(
9238
9256
  t,
9239
- 3,
9257
+ this._degree,
9240
9258
  this._knotParameterization
9241
9259
  );
9242
9260
  }
@@ -9246,13 +9264,13 @@ class Ut extends Ee {
9246
9264
  const t = this._knotParameterization || "Chord";
9247
9265
  this._nurbsCurve = ut.createClosedCurve(
9248
9266
  this._controlPoints,
9249
- 3,
9267
+ this._degree,
9250
9268
  t
9251
9269
  ), this._controlPoints = this._nurbsCurve.controlPoints();
9252
9270
  } else {
9253
9271
  const t = this._nurbsCurve.knots(), e = this._nurbsCurve.weights();
9254
9272
  this._nurbsCurve = ut.byKnotsControlPointsWeights(
9255
- 3,
9273
+ this._degree,
9256
9274
  t,
9257
9275
  this._controlPoints,
9258
9276
  e
@@ -9269,7 +9287,7 @@ class Ut extends Ee {
9269
9287
  * Degree of the spline to be created.
9270
9288
  */
9271
9289
  get degree() {
9272
- return this._nurbsCurve.degree();
9290
+ return this._degree;
9273
9291
  }
9274
9292
  get knotParameterization() {
9275
9293
  return this._knotParameterization;
@@ -9374,12 +9392,13 @@ class Ut extends Ee {
9374
9392
  * Create a closed spline from fit points using AcGeNurbsCurve.createClosedCurve
9375
9393
  * @param fitPoints - Array of fit points defining the curve
9376
9394
  * @param parameterization - Knot parameterization type for NURBS
9395
+ * @param degree - Optional degree of the spline (default: 3)
9377
9396
  * @returns A closed spline
9378
9397
  */
9379
- static createClosedSpline(t, e = "Uniform") {
9380
- if (t.length < 4)
9381
- throw new Error("At least 4 points are required for a closed spline");
9382
- return new Ut(t, e, !0);
9398
+ static createClosedSpline(t, e = "Uniform", s = 3) {
9399
+ if (t.length < s + 1)
9400
+ throw new Error(`At least ${s + 1} points are required for a degree ${s} closed spline`);
9401
+ return new Ut(t, e, s, !0);
9383
9402
  }
9384
9403
  }
9385
9404
  var Vt = 256, Pn = [], Js = 256, Fe;
@@ -11757,20 +11776,22 @@ class oo extends Tt {
11757
11776
  }
11758
11777
  }
11759
11778
  class tr extends mt {
11760
- constructor(t, e, s, n) {
11779
+ constructor(t, e, s, n, i) {
11761
11780
  super();
11762
- const i = +(t !== void 0) + +(e !== void 0) + +(s !== void 0) + +(n !== void 0);
11763
- if (i < 2 || i > 4)
11781
+ const a = +(t !== void 0) + +(e !== void 0) + +(s !== void 0) + +(n !== void 0) + +(i !== void 0);
11782
+ if (a < 2 || a > 5)
11764
11783
  throw ot.ILLEGAL_PARAMETERS;
11765
- i <= 3 && !Array.isArray(e) ? this._geo = new Ut(
11784
+ !Array.isArray(e) ? this._geo = new Ut(
11766
11785
  t,
11767
11786
  e,
11768
- s
11787
+ s,
11788
+ n
11769
11789
  ) : this._geo = new Ut(
11770
11790
  t,
11771
11791
  e,
11772
11792
  s,
11773
- n
11793
+ n,
11794
+ i
11774
11795
  );
11775
11796
  }
11776
11797
  /**
@@ -15138,6 +15159,7 @@ class rr {
15138
15159
  t.controlPoints,
15139
15160
  t.knots,
15140
15161
  t.weights,
15162
+ t.degree,
15141
15163
  !!(t.flag & 1)
15142
15164
  );
15143
15165
  if (t.numberOfFitPoints > 0) {
@@ -15146,7 +15168,7 @@ class rr {
15146
15168
  t.numberOfFitPoints
15147
15169
  );
15148
15170
  if (e != null)
15149
- return new tr(e, "Uniform", !!(t.flag & 1));
15171
+ return new tr(e, "Uniform", t.degree, !!(t.flag & 1));
15150
15172
  }
15151
15173
  return null;
15152
15174
  }