@itwin/core-geometry 5.0.0-dev.62 → 5.0.0-dev.64

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.
Files changed (55) hide show
  1. package/lib/cjs/bspline/BSpline1dNd.d.ts +90 -54
  2. package/lib/cjs/bspline/BSpline1dNd.d.ts.map +1 -1
  3. package/lib/cjs/bspline/BSpline1dNd.js +134 -99
  4. package/lib/cjs/bspline/BSpline1dNd.js.map +1 -1
  5. package/lib/cjs/bspline/BSplineCurve.d.ts +193 -155
  6. package/lib/cjs/bspline/BSplineCurve.d.ts.map +1 -1
  7. package/lib/cjs/bspline/BSplineCurve.js +245 -181
  8. package/lib/cjs/bspline/BSplineCurve.js.map +1 -1
  9. package/lib/cjs/bspline/BezierCurve3d.d.ts +3 -1
  10. package/lib/cjs/bspline/BezierCurve3d.d.ts.map +1 -1
  11. package/lib/cjs/bspline/BezierCurve3d.js +3 -5
  12. package/lib/cjs/bspline/BezierCurve3d.js.map +1 -1
  13. package/lib/cjs/bspline/KnotVector.d.ts +74 -54
  14. package/lib/cjs/bspline/KnotVector.d.ts.map +1 -1
  15. package/lib/cjs/bspline/KnotVector.js +127 -80
  16. package/lib/cjs/bspline/KnotVector.js.map +1 -1
  17. package/lib/cjs/curve/Arc3d.d.ts +2 -0
  18. package/lib/cjs/curve/Arc3d.d.ts.map +1 -1
  19. package/lib/cjs/curve/Arc3d.js +2 -0
  20. package/lib/cjs/curve/Arc3d.js.map +1 -1
  21. package/lib/cjs/geometry3d/PointHelpers.d.ts +3 -3
  22. package/lib/cjs/geometry3d/PointHelpers.js +3 -3
  23. package/lib/cjs/geometry3d/PointHelpers.js.map +1 -1
  24. package/lib/cjs/geometry3d/Ray3d.d.ts +2 -2
  25. package/lib/cjs/geometry3d/Ray3d.d.ts.map +1 -1
  26. package/lib/cjs/geometry3d/Ray3d.js +8 -11
  27. package/lib/cjs/geometry3d/Ray3d.js.map +1 -1
  28. package/lib/esm/bspline/BSpline1dNd.d.ts +90 -54
  29. package/lib/esm/bspline/BSpline1dNd.d.ts.map +1 -1
  30. package/lib/esm/bspline/BSpline1dNd.js +134 -99
  31. package/lib/esm/bspline/BSpline1dNd.js.map +1 -1
  32. package/lib/esm/bspline/BSplineCurve.d.ts +193 -155
  33. package/lib/esm/bspline/BSplineCurve.d.ts.map +1 -1
  34. package/lib/esm/bspline/BSplineCurve.js +245 -181
  35. package/lib/esm/bspline/BSplineCurve.js.map +1 -1
  36. package/lib/esm/bspline/BezierCurve3d.d.ts +3 -1
  37. package/lib/esm/bspline/BezierCurve3d.d.ts.map +1 -1
  38. package/lib/esm/bspline/BezierCurve3d.js +3 -5
  39. package/lib/esm/bspline/BezierCurve3d.js.map +1 -1
  40. package/lib/esm/bspline/KnotVector.d.ts +74 -54
  41. package/lib/esm/bspline/KnotVector.d.ts.map +1 -1
  42. package/lib/esm/bspline/KnotVector.js +127 -80
  43. package/lib/esm/bspline/KnotVector.js.map +1 -1
  44. package/lib/esm/curve/Arc3d.d.ts +2 -0
  45. package/lib/esm/curve/Arc3d.d.ts.map +1 -1
  46. package/lib/esm/curve/Arc3d.js +2 -0
  47. package/lib/esm/curve/Arc3d.js.map +1 -1
  48. package/lib/esm/geometry3d/PointHelpers.d.ts +3 -3
  49. package/lib/esm/geometry3d/PointHelpers.js +3 -3
  50. package/lib/esm/geometry3d/PointHelpers.js.map +1 -1
  51. package/lib/esm/geometry3d/Ray3d.d.ts +2 -2
  52. package/lib/esm/geometry3d/Ray3d.d.ts.map +1 -1
  53. package/lib/esm/geometry3d/Ray3d.js +8 -11
  54. package/lib/esm/geometry3d/Ray3d.js.map +1 -1
  55. package/package.json +3 -3
@@ -5,6 +5,7 @@
5
5
  /** @packageDocumentation
6
6
  * @module Bspline
7
7
  */
8
+ import { assert } from "@itwin/core-bentley";
8
9
  import { Geometry } from "../Geometry";
9
10
  import { NumberArray } from "../geometry3d/PointHelpers";
10
11
  /**
@@ -16,68 +17,89 @@ export var BSplineWrapMode;
16
17
  (function (BSplineWrapMode) {
17
18
  /** No conversion performed. */
18
19
  BSplineWrapMode[BSplineWrapMode["None"] = 0] = "None";
19
- /** The B-spline was opened up by adding degree wrap-around control points to the legacy periodic data.
20
- * * This is typical of B-splines constructed with maximum (degree - 1) continuity.
20
+ /**
21
+ * The legacy periodic B-spline data was opened up by adding `degree` wrap-around poles.
22
+ * * This is typical of B-spline curves and surfaces constructed with maximum `degree - 1` continuity.
21
23
  * * Knots are unaffected by this conversion.
22
24
  */
23
25
  BSplineWrapMode[BSplineWrapMode["OpenByAddingControlPoints"] = 1] = "OpenByAddingControlPoints";
24
- /** The B-spline was opened up by removing degree extreme knots from the legacy periodic data.
26
+ /**
27
+ * The legacy periodic B-spline data was opened up by removing `degree` exterior knots.
25
28
  * * This is typical of rational B-spline curves representing full circles and ellipses.
26
29
  * * Poles are unaffected by this conversion.
27
30
  */
28
31
  BSplineWrapMode[BSplineWrapMode["OpenByRemovingKnots"] = 2] = "OpenByRemovingKnots";
29
32
  })(BSplineWrapMode || (BSplineWrapMode = {}));
30
33
  /**
31
- * Array of non-decreasing numbers acting as a knot array for B-splines.
34
+ * Array of non-decreasing numbers acting as a knot vector for B-spline curves and surfaces.
32
35
  *
33
36
  * * Essential identity: numKnots = numPoles + order - 2 = numPoles + degree - 1
34
- * * Various B-spline libraries have confusion over how many "end knots" are needed. Many libraries (including MicroStation and Parasolid)
35
- * demand order knots at each end for clamping. But only order-1 are really needed. This class uses the order-1 convention.
37
+ * * Various B-spline libraries have confusion over how many "end knots" are needed. Many libraries (including MicroStation
38
+ * and Parasolid) demand order knots at each end for clamping. However, only order-1 are really needed. This class uses the
39
+ * order-1 convention.
36
40
  * * A span is a single interval of the knots.
37
- * * The left knot of span {k} is knot {k+degree-1}.
41
+ * * The left knot of the span with index `k>=0` is the knot with index `k+degree-1`.
42
+ * * A knot vector is clamped when the first `degree` knots are equal and the last `degree` knots are equal.
43
+ * * The "active knot interval" is the subset of the knot vector sans its first and last `degree-1` knots, and serves as
44
+ * the parametric domain of the associated B-spline object.
38
45
  * * This class provides queries to convert among spanIndex, knotIndex, spanFraction, fraction of knot range, and knot.
39
- * * Core computations (evaluateBasisFunctions) have leftKnotIndex and global knot value as inputs. Callers need to
40
- * know their primary values (global knot, spanFraction).
46
+ * * Callers need to distinguish core computational inputs such as left knot index, knot value, span index, and span fraction.
41
47
  * @public
42
48
  */
43
49
  export class KnotVector {
44
50
  /** The simple array of knot values. */
45
51
  knots;
46
- /** Return the degree of basis functions defined in these knots. */
52
+ /** The degree of basis functions defined in these knots. */
47
53
  degree;
54
+ /** The leftmost knot value (of the active interval, ignoring unclamped leading knots). */
48
55
  _knot0;
56
+ /** The rightmost knot value (of the active interval, ignoring unclamped leading knots). */
49
57
  _knot1;
50
58
  _wrapMode;
51
- /** tolerance for considering two knots to be the same. */
59
+ /** Tolerance for considering two knots to be the same. */
52
60
  static knotTolerance = 1.0e-9;
53
- /** Return the leftmost knot value (of the active interval, ignoring unclamped leading knots)*/
54
- get leftKnot() { return this._knot0; }
55
- /** Return the rightmost knot value (of the active interval, ignoring unclamped leading knots)*/
56
- get rightKnot() { return this._knot1; }
57
- /** Return the index of the leftmost knot of the active interval */
58
- get leftKnotIndex() { return this.degree - 1; }
59
- /** Return the index of the rightmost knot of the active interval */
60
- get rightKnotIndex() { return this.knots.length - this.degree; }
61
- /** Whether this KnotVector was created by converting legacy periodic data during deserialization. The conversion used is specified by BSplineWrapMode, and is reversed at serialization time. */
62
- get wrappable() { return this._wrapMode === undefined ? BSplineWrapMode.None : this._wrapMode; }
63
- set wrappable(value) { this._wrapMode = value; }
64
- /** Return the number of bezier spans. Note that this includes zero-length spans if there are repeated knots. */
65
- get numSpans() { return this.rightKnotIndex - this.leftKnotIndex; }
61
+ /** Return the leftmost knot value (of the active interval, ignoring unclamped leading knots). */
62
+ get leftKnot() {
63
+ return this._knot0;
64
+ }
65
+ /** Return the rightmost knot value (of the active interval, ignoring unclamped leading knots). */
66
+ get rightKnot() {
67
+ return this._knot1;
68
+ }
69
+ /** Return the index of the leftmost knot of the active interval. */
70
+ get leftKnotIndex() {
71
+ return this.degree - 1;
72
+ }
73
+ /** Return the index of the rightmost knot of the active interval. */
74
+ get rightKnotIndex() {
75
+ return this.knots.length - this.degree;
76
+ }
77
+ /**
78
+ * Whether this KnotVector was created by converting legacy periodic data during deserialization. The conversion used
79
+ * is specified by BSplineWrapMode, and is reversed at serialization time.
80
+ */
81
+ get wrappable() {
82
+ return this._wrapMode === undefined ? BSplineWrapMode.None : this._wrapMode;
83
+ }
84
+ set wrappable(value) {
85
+ this._wrapMode = value;
86
+ }
87
+ /** Return the number of Bezier spans. Note that this includes zero-length spans if there are repeated knots. */
88
+ get numSpans() {
89
+ return this.rightKnotIndex - this.leftKnotIndex;
90
+ }
66
91
  /**
67
- *
68
- * * If knots is a number array or Float64Array, the those values become the local knot array.
69
- * * If knots is a simple number, the local knot array is allocated to that size but left as zeros.
70
- * @param knots
71
- * @param degree
92
+ * Private constructor.
93
+ * * If `knots` is a number array or Float64Array, then its values are copied to the instance array.
94
+ * * If `knots` is a number, the instance array is allocated to this size but left as zeros.
72
95
  */
73
96
  constructor(knots, degree, wrapMode) {
74
97
  this.degree = degree;
75
98
  this._wrapMode = wrapMode;
76
- // default values to satisfy compiler -- real values happen in setupFixedValues, or final else defers to user
99
+ // default values to satisfy compiler; real values happen in setupFixedValues or the final else clause defers to user
77
100
  this._knot0 = 0.0;
78
101
  this._knot1 = 1.0;
79
- // satisfy the initialize checker ..
80
- if (Array.isArray(knots)) { // remark: This ctor is private. The callers (as of April 2019) do not use this path.
102
+ if (Array.isArray(knots)) {
81
103
  this.knots = new Float64Array(knots.length);
82
104
  this.setKnots(knots);
83
105
  this.setupFixedValues();
@@ -86,23 +108,32 @@ export class KnotVector {
86
108
  this.knots = knots.slice();
87
109
  this.setupFixedValues();
88
110
  }
89
- else { // caller is responsible for filling array separately ...
90
- this.knots = new Float64Array(knots);
111
+ else { // caller is responsible for filling array separately
112
+ const knotSize = knots;
113
+ this.knots = new Float64Array(knotSize);
91
114
  }
92
115
  }
93
- /** copy degree and knots to a new KnotVector. */
94
- clone() { return new KnotVector(this.knots, this.degree, this.wrappable); }
116
+ /** Copy degree and knots to a new KnotVector. */
117
+ clone() {
118
+ return new KnotVector(this.knots, this.degree, this.wrappable);
119
+ }
95
120
  setupFixedValues() {
96
121
  if (this.degree > 0 && this.knots.length > this.degree) {
97
122
  this._knot0 = this.knots[this.degree - 1];
98
123
  this._knot1 = this.knots[this.knots.length - this.degree];
99
124
  }
100
125
  }
101
- /** Return the total knot distance from beginning to end. */
102
- get knotLength01() { return this._knot1 - this._knot0; }
103
126
  /**
104
- * Returns true if all numeric values have wraparound conditions that allow the knots to be closed with specified wrap mode.
105
- * @param mode optional test mode. If undefined, use this.wrappable.
127
+ * Return the length of the active knot interval.
128
+ * * This is the size of (one dimension of) the parametric domain for the associated B-spline object.
129
+ */
130
+ get knotLength01() {
131
+ return this._knot1 - this._knot0;
132
+ }
133
+ /**
134
+ * Returns true if all numeric values have wraparound conditions that allow the knots to be closed with specified
135
+ * wrap mode.
136
+ * @param mode optional test mode. If undefined, use this.wrappable.
106
137
  */
107
138
  testClosable(mode) {
108
139
  if (mode === undefined)
@@ -136,7 +167,7 @@ export class KnotVector {
136
167
  }
137
168
  return false;
138
169
  }
139
- /** Test matching degree and knot values */
170
+ /** Test matching degree and knot values. */
140
171
  isAlmostEqual(other) {
141
172
  if (this.degree !== other.degree)
142
173
  return false;
@@ -176,8 +207,9 @@ export class KnotVector {
176
207
  }
177
208
  return m;
178
209
  }
179
- /** Transform knots to span [0,1].
180
- * @returns false if and only if this.knotLength01 is trivial
210
+ /**
211
+ * Transform knots such that the active knot range becomes [0,1].
212
+ * @returns false if and only if `this.knotLength01` is trivial.
181
213
  */
182
214
  normalize() {
183
215
  if (this.knotLength01 < KnotVector.knotTolerance)
@@ -195,8 +227,7 @@ export class KnotVector {
195
227
  this.setupFixedValues();
196
228
  return true;
197
229
  }
198
- /** install knot values from an array, optionally ignoring first and last.
199
- */
230
+ /** Install knot values from an array, optionally ignoring first and last. */
200
231
  setKnots(knots, skipFirstAndLast) {
201
232
  const numAllocate = skipFirstAndLast ? knots.length - 2 : knots.length;
202
233
  if (numAllocate !== this.knots.length)
@@ -211,17 +242,17 @@ export class KnotVector {
211
242
  }
212
243
  this.setupFixedValues();
213
244
  }
214
- /** Set knots to input array (CAPTURED) */
245
+ /** Set knots to input array (CAPTURED). */
215
246
  setKnotsCapture(knots) {
216
247
  this.knots = knots;
217
248
  this.setupFixedValues();
218
249
  }
219
250
  /**
220
251
  * Create knot vector with {degree-1} replicated knots at start and end, and uniform knots between.
221
- * @param numPoles Number of poles
222
- * @param degree degree of polynomial
223
- * @param a0 left knot value for active interval
224
- * @param a1 right knot value for active interval
252
+ * @param numPoles number of poles.
253
+ * @param degree degree of polynomial.
254
+ * @param a0 left knot value for active interval.
255
+ * @param a1 right knot value for active interval.
225
256
  */
226
257
  static createUniformClamped(numPoles, degree, a0, a1) {
227
258
  const knots = new KnotVector(numPoles + degree - 1, degree);
@@ -238,24 +269,26 @@ export class KnotVector {
238
269
  }
239
270
  /**
240
271
  * Create knot vector with wraparound knots at start and end, and uniform knots between.
241
- * @param numInterval number of intervals in knot space. (NOT POLE COUNT)
242
- * @param degree degree of polynomial
243
- * @param a0 left knot value for active interval
244
- * @param a1 right knot value for active interval
272
+ * @param numInterval the number of intervals into which to uniformly divide the active knot interval `[a0,a1]`,
273
+ * creating `numInterval-1` equally spaced interior knots between `a0` and `a1`.
274
+ * This number is equal to the number of Bezier spans in the associated B-spline object.
275
+ * It is _not_ the pole count.
276
+ * @param degree degree of polynomial.
277
+ * @param a0 left knot value for active interval.
278
+ * @param a1 right knot value for active interval.
245
279
  */
246
280
  static createUniformWrapped(numInterval, degree, a0, a1) {
247
281
  const knots = new KnotVector(numInterval + 2 * degree - 1, degree);
248
282
  const du = 1.0 / numInterval;
249
- for (let i = 1 - degree, k = 0; i < numInterval + degree; i++, k++) {
283
+ for (let i = 1 - degree, k = 0; i < numInterval + degree; i++, k++)
250
284
  knots.knots[k] = Geometry.interpolate(a0, i * du, a1);
251
- }
252
285
  knots.setupFixedValues();
253
286
  return knots;
254
287
  }
255
288
  /**
256
289
  * Create knot vector with given knot values and degree.
257
- * @param knotArray knot values
258
- * @param degree degree of polynomial
290
+ * @param knotArray knot values.
291
+ * @param degree degree of polynomial.
259
292
  * @param skipFirstAndLast true to skip copying the first and last knot values.
260
293
  */
261
294
  static create(knotArray, degree, skipFirstAndLast) {
@@ -266,19 +299,24 @@ export class KnotVector {
266
299
  }
267
300
  /**
268
301
  * Return the average of degree consecutive knots beginning at knotIndex.
302
+ * * If `knotIndex` is negative, return `leftKnot`.
303
+ * * If `knotIndex > rightKnotIndex` return `rightKnot`.
269
304
  */
270
305
  grevilleKnot(knotIndex) {
271
306
  if (knotIndex < 0)
272
307
  return this.leftKnot;
273
308
  if (knotIndex > this.rightKnotIndex)
274
309
  return this.rightKnot;
310
+ knotIndex = Math.floor(knotIndex);
275
311
  let sum = 0.0;
276
312
  for (let i = knotIndex; i < knotIndex + this.degree; i++)
277
313
  sum += this.knots[i];
278
314
  return sum / this.degree;
279
315
  }
280
- /** Return an array sized for a set of the basis function values. */
281
- createBasisArray() { return new Float64Array(this.degree + 1); }
316
+ /** Return an array of size `degree + 1`, e.g., to hold the set of relevant basis function values at a parameter. */
317
+ createBasisArray() {
318
+ return new Float64Array(this.degree + 1);
319
+ }
282
320
  /** Convert localFraction within the interval following an indexed knot to a knot value. */
283
321
  baseKnotFractionToKnot(knotIndex0, localFraction) {
284
322
  const knot0 = this.knots[knotIndex0];
@@ -301,32 +339,38 @@ export class KnotVector {
301
339
  fraction = Geometry.clamp(fraction, 0, 1); // B-splines are not extendable
302
340
  return Geometry.interpolate(this.knots[this.degree - 1], fraction, this.knots[this.knots.length - this.degree]);
303
341
  }
342
+ isKnotInValidSpan(knotIndex0, u) {
343
+ const spanIsValid = knotIndex0 >= this.degree - 1 && knotIndex0 + this.degree < this.knots.length;
344
+ const uIsInSpan = this.knots[knotIndex0] <= u && u <= this.knots[knotIndex0 + 1];
345
+ return spanIsValid && uIsInSpan;
346
+ }
304
347
  /**
305
348
  * Evaluate the B-spline basis functions f[] at a parameter u in a knot span.
306
349
  * * This method implements the Mansfield-Cox-de Boor recurrence relation.
307
350
  * @param knotIndex0 index of the left knot of the span.
308
351
  * @param u value in the knot span: knot[knotIndex0] <= u <= knot[knotIndex0 + 1].
309
- * @param f preallocated output array of order basis function values
310
- * @returns true if and only if output array is sufficiently sized
352
+ * @param f preallocated output array of order basis function values.
353
+ * @returns true if and only if output array is sufficiently sized.
311
354
  */
312
355
  evaluateBasisFunctions(knotIndex0, u, f) {
313
356
  if (f.length < this.degree + 1)
314
357
  return false;
358
+ assert(() => this.isKnotInValidSpan(knotIndex0, u), "knot is in a valid span");
315
359
  f[0] = 1.0;
316
360
  if (this.degree < 1)
317
361
  return true;
318
- // direct compute for linear part ...
362
+ // direct compute for linear part
319
363
  const u0 = this.knots[knotIndex0];
320
364
  const u1 = this.knots[knotIndex0 + 1];
321
365
  f[1] = (u - u0) / (u1 - u0);
322
366
  f[0] = 1.0 - f[1];
323
367
  if (this.degree < 2)
324
368
  return true;
325
- // Each iteration of the outer loop evaluates the basis functions of degree depth+1 using
326
- // one or two values of the basis functions of one less degree from the preceding iteration.
369
+ // each iteration of the outer loop evaluates the basis functions of degree depth+1 using
370
+ // one or two values of the basis functions of one less degree from the preceding iteration
327
371
  for (let depth = 1; depth < this.degree; depth++) {
328
372
  let kLeft = knotIndex0 - depth;
329
- let kRight = kLeft + depth + 1;
373
+ let kRight = knotIndex0 + 1;
330
374
  let gCarry = 0.0;
331
375
  for (let step = 0; step <= depth; step++) {
332
376
  const tLeft = this.knots[kLeft++];
@@ -348,10 +392,10 @@ export class KnotVector {
348
392
  * in a knot span.
349
393
  * @param knotIndex0 index of the left knot of the span.
350
394
  * @param u value in the knot span: knot[knotIndex0] <= u <= knot[knotIndex0 + 1].
351
- * @param f preallocated output array of order basis function values
352
- * @param df preallocated output array of order basis derivative values
353
- * @param ddf optional preallocated output array of order basis second derivative values
354
- * @returns true if and only if output arrays are sufficiently sized
395
+ * @param f preallocated output array of order basis function values.
396
+ * @param df preallocated output array of order basis derivative values.
397
+ * @param ddf optional preallocated output array of order basis second derivative values.
398
+ * @returns true if and only if output arrays are sufficiently sized.
355
399
  */
356
400
  evaluateBasisFunctions1(knotIndex0, u, f, df, ddf) {
357
401
  if (f.length < this.degree + 1)
@@ -360,15 +404,16 @@ export class KnotVector {
360
404
  return false;
361
405
  if (ddf && ddf.length < this.degree + 1)
362
406
  return false;
407
+ assert(() => this.isKnotInValidSpan(knotIndex0, u), "knot is in a valid span");
363
408
  f[0] = 1.0;
364
409
  df[0] = 0.0;
365
410
  if (this.degree < 1)
366
411
  return true;
367
- // direct compute for linear part ...
412
+ // direct compute for linear part
368
413
  const u0 = this.knots[knotIndex0];
369
414
  const u1 = this.knots[knotIndex0 + 1];
370
- // ah = 1/(u1-u0) is the derivative of fraction0
371
- // (-ah) is the derivative of fraction1.
415
+ // ah = 1/(u1-u0) is the derivative of fraction0
416
+ // -ah is the derivative of fraction1
372
417
  let ah = 1.0 / (u1 - u0);
373
418
  f[1] = (u - u0) * ah;
374
419
  f[0] = 1.0 - f[1];
@@ -387,7 +432,7 @@ export class KnotVector {
387
432
  let dgCarry = 0.0;
388
433
  let ddgCarry = 0.0;
389
434
  // f, df, ddf, are each row vectors with product of `step` linear terms.
390
- // f is multiplied on the right by matrix V. Each row has 2 nonzero entries (which sum to 1) (0,0,1-fraction, fraction,0,0,0)
435
+ // f is multiplied on the right by matrix V. Each row has 2 nonzero entries (which sum to 1) (0,0,1-fraction, fraction,0,0,0)
391
436
  // Each row of the derivative dV is two entries (0,0, -1/h, 1/h,0,0,0)
392
437
  // Hence fnew = f * V
393
438
  // dfnew = df * V + f * dV
@@ -409,7 +454,7 @@ export class KnotVector {
409
454
  df[step] = dgCarry + dg0;
410
455
  gCarry = g1;
411
456
  dgCarry = dg1;
412
- if (ddf) { // do the backward reference to df before rewriting df !!!
457
+ if (ddf) { // do the backward reference to df before rewriting df
413
458
  const ddg1 = ddf[step] * fraction + dfSave;
414
459
  const ddg0 = ddf[step] * fraction1 - dfSave;
415
460
  ddf[step] = ddgCarry + ddg0;
@@ -423,9 +468,10 @@ export class KnotVector {
423
468
  }
424
469
  return true;
425
470
  }
426
- /** Find the knot span bracketing knots[i] <= u < knots[i+1] and return i.
471
+ /**
472
+ * Find the knot span bracketing knots[i] <= u < knots[i+1] and return i.
427
473
  * * If u has no such bracket, return the smaller index of the closest nontrivial bracket.
428
- * @param u value to bracket
474
+ * @param u value to bracket.
429
475
  */
430
476
  knotToLeftKnotIndex(u) {
431
477
  for (let i = this.leftKnotIndex; i < this.rightKnotIndex; ++i) {
@@ -441,7 +487,7 @@ export class KnotVector {
441
487
  }
442
488
  /**
443
489
  * Given a span index, return the index of the knot at its left.
444
- * @param spanIndex index of span
490
+ * @param spanIndex index of span.
445
491
  */
446
492
  spanIndexToLeftKnotIndex(spanIndex) {
447
493
  const d = this.degree;
@@ -456,7 +502,8 @@ export class KnotVector {
456
502
  }
457
503
  /**
458
504
  * Given a span index, test if it is within range and has nonzero length.
459
- * * note that a false return does not imply there are no more spans. This may be a double knot (zero length span) followed by more real spans
505
+ * * note that a false return does not imply there are no more spans. This may be a double knot (zero length span)
506
+ * followed by more real spans
460
507
  * @param spanIndex index of span to test.
461
508
  */
462
509
  isIndexOfRealSpan(spanIndex) {
@@ -464,7 +511,7 @@ export class KnotVector {
464
511
  return !Geometry.isSmallMetricDistance(this.spanIndexToSpanLength(spanIndex));
465
512
  return false;
466
513
  }
467
- /** Reflect all knots so `leftKnot` and `rightKnot` are maintained but interval lengths reverse. */
514
+ /** Reflect all knots so `leftKnot` and `rightKnot` are maintained but interval lengths are reversed. */
468
515
  reflectKnots() {
469
516
  const a = this.leftKnot;
470
517
  const b = this.rightKnot;
@@ -1 +1 @@
1
- {"version":3,"file":"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AC;;gBAE/C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,uHAAuH;IAChH,SAAS,CAAC,mBAA4B;QAC3C,MAAM,QAAQ,GAAG,CAAC,mBAAmB,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;QAC3F,OAAO,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,mBAAmB,EAAE,QAAQ,CAAC,CAAC;IACtF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Bspline\n */\n\nimport { Geometry } from \"../Geometry\";\nimport { NumberArray } from \"../geometry3d/PointHelpers\";\n\n/**\n * B-spline curve and surface types in this library are non-periodic. But they can be created from legacy periodic data.\n * This enumeration lists the possible ways a B-spline object can have been created from legacy periodic data.\n * @public\n */\nexport enum BSplineWrapMode {\n /** No conversion performed. */\n None = 0,\n /** The B-spline was opened up by adding degree wrap-around control points to the legacy periodic data.\n * * This is typical of B-splines constructed with maximum (degree - 1) continuity.\n * * Knots are unaffected by this conversion.\n */\n OpenByAddingControlPoints = 1,\n /** The B-spline was opened up by removing degree extreme knots from the legacy periodic data.\n * * This is typical of rational B-spline curves representing full circles and ellipses.\n * * Poles are unaffected by this conversion.\n */\n OpenByRemovingKnots = 2,\n}\n/**\n * Array of non-decreasing numbers acting as a knot array for B-splines.\n *\n * * Essential identity: numKnots = numPoles + order - 2 = numPoles + degree - 1\n * * Various B-spline libraries have confusion over how many \"end knots\" are needed. Many libraries (including MicroStation and Parasolid)\n * demand order knots at each end for clamping. But only order-1 are really needed. This class uses the order-1 convention.\n * * A span is a single interval of the knots.\n * * The left knot of span {k} is knot {k+degree-1}.\n * * This class provides queries to convert among spanIndex, knotIndex, spanFraction, fraction of knot range, and knot.\n * * Core computations (evaluateBasisFunctions) have leftKnotIndex and global knot value as inputs. Callers need to\n * know their primary values (global knot, spanFraction).\n * @public\n */\nexport class KnotVector {\n /** The simple array of knot values. */\n public knots: Float64Array;\n /** Return the degree of basis functions defined in these knots. */\n public degree: number;\n private _knot0: number;\n private _knot1: number;\n\n private _wrapMode?: BSplineWrapMode;\n /** tolerance for considering two knots to be the same. */\n public static readonly knotTolerance = 1.0e-9;\n /** Return the leftmost knot value (of the active interval, ignoring unclamped leading knots)*/\n public get leftKnot() { return this._knot0; }\n /** Return the rightmost knot value (of the active interval, ignoring unclamped leading knots)*/\n public get rightKnot() { return this._knot1; }\n /** Return the index of the leftmost knot of the active interval */\n public get leftKnotIndex() { return this.degree - 1; }\n /** Return the index of the rightmost knot of the active interval */\n public get rightKnotIndex() { return this.knots.length - this.degree; }\n /** Whether this KnotVector was created by converting legacy periodic data during deserialization. The conversion used is specified by BSplineWrapMode, and is reversed at serialization time. */\n public get wrappable() { return this._wrapMode === undefined ? BSplineWrapMode.None : this._wrapMode; }\n public set wrappable(value: BSplineWrapMode) { this._wrapMode = value; }\n /** Return the number of bezier spans. Note that this includes zero-length spans if there are repeated knots. */\n public get numSpans() { return this.rightKnotIndex - this.leftKnotIndex; }\n /**\n *\n * * If knots is a number array or Float64Array, the those values become the local knot array.\n * * If knots is a simple number, the local knot array is allocated to that size but left as zeros.\n * @param knots\n * @param degree\n */\n private constructor(knots: number[] | Float64Array | number, degree: number, wrapMode?: BSplineWrapMode) {\n this.degree = degree;\n this._wrapMode = wrapMode;\n // default values to satisfy compiler -- real values happen in setupFixedValues, or final else defers to user\n this._knot0 = 0.0;\n this._knot1 = 1.0;\n // satisfy the initialize checker ..\n if (Array.isArray(knots)) { // remark: This ctor is private. The callers (as of April 2019) do not use this path.\n this.knots = new Float64Array(knots.length);\n this.setKnots(knots);\n this.setupFixedValues();\n } else if (knots instanceof Float64Array) {\n this.knots = knots.slice();\n this.setupFixedValues();\n } else { // caller is responsible for filling array separately ...\n this.knots = new Float64Array(knots);\n }\n }\n /** copy degree and knots to a new KnotVector. */\n public clone(): KnotVector { return new KnotVector(this.knots, this.degree, this.wrappable); }\n private setupFixedValues() {\n if (this.degree > 0 && this.knots.length > this.degree) {\n this._knot0 = this.knots[this.degree - 1];\n this._knot1 = this.knots[this.knots.length - this.degree];\n }\n }\n /** Return the total knot distance from beginning to end. */\n public get knotLength01(): number { return this._knot1 - this._knot0; }\n /**\n * Returns true if all numeric values have wraparound conditions that allow the knots to be closed with specified wrap mode.\n * @param mode optional test mode. If undefined, use this.wrappable.\n */\n public testClosable(mode?: BSplineWrapMode): boolean {\n if (mode === undefined)\n mode = this.wrappable;\n const degree = this.degree;\n const leftKnotIndex = this.leftKnotIndex;\n const rightKnotIndex = this.rightKnotIndex;\n if (mode === BSplineWrapMode.OpenByAddingControlPoints) {\n // maximum continuity mode: we expect degree periodically extended knots at each end\n const period = this.rightKnot - this.leftKnot;\n const indexDelta = rightKnotIndex - leftKnotIndex;\n for (let k0 = 0; k0 < leftKnotIndex + degree; k0++) {\n const k1 = k0 + indexDelta;\n if (Math.abs(this.knots[k0] + period - this.knots[k1]) >= KnotVector.knotTolerance)\n return false;\n }\n return true;\n }\n if (mode === BSplineWrapMode.OpenByRemovingKnots) {\n // legacy periodic mode: we expect multiplicity degree knots at each end\n const numRepeated = degree - 1;\n const leftKnot = this.leftKnot;\n const rightKnot = this.rightKnot;\n for (let i = 0; i < numRepeated; i++) {\n if (Math.abs(leftKnot - this.knots[leftKnotIndex - i - 1]) >= KnotVector.knotTolerance)\n return false;\n if (Math.abs(rightKnot - this.knots[rightKnotIndex + i + 1]) >= KnotVector.knotTolerance)\n return false;\n }\n return true;\n }\n return false;\n }\n /** Test matching degree and knot values */\n public isAlmostEqual(other: KnotVector): boolean {\n if (this.degree !== other.degree) return false;\n return NumberArray.isAlmostEqual(this.knots, other.knots, KnotVector.knotTolerance);\n }\n\n /** Compute the multiplicity of the input knot, or zero if not a knot. */\n public getKnotMultiplicity(knot: number): number {\n let m = 0;\n for (const k of this.knots) {\n if (Math.abs(k - knot) < KnotVector.knotTolerance)\n ++m;\n else if (knot < k)\n break;\n }\n return m;\n }\n\n /** Compute the multiplicity of the knot at the given index. */\n public getKnotMultiplicityAtIndex(knotIndex: number): number {\n let m = 0;\n if (knotIndex >= 0 && knotIndex < this.knots.length) {\n const knot = this.knots[knotIndex];\n ++m; // count this knot\n for (let i = knotIndex - 1; i >= 0; --i) {\n const k = this.knots[i];\n if (Math.abs(k - knot) < KnotVector.knotTolerance)\n ++m; // found multiple to left of knot\n else if (knot > k)\n break;\n }\n for (let i = knotIndex + 1; i < this.knots.length; ++i) {\n const k = this.knots[i];\n if (Math.abs(k - knot) < KnotVector.knotTolerance)\n ++m; // found multiple to right of knot\n else if (knot < k)\n break;\n }\n }\n return m;\n }\n\n /** Transform knots to span [0,1].\n * @returns false if and only if this.knotLength01 is trivial\n */\n public normalize(): boolean {\n if (this.knotLength01 < KnotVector.knotTolerance)\n return false;\n const divisor = 1.0 / this.knotLength01;\n const leftKnot = this.leftKnot;\n for (let i = 0; i < this.knots.length; ++i)\n this.knots[i] = (this.knots[i] - leftKnot) * divisor;\n // explicitly set rightKnot and its multiples to 1.0 to avoid round-off\n for (let i = this.rightKnotIndex - 1; i > this.leftKnotIndex && (this.knots[i] === this.knots[this.rightKnotIndex]); --i) this.knots[i] = 1.0;\n for (let i = this.rightKnotIndex + 1; i < this.knots.length && (this.knots[i] === this.knots[this.rightKnotIndex]); ++i) this.knots[i] = 1.0;\n this.knots[this.rightKnotIndex] = 1.0;\n this.setupFixedValues();\n return true;\n }\n\n /** install knot values from an array, optionally ignoring first and last.\n */\n public setKnots(knots: number[] | Float64Array, skipFirstAndLast?: boolean) {\n const numAllocate = skipFirstAndLast ? knots.length - 2 : knots.length;\n if (numAllocate !== this.knots.length)\n this.knots = new Float64Array(numAllocate);\n if (skipFirstAndLast) {\n for (let i = 1; i + 1 < knots.length; i++)\n this.knots[i - 1] = knots[i];\n\n } else {\n for (let i = 0; i < knots.length; i++)\n this.knots[i] = knots[i];\n }\n this.setupFixedValues();\n }\n\n /** Set knots to input array (CAPTURED) */\n public setKnotsCapture(knots: Float64Array) {\n this.knots = knots;\n this.setupFixedValues();\n }\n\n /**\n * Create knot vector with {degree-1} replicated knots at start and end, and uniform knots between.\n * @param numPoles Number of poles\n * @param degree degree of polynomial\n * @param a0 left knot value for active interval\n * @param a1 right knot value for active interval\n */\n public static createUniformClamped(numPoles: number, degree: number, a0: number, a1: number): KnotVector {\n const knots = new KnotVector(numPoles + degree - 1, degree);\n let k = 0;\n for (let m = 0; m < degree; m++)knots.knots[k++] = a0;\n const du = 1.0 / (numPoles - degree);\n for (let i = 1; i + degree < numPoles; i++)\n knots.knots[k++] = a0 + i * du * (a1 - a0);\n for (let m = 0; m < degree; m++)knots.knots[k++] = a1;\n knots.setupFixedValues();\n return knots;\n }\n /**\n * Create knot vector with wraparound knots at start and end, and uniform knots between.\n * @param numInterval number of intervals in knot space. (NOT POLE COUNT)\n * @param degree degree of polynomial\n * @param a0 left knot value for active interval\n * @param a1 right knot value for active interval\n */\n public static createUniformWrapped(numInterval: number, degree: number, a0: number, a1: number): KnotVector {\n const knots = new KnotVector(numInterval + 2 * degree - 1, degree);\n const du = 1.0 / numInterval;\n for (let i = 1 - degree, k = 0; i < numInterval + degree; i++, k++) {\n knots.knots[k] = Geometry.interpolate(a0, i * du, a1);\n }\n knots.setupFixedValues();\n return knots;\n }\n\n /**\n * Create knot vector with given knot values and degree.\n * @param knotArray knot values\n * @param degree degree of polynomial\n * @param skipFirstAndLast true to skip copying the first and last knot values.\n */\n public static create(knotArray: number[] | Float64Array, degree: number, skipFirstAndLast?: boolean): KnotVector {\n const numAllocate = skipFirstAndLast ? knotArray.length - 2 : knotArray.length;\n const knots = new KnotVector(numAllocate, degree);\n knots.setKnots(knotArray, skipFirstAndLast);\n return knots;\n }\n\n /**\n * Return the average of degree consecutive knots beginning at knotIndex.\n */\n public grevilleKnot(knotIndex: number): number {\n if (knotIndex < 0) return this.leftKnot;\n if (knotIndex > this.rightKnotIndex) return this.rightKnot;\n let sum = 0.0;\n for (let i = knotIndex; i < knotIndex + this.degree; i++)\n sum += this.knots[i];\n return sum / this.degree;\n }\n /** Return an array sized for a set of the basis function values. */\n public createBasisArray(): Float64Array { return new Float64Array(this.degree + 1); }\n /** Convert localFraction within the interval following an indexed knot to a knot value. */\n public baseKnotFractionToKnot(knotIndex0: number, localFraction: number): number {\n const knot0 = this.knots[knotIndex0];\n localFraction = Geometry.clamp(localFraction, 0, 1);\n return knot0 + localFraction * (this.knots[knotIndex0 + 1] - knot0);\n }\n /** Convert localFraction within an indexed bezier span to a knot value. */\n public spanFractionToKnot(spanIndex: number, localFraction: number): number {\n const k = this.spanIndexToLeftKnotIndex(spanIndex);\n localFraction = Geometry.clamp(localFraction, 0, 1);\n return this.knots[k] + localFraction * (this.knots[k + 1] - this.knots[k]);\n }\n /** Convert localFraction within an indexed bezier span to fraction of active knot range. */\n public spanFractionToFraction(spanIndex: number, localFraction: number): number {\n const knot = this.spanFractionToKnot(spanIndex, localFraction);\n return (knot - this.leftKnot) / (this.rightKnot - this.leftKnot);\n }\n /** Return fraction of active knot range to knot value. */\n public fractionToKnot(fraction: number): number {\n fraction = Geometry.clamp(fraction, 0, 1); // B-splines are not extendable\n return Geometry.interpolate(this.knots[this.degree - 1], fraction, this.knots[this.knots.length - this.degree]);\n }\n /**\n * Evaluate the B-spline basis functions f[] at a parameter u in a knot span.\n * * This method implements the Mansfield-Cox-de Boor recurrence relation.\n * @param knotIndex0 index of the left knot of the span.\n * @param u value in the knot span: knot[knotIndex0] <= u <= knot[knotIndex0 + 1].\n * @param f preallocated output array of order basis function values\n * @returns true if and only if output array is sufficiently sized\n */\n public evaluateBasisFunctions(knotIndex0: number, u: number, f: Float64Array): boolean {\n if (f.length < this.degree + 1)\n return false;\n f[0] = 1.0;\n if (this.degree < 1)\n return true;\n // direct compute for linear part ...\n const u0 = this.knots[knotIndex0];\n const u1 = this.knots[knotIndex0 + 1];\n f[1] = (u - u0) / (u1 - u0);\n f[0] = 1.0 - f[1];\n if (this.degree < 2)\n return true;\n // Each iteration of the outer loop evaluates the basis functions of degree depth+1 using\n // one or two values of the basis functions of one less degree from the preceding iteration.\n for (let depth = 1; depth < this.degree; depth++) {\n let kLeft = knotIndex0 - depth;\n let kRight = kLeft + depth + 1;\n let gCarry = 0.0;\n for (let step = 0; step <= depth; step++) {\n const tLeft = this.knots[kLeft++];\n const tRight = this.knots[kRight++];\n const fraction = (u - tLeft) / (tRight - tLeft);\n const g1 = f[step] * fraction;\n const g0 = f[step] * (1.0 - fraction);\n f[step] = gCarry + g0;\n gCarry = g1;\n }\n f[depth + 1] = gCarry;\n // at this point, the head of f[] contains the depth+2 values at u\n // of the basis functions of degree depth+1 with support over [u0,u1)\n }\n return true;\n }\n\n /**\n * Evaluate basis functions f[], derivatives df[], and optional second derivatives ddf[] at a parameter u\n * in a knot span.\n * @param knotIndex0 index of the left knot of the span.\n * @param u value in the knot span: knot[knotIndex0] <= u <= knot[knotIndex0 + 1].\n * @param f preallocated output array of order basis function values\n * @param df preallocated output array of order basis derivative values\n * @param ddf optional preallocated output array of order basis second derivative values\n * @returns true if and only if output arrays are sufficiently sized\n */\n public evaluateBasisFunctions1(knotIndex0: number, u: number, f: Float64Array, df: Float64Array, ddf?: Float64Array): boolean {\n if (f.length < this.degree + 1)\n return false;\n if (df.length < this.degree + 1)\n return false;\n if (ddf && ddf.length < this.degree + 1)\n return false;\n f[0] = 1.0; df[0] = 0.0;\n if (this.degree < 1)\n return true;\n // direct compute for linear part ...\n const u0 = this.knots[knotIndex0];\n const u1 = this.knots[knotIndex0 + 1];\n // ah = 1/(u1-u0) is the derivative of fraction0\n // (-ah) is the derivative of fraction1.\n let ah = 1.0 / (u1 - u0);\n f[1] = (u - u0) * ah;\n f[0] = 1.0 - f[1];\n df[0] = -ah; df[1] = ah;\n if (ddf) { // first derivative started constant, second derivative started zero.\n ddf[0] = 0.0; ddf[1] = 0.0;\n }\n if (this.degree < 2)\n return true;\n for (let depth = 1; depth < this.degree; depth++) {\n let kLeft = knotIndex0 - depth;\n let kRight = kLeft + depth + 1;\n let gCarry = 0.0;\n let dgCarry = 0.0;\n let ddgCarry = 0.0;\n // f, df, ddf, are each row vectors with product of `step` linear terms.\n // f is multiplied on the right by matrix V. Each row has 2 nonzero entries (which sum to 1) (0,0,1-fraction, fraction,0,0,0)\n // Each row of the derivative dV is two entries (0,0, -1/h, 1/h,0,0,0)\n // Hence fnew = f * V\n // dfnew = df * V + f * dV\n // ddfnew = ddf * V + df*dV + df * dV + f * ddV\n // but ddV is zero so\n // ddfnew = ddf * V + 2 * df * dV\n for (let step = 0; step <= depth; step++) {\n const tLeft = this.knots[kLeft++];\n const tRight = this.knots[kRight++];\n ah = 1.0 / (tRight - tLeft);\n const fraction = (u - tLeft) * ah;\n const fraction1 = 1.0 - fraction;\n const g1 = f[step] * fraction;\n const g0 = f[step] * fraction1;\n const dg1 = df[step] * fraction + f[step] * ah;\n const dg0 = df[step] * fraction1 - f[step] * ah;\n const dfSave = 2.0 * df[step] * ah;\n f[step] = gCarry + g0;\n df[step] = dgCarry + dg0;\n gCarry = g1;\n dgCarry = dg1;\n if (ddf) { // do the backward reference to df before rewriting df !!!\n const ddg1 = ddf[step] * fraction + dfSave;\n const ddg0 = ddf[step] * fraction1 - dfSave;\n ddf[step] = ddgCarry + ddg0;\n ddgCarry = ddg1;\n }\n }\n f[depth + 1] = gCarry;\n df[depth + 1] = dgCarry;\n if (ddf)\n ddf[depth + 1] = ddgCarry;\n }\n return true;\n }\n /** Find the knot span bracketing knots[i] <= u < knots[i+1] and return i.\n * * If u has no such bracket, return the smaller index of the closest nontrivial bracket.\n * @param u value to bracket\n */\n public knotToLeftKnotIndex(u: number): number {\n for (let i = this.leftKnotIndex; i < this.rightKnotIndex; ++i) {\n if (u < this.knots[i + 1])\n return i;\n }\n // for u >= rightKnot, return left index of last nontrivial span\n for (let i = this.rightKnotIndex; i > this.leftKnotIndex; --i) {\n if (this.knots[i] - this.knots[i - 1] >= KnotVector.knotTolerance)\n return i - 1;\n }\n return this.rightKnotIndex - 1; // shouldn't get here\n }\n /**\n * Given a span index, return the index of the knot at its left.\n * @param spanIndex index of span\n */\n public spanIndexToLeftKnotIndex(spanIndex: number): number {\n const d = this.degree;\n if (spanIndex <= 0.0) return d - 1;\n return Math.min(spanIndex + d - 1, this.knots.length - d - 1);\n }\n /** Return the knot interval length of indexed bezier span. */\n public spanIndexToSpanLength(spanIndex: number): number {\n const k = this.spanIndexToLeftKnotIndex(spanIndex);\n return this.knots[k + 1] - this.knots[k];\n }\n /**\n * Given a span index, test if it is within range and has nonzero length.\n * * note that a false return does not imply there are no more spans. This may be a double knot (zero length span) followed by more real spans\n * @param spanIndex index of span to test.\n */\n public isIndexOfRealSpan(spanIndex: number): boolean {\n if (spanIndex >= 0 && spanIndex < this.numSpans)\n return !Geometry.isSmallMetricDistance(this.spanIndexToSpanLength(spanIndex));\n return false;\n }\n /** Reflect all knots so `leftKnot` and `rightKnot` are maintained but interval lengths reverse. */\n public reflectKnots() {\n const a = this.leftKnot;\n const b = this.rightKnot;\n const numKnots = this.knots.length;\n for (let i = 0; i < numKnots; i++)\n this.knots[i] = a + (b - this.knots[i]);\n this.knots.reverse();\n }\n\n /** Return a simple array form of the knots. Optionally replicate the first and last in classic over-clamped manner. */\n public static copyKnots(knots: number[] | Float64Array, degree: number, includeExtraEndKnot?: boolean, wrapMode?: BSplineWrapMode): number[] {\n const isExtraEndKnotPeriodic = (includeExtraEndKnot && wrapMode === BSplineWrapMode.OpenByAddingControlPoints);\n const leftIndex = degree - 1;\n const rightIndex = knots.length - degree;\n const a0 = knots[leftIndex];\n const a1 = knots[rightIndex];\n const delta = a1 - a0;\n const values: number[] = [];\n if (includeExtraEndKnot) {\n if (isExtraEndKnotPeriodic)\n values.push(knots[rightIndex - degree] - delta);\n else\n values.push(knots[0]);\n }\n for (const u of knots) {\n values.push(u);\n }\n if (includeExtraEndKnot) {\n if (isExtraEndKnotPeriodic)\n values.push(knots[leftIndex + degree] + delta);\n else\n values.push(knots[knots.length - 1]);\n }\n return values;\n }\n\n /** Return a simple array form of the knots. Optionally replicate the first and last in classic over-clamped manner. */\n public copyKnots(includeExtraEndKnot: boolean): number[] {\n const wrapMode = (includeExtraEndKnot && this.testClosable()) ? this.wrappable : undefined;\n return KnotVector.copyKnots(this.knots, this.degree, includeExtraEndKnot, wrapMode);\n }\n}\n"]}
1
+ {"version":3,"file":"KnotVector.js","sourceRoot":"","sources":["../../../src/bspline/KnotVector.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD;;;;GAIG;AACH,MAAM,CAAN,IAAY,eAeX;AAfD,WAAY,eAAe;IACzB,+BAA+B;IAC/B,qDAAQ,CAAA;IACR;;;;OAIG;IACH,+FAA6B,CAAA;IAC7B;;;;OAIG;IACH,mFAAuB,CAAA;AACzB,CAAC,EAfW,eAAe,KAAf,eAAe,QAe1B;AACD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,UAAU;IACrB,uCAAuC;IAChC,KAAK,CAAe;IAC3B,4DAA4D;IACrD,MAAM,CAAS;IACtB,0FAA0F;IAClF,MAAM,CAAS;IACvB,2FAA2F;IACnF,MAAM,CAAS;IACf,SAAS,CAAmB;IACpC,0DAA0D;IACnD,MAAM,CAAU,aAAa,GAAG,MAAM,CAAC;IAC9C,iGAAiG;IACjG,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,MAAM,CA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,CAAC,CAAC,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,uHAAuH;IAChH,SAAS,CAAC,mBAA4B;QAC3C,MAAM,QAAQ,GAAG,CAAC,mBAAmB,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;QAC3F,OAAO,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,mBAAmB,EAAE,QAAQ,CAAC,CAAC;IACtF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Bspline\n */\n\nimport { assert } from \"@itwin/core-bentley\";\nimport { Geometry } from \"../Geometry\";\nimport { NumberArray } from \"../geometry3d/PointHelpers\";\n\n/**\n * B-spline curve and surface types in this library are non-periodic. But they can be created from legacy periodic data.\n * This enumeration lists the possible ways a B-spline object can have been created from legacy periodic data.\n * @public\n */\nexport enum BSplineWrapMode {\n /** No conversion performed. */\n None = 0,\n /**\n * The legacy periodic B-spline data was opened up by adding `degree` wrap-around poles.\n * * This is typical of B-spline curves and surfaces constructed with maximum `degree - 1` continuity.\n * * Knots are unaffected by this conversion.\n */\n OpenByAddingControlPoints = 1,\n /**\n * The legacy periodic B-spline data was opened up by removing `degree` exterior knots.\n * * This is typical of rational B-spline curves representing full circles and ellipses.\n * * Poles are unaffected by this conversion.\n */\n OpenByRemovingKnots = 2,\n}\n/**\n * Array of non-decreasing numbers acting as a knot vector for B-spline curves and surfaces.\n *\n * * Essential identity: numKnots = numPoles + order - 2 = numPoles + degree - 1\n * * Various B-spline libraries have confusion over how many \"end knots\" are needed. Many libraries (including MicroStation\n * and Parasolid) demand order knots at each end for clamping. However, only order-1 are really needed. This class uses the\n * order-1 convention.\n * * A span is a single interval of the knots.\n * * The left knot of the span with index `k>=0` is the knot with index `k+degree-1`.\n * * A knot vector is clamped when the first `degree` knots are equal and the last `degree` knots are equal.\n * * The \"active knot interval\" is the subset of the knot vector sans its first and last `degree-1` knots, and serves as\n * the parametric domain of the associated B-spline object.\n * * This class provides queries to convert among spanIndex, knotIndex, spanFraction, fraction of knot range, and knot.\n * * Callers need to distinguish core computational inputs such as left knot index, knot value, span index, and span fraction.\n * @public\n */\nexport class KnotVector {\n /** The simple array of knot values. */\n public knots: Float64Array;\n /** The degree of basis functions defined in these knots. */\n public degree: number;\n /** The leftmost knot value (of the active interval, ignoring unclamped leading knots). */\n private _knot0: number;\n /** The rightmost knot value (of the active interval, ignoring unclamped leading knots). */\n private _knot1: number;\n private _wrapMode?: BSplineWrapMode;\n /** Tolerance for considering two knots to be the same. */\n public static readonly knotTolerance = 1.0e-9;\n /** Return the leftmost knot value (of the active interval, ignoring unclamped leading knots). */\n public get leftKnot() {\n return this._knot0;\n }\n /** Return the rightmost knot value (of the active interval, ignoring unclamped leading knots). */\n public get rightKnot() {\n return this._knot1;\n }\n /** Return the index of the leftmost knot of the active interval. */\n public get leftKnotIndex() {\n return this.degree - 1;\n }\n /** Return the index of the rightmost knot of the active interval. */\n public get rightKnotIndex() {\n return this.knots.length - this.degree;\n }\n /**\n * Whether this KnotVector was created by converting legacy periodic data during deserialization. The conversion used\n * is specified by BSplineWrapMode, and is reversed at serialization time.\n */\n public get wrappable() {\n return this._wrapMode === undefined ? BSplineWrapMode.None : this._wrapMode;\n }\n public set wrappable(value: BSplineWrapMode) {\n this._wrapMode = value;\n }\n /** Return the number of Bezier spans. Note that this includes zero-length spans if there are repeated knots. */\n public get numSpans() {\n return this.rightKnotIndex - this.leftKnotIndex;\n }\n /**\n * Private constructor.\n * * If `knots` is a number array or Float64Array, then its values are copied to the instance array.\n * * If `knots` is a number, the instance array is allocated to this size but left as zeros.\n */\n private constructor(knots: number[] | Float64Array | number, degree: number, wrapMode?: BSplineWrapMode) {\n this.degree = degree;\n this._wrapMode = wrapMode;\n // default values to satisfy compiler; real values happen in setupFixedValues or the final else clause defers to user\n this._knot0 = 0.0;\n this._knot1 = 1.0;\n if (Array.isArray(knots)) {\n this.knots = new Float64Array(knots.length);\n this.setKnots(knots);\n this.setupFixedValues();\n } else if (knots instanceof Float64Array) {\n this.knots = knots.slice();\n this.setupFixedValues();\n } else { // caller is responsible for filling array separately\n const knotSize = knots;\n this.knots = new Float64Array(knotSize);\n }\n }\n /** Copy degree and knots to a new KnotVector. */\n public clone(): KnotVector {\n return new KnotVector(this.knots, this.degree, this.wrappable);\n }\n private setupFixedValues() {\n if (this.degree > 0 && this.knots.length > this.degree) {\n this._knot0 = this.knots[this.degree - 1];\n this._knot1 = this.knots[this.knots.length - this.degree];\n }\n }\n /**\n * Return the length of the active knot interval.\n * * This is the size of (one dimension of) the parametric domain for the associated B-spline object.\n */\n public get knotLength01(): number {\n return this._knot1 - this._knot0;\n }\n /**\n * Returns true if all numeric values have wraparound conditions that allow the knots to be closed with specified\n * wrap mode.\n * @param mode optional test mode. If undefined, use this.wrappable.\n */\n public testClosable(mode?: BSplineWrapMode): boolean {\n if (mode === undefined)\n mode = this.wrappable;\n const degree = this.degree;\n const leftKnotIndex = this.leftKnotIndex;\n const rightKnotIndex = this.rightKnotIndex;\n if (mode === BSplineWrapMode.OpenByAddingControlPoints) {\n // maximum continuity mode: we expect degree periodically extended knots at each end\n const period = this.rightKnot - this.leftKnot;\n const indexDelta = rightKnotIndex - leftKnotIndex;\n for (let k0 = 0; k0 < leftKnotIndex + degree; k0++) {\n const k1 = k0 + indexDelta;\n if (Math.abs(this.knots[k0] + period - this.knots[k1]) >= KnotVector.knotTolerance)\n return false;\n }\n return true;\n }\n if (mode === BSplineWrapMode.OpenByRemovingKnots) {\n // legacy periodic mode: we expect multiplicity degree knots at each end\n const numRepeated = degree - 1;\n const leftKnot = this.leftKnot;\n const rightKnot = this.rightKnot;\n for (let i = 0; i < numRepeated; i++) {\n if (Math.abs(leftKnot - this.knots[leftKnotIndex - i - 1]) >= KnotVector.knotTolerance)\n return false;\n if (Math.abs(rightKnot - this.knots[rightKnotIndex + i + 1]) >= KnotVector.knotTolerance)\n return false;\n }\n return true;\n }\n return false;\n }\n /** Test matching degree and knot values. */\n public isAlmostEqual(other: KnotVector): boolean {\n if (this.degree !== other.degree)\n return false;\n return NumberArray.isAlmostEqual(this.knots, other.knots, KnotVector.knotTolerance);\n }\n /** Compute the multiplicity of the input knot, or zero if not a knot. */\n public getKnotMultiplicity(knot: number): number {\n let m = 0;\n for (const k of this.knots) {\n if (Math.abs(k - knot) < KnotVector.knotTolerance)\n ++m;\n else if (knot < k)\n break;\n }\n return m;\n }\n /** Compute the multiplicity of the knot at the given index. */\n public getKnotMultiplicityAtIndex(knotIndex: number): number {\n let m = 0;\n if (knotIndex >= 0 && knotIndex < this.knots.length) {\n const knot = this.knots[knotIndex];\n ++m; // count this knot\n for (let i = knotIndex - 1; i >= 0; --i) {\n const k = this.knots[i];\n if (Math.abs(k - knot) < KnotVector.knotTolerance)\n ++m; // found multiple to left of knot\n else if (knot > k)\n break;\n }\n for (let i = knotIndex + 1; i < this.knots.length; ++i) {\n const k = this.knots[i];\n if (Math.abs(k - knot) < KnotVector.knotTolerance)\n ++m; // found multiple to right of knot\n else if (knot < k)\n break;\n }\n }\n return m;\n }\n /**\n * Transform knots such that the active knot range becomes [0,1].\n * @returns false if and only if `this.knotLength01` is trivial.\n */\n public normalize(): boolean {\n if (this.knotLength01 < KnotVector.knotTolerance)\n return false;\n const divisor = 1.0 / this.knotLength01;\n const leftKnot = this.leftKnot;\n for (let i = 0; i < this.knots.length; ++i)\n this.knots[i] = (this.knots[i] - leftKnot) * divisor;\n // explicitly set rightKnot and its multiples to 1.0 to avoid round-off\n for (let i = this.rightKnotIndex - 1; i > this.leftKnotIndex && (this.knots[i] === this.knots[this.rightKnotIndex]); --i)\n this.knots[i] = 1.0;\n for (let i = this.rightKnotIndex + 1; i < this.knots.length && (this.knots[i] === this.knots[this.rightKnotIndex]); ++i)\n this.knots[i] = 1.0;\n this.knots[this.rightKnotIndex] = 1.0;\n this.setupFixedValues();\n return true;\n }\n /** Install knot values from an array, optionally ignoring first and last. */\n public setKnots(knots: number[] | Float64Array, skipFirstAndLast?: boolean) {\n const numAllocate = skipFirstAndLast ? knots.length - 2 : knots.length;\n if (numAllocate !== this.knots.length)\n this.knots = new Float64Array(numAllocate);\n if (skipFirstAndLast) {\n for (let i = 1; i + 1 < knots.length; i++)\n this.knots[i - 1] = knots[i];\n } else {\n for (let i = 0; i < knots.length; i++)\n this.knots[i] = knots[i];\n }\n this.setupFixedValues();\n }\n /** Set knots to input array (CAPTURED). */\n public setKnotsCapture(knots: Float64Array) {\n this.knots = knots;\n this.setupFixedValues();\n }\n /**\n * Create knot vector with {degree-1} replicated knots at start and end, and uniform knots between.\n * @param numPoles number of poles.\n * @param degree degree of polynomial.\n * @param a0 left knot value for active interval.\n * @param a1 right knot value for active interval.\n */\n public static createUniformClamped(numPoles: number, degree: number, a0: number, a1: number): KnotVector {\n const knots = new KnotVector(numPoles + degree - 1, degree);\n let k = 0;\n for (let m = 0; m < degree; m++)\n knots.knots[k++] = a0;\n const du = 1.0 / (numPoles - degree);\n for (let i = 1; i + degree < numPoles; i++)\n knots.knots[k++] = a0 + i * du * (a1 - a0);\n for (let m = 0; m < degree; m++)\n knots.knots[k++] = a1;\n knots.setupFixedValues();\n return knots;\n }\n /**\n * Create knot vector with wraparound knots at start and end, and uniform knots between.\n * @param numInterval the number of intervals into which to uniformly divide the active knot interval `[a0,a1]`,\n * creating `numInterval-1` equally spaced interior knots between `a0` and `a1`.\n * This number is equal to the number of Bezier spans in the associated B-spline object.\n * It is _not_ the pole count.\n * @param degree degree of polynomial.\n * @param a0 left knot value for active interval.\n * @param a1 right knot value for active interval.\n */\n public static createUniformWrapped(numInterval: number, degree: number, a0: number, a1: number): KnotVector {\n const knots = new KnotVector(numInterval + 2 * degree - 1, degree);\n const du = 1.0 / numInterval;\n for (let i = 1 - degree, k = 0; i < numInterval + degree; i++, k++)\n knots.knots[k] = Geometry.interpolate(a0, i * du, a1);\n knots.setupFixedValues();\n return knots;\n }\n /**\n * Create knot vector with given knot values and degree.\n * @param knotArray knot values.\n * @param degree degree of polynomial.\n * @param skipFirstAndLast true to skip copying the first and last knot values.\n */\n public static create(knotArray: number[] | Float64Array, degree: number, skipFirstAndLast?: boolean): KnotVector {\n const numAllocate = skipFirstAndLast ? knotArray.length - 2 : knotArray.length;\n const knots = new KnotVector(numAllocate, degree);\n knots.setKnots(knotArray, skipFirstAndLast);\n return knots;\n }\n /**\n * Return the average of degree consecutive knots beginning at knotIndex.\n * * If `knotIndex` is negative, return `leftKnot`.\n * * If `knotIndex > rightKnotIndex` return `rightKnot`.\n */\n public grevilleKnot(knotIndex: number): number {\n if (knotIndex < 0)\n return this.leftKnot;\n if (knotIndex > this.rightKnotIndex)\n return this.rightKnot;\n knotIndex = Math.floor(knotIndex);\n let sum = 0.0;\n for (let i = knotIndex; i < knotIndex + this.degree; i++)\n sum += this.knots[i];\n return sum / this.degree;\n }\n /** Return an array of size `degree + 1`, e.g., to hold the set of relevant basis function values at a parameter. */\n public createBasisArray(): Float64Array {\n return new Float64Array(this.degree + 1);\n }\n /** Convert localFraction within the interval following an indexed knot to a knot value. */\n public baseKnotFractionToKnot(knotIndex0: number, localFraction: number): number {\n const knot0 = this.knots[knotIndex0];\n localFraction = Geometry.clamp(localFraction, 0, 1);\n return knot0 + localFraction * (this.knots[knotIndex0 + 1] - knot0);\n }\n /** Convert localFraction within an indexed bezier span to a knot value. */\n public spanFractionToKnot(spanIndex: number, localFraction: number): number {\n const k = this.spanIndexToLeftKnotIndex(spanIndex);\n localFraction = Geometry.clamp(localFraction, 0, 1);\n return this.knots[k] + localFraction * (this.knots[k + 1] - this.knots[k]);\n }\n /** Convert localFraction within an indexed bezier span to fraction of active knot range. */\n public spanFractionToFraction(spanIndex: number, localFraction: number): number {\n const knot = this.spanFractionToKnot(spanIndex, localFraction);\n return (knot - this.leftKnot) / (this.rightKnot - this.leftKnot);\n }\n /** Return fraction of active knot range to knot value. */\n public fractionToKnot(fraction: number): number {\n fraction = Geometry.clamp(fraction, 0, 1); // B-splines are not extendable\n return Geometry.interpolate(this.knots[this.degree - 1], fraction, this.knots[this.knots.length - this.degree]);\n }\n private isKnotInValidSpan(knotIndex0: number, u: number): boolean {\n const spanIsValid = knotIndex0 >= this.degree - 1 && knotIndex0 + this.degree < this.knots.length;\n const uIsInSpan = this.knots[knotIndex0] <= u && u <= this.knots[knotIndex0 + 1];\n return spanIsValid && uIsInSpan;\n }\n /**\n * Evaluate the B-spline basis functions f[] at a parameter u in a knot span.\n * * This method implements the Mansfield-Cox-de Boor recurrence relation.\n * @param knotIndex0 index of the left knot of the span.\n * @param u value in the knot span: knot[knotIndex0] <= u <= knot[knotIndex0 + 1].\n * @param f preallocated output array of order basis function values.\n * @returns true if and only if output array is sufficiently sized.\n */\n public evaluateBasisFunctions(knotIndex0: number, u: number, f: Float64Array): boolean {\n if (f.length < this.degree + 1)\n return false;\n assert(() => this.isKnotInValidSpan(knotIndex0, u), \"knot is in a valid span\");\n f[0] = 1.0;\n if (this.degree < 1)\n return true;\n // direct compute for linear part\n const u0 = this.knots[knotIndex0];\n const u1 = this.knots[knotIndex0 + 1];\n f[1] = (u - u0) / (u1 - u0);\n f[0] = 1.0 - f[1];\n if (this.degree < 2)\n return true;\n // each iteration of the outer loop evaluates the basis functions of degree depth+1 using\n // one or two values of the basis functions of one less degree from the preceding iteration\n for (let depth = 1; depth < this.degree; depth++) {\n let kLeft = knotIndex0 - depth;\n let kRight = knotIndex0 + 1;\n let gCarry = 0.0;\n for (let step = 0; step <= depth; step++) {\n const tLeft = this.knots[kLeft++];\n const tRight = this.knots[kRight++];\n const fraction = (u - tLeft) / (tRight - tLeft);\n const g1 = f[step] * fraction;\n const g0 = f[step] * (1.0 - fraction);\n f[step] = gCarry + g0;\n gCarry = g1;\n }\n f[depth + 1] = gCarry;\n // at this point, the head of f[] contains the depth+2 values at u\n // of the basis functions of degree depth+1 with support over [u0,u1)\n }\n return true;\n }\n /**\n * Evaluate basis functions f[], derivatives df[], and optional second derivatives ddf[] at a parameter u\n * in a knot span.\n * @param knotIndex0 index of the left knot of the span.\n * @param u value in the knot span: knot[knotIndex0] <= u <= knot[knotIndex0 + 1].\n * @param f preallocated output array of order basis function values.\n * @param df preallocated output array of order basis derivative values.\n * @param ddf optional preallocated output array of order basis second derivative values.\n * @returns true if and only if output arrays are sufficiently sized.\n */\n public evaluateBasisFunctions1(\n knotIndex0: number, u: number, f: Float64Array, df: Float64Array, ddf?: Float64Array,\n ): boolean {\n if (f.length < this.degree + 1)\n return false;\n if (df.length < this.degree + 1)\n return false;\n if (ddf && ddf.length < this.degree + 1)\n return false;\n assert(() => this.isKnotInValidSpan(knotIndex0, u), \"knot is in a valid span\");\n f[0] = 1.0;\n df[0] = 0.0;\n if (this.degree < 1)\n return true;\n // direct compute for linear part\n const u0 = this.knots[knotIndex0];\n const u1 = this.knots[knotIndex0 + 1];\n // ah = 1/(u1-u0) is the derivative of fraction0\n // -ah is the derivative of fraction1\n let ah = 1.0 / (u1 - u0);\n f[1] = (u - u0) * ah;\n f[0] = 1.0 - f[1];\n df[0] = -ah; df[1] = ah;\n if (ddf) { // first derivative started constant, second derivative started zero.\n ddf[0] = 0.0;\n ddf[1] = 0.0;\n }\n if (this.degree < 2)\n return true;\n for (let depth = 1; depth < this.degree; depth++) {\n let kLeft = knotIndex0 - depth;\n let kRight = kLeft + depth + 1;\n let gCarry = 0.0;\n let dgCarry = 0.0;\n let ddgCarry = 0.0;\n // f, df, ddf, are each row vectors with product of `step` linear terms.\n // f is multiplied on the right by matrix V. Each row has 2 nonzero entries (which sum to 1) (0,0,1-fraction, fraction,0,0,0)\n // Each row of the derivative dV is two entries (0,0, -1/h, 1/h,0,0,0)\n // Hence fnew = f * V\n // dfnew = df * V + f * dV\n // ddfnew = ddf * V + df*dV + df * dV + f * ddV\n // but ddV is zero so\n // ddfnew = ddf * V + 2 * df * dV\n for (let step = 0; step <= depth; step++) {\n const tLeft = this.knots[kLeft++];\n const tRight = this.knots[kRight++];\n ah = 1.0 / (tRight - tLeft);\n const fraction = (u - tLeft) * ah;\n const fraction1 = 1.0 - fraction;\n const g1 = f[step] * fraction;\n const g0 = f[step] * fraction1;\n const dg1 = df[step] * fraction + f[step] * ah;\n const dg0 = df[step] * fraction1 - f[step] * ah;\n const dfSave = 2.0 * df[step] * ah;\n f[step] = gCarry + g0;\n df[step] = dgCarry + dg0;\n gCarry = g1;\n dgCarry = dg1;\n if (ddf) { // do the backward reference to df before rewriting df\n const ddg1 = ddf[step] * fraction + dfSave;\n const ddg0 = ddf[step] * fraction1 - dfSave;\n ddf[step] = ddgCarry + ddg0;\n ddgCarry = ddg1;\n }\n }\n f[depth + 1] = gCarry;\n df[depth + 1] = dgCarry;\n if (ddf)\n ddf[depth + 1] = ddgCarry;\n }\n return true;\n }\n /**\n * Find the knot span bracketing knots[i] <= u < knots[i+1] and return i.\n * * If u has no such bracket, return the smaller index of the closest nontrivial bracket.\n * @param u value to bracket.\n */\n public knotToLeftKnotIndex(u: number): number {\n for (let i = this.leftKnotIndex; i < this.rightKnotIndex; ++i) {\n if (u < this.knots[i + 1])\n return i;\n }\n // for u >= rightKnot, return left index of last nontrivial span\n for (let i = this.rightKnotIndex; i > this.leftKnotIndex; --i) {\n if (this.knots[i] - this.knots[i - 1] >= KnotVector.knotTolerance)\n return i - 1;\n }\n return this.rightKnotIndex - 1; // shouldn't get here\n }\n /**\n * Given a span index, return the index of the knot at its left.\n * @param spanIndex index of span.\n */\n public spanIndexToLeftKnotIndex(spanIndex: number): number {\n const d = this.degree;\n if (spanIndex <= 0.0)\n return d - 1;\n return Math.min(spanIndex + d - 1, this.knots.length - d - 1);\n }\n /** Return the knot interval length of indexed bezier span. */\n public spanIndexToSpanLength(spanIndex: number): number {\n const k = this.spanIndexToLeftKnotIndex(spanIndex);\n return this.knots[k + 1] - this.knots[k];\n }\n /**\n * Given a span index, test if it is within range and has nonzero length.\n * * note that a false return does not imply there are no more spans. This may be a double knot (zero length span)\n * followed by more real spans\n * @param spanIndex index of span to test.\n */\n public isIndexOfRealSpan(spanIndex: number): boolean {\n if (spanIndex >= 0 && spanIndex < this.numSpans)\n return !Geometry.isSmallMetricDistance(this.spanIndexToSpanLength(spanIndex));\n return false;\n }\n /** Reflect all knots so `leftKnot` and `rightKnot` are maintained but interval lengths are reversed. */\n public reflectKnots(): void {\n const a = this.leftKnot;\n const b = this.rightKnot;\n const numKnots = this.knots.length;\n for (let i = 0; i < numKnots; i++)\n this.knots[i] = a + (b - this.knots[i]);\n this.knots.reverse();\n }\n /** Return a simple array form of the knots. Optionally replicate the first and last in classic over-clamped manner. */\n public static copyKnots(\n knots: number[] | Float64Array, degree: number, includeExtraEndKnot?: boolean, wrapMode?: BSplineWrapMode,\n ): number[] {\n const isExtraEndKnotPeriodic = (includeExtraEndKnot && wrapMode === BSplineWrapMode.OpenByAddingControlPoints);\n const leftIndex = degree - 1;\n const rightIndex = knots.length - degree;\n const a0 = knots[leftIndex];\n const a1 = knots[rightIndex];\n const delta = a1 - a0;\n const values: number[] = [];\n if (includeExtraEndKnot) {\n if (isExtraEndKnotPeriodic)\n values.push(knots[rightIndex - degree] - delta);\n else\n values.push(knots[0]);\n }\n for (const u of knots) {\n values.push(u);\n }\n if (includeExtraEndKnot) {\n if (isExtraEndKnotPeriodic)\n values.push(knots[leftIndex + degree] + delta);\n else\n values.push(knots[knots.length - 1]);\n }\n return values;\n }\n /** Return a simple array form of the knots. Optionally replicate the first and last in classic over-clamped manner. */\n public copyKnots(includeExtraEndKnot: boolean): number[] {\n const wrapMode = (includeExtraEndKnot && this.testClosable()) ? this.wrappable : undefined;\n return KnotVector.copyKnots(this.knots, this.degree, includeExtraEndKnot, wrapMode);\n }\n}\n"]}
@@ -632,6 +632,8 @@ export declare class Arc3d extends CurvePrimitive implements BeJSONFunctions {
632
632
  projectedParameterRange(ray: Vector3d | Ray3d, lowHigh?: Range1d): Range1d | undefined;
633
633
  /**
634
634
  * Construct a circular arc chain approximation to the instance elliptical arc.
635
+ * * Visualization can be found at https://www.itwinjs.org/sandbox/SaeedTorabi/ArcApproximationGeneral and
636
+ * https://www.itwinjs.org/sandbox/SaeedTorabi/ArcApproximation
635
637
  * @param options bundle of options for sampling an elliptical arc (use default options if undefined).
636
638
  * @returns the approximating curve chain, the circular instance, or undefined if construction fails.
637
639
  */