@ac-kit/math-curves 0.1.10 → 0.2.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.
@@ -0,0 +1,42 @@
1
+ import { assertInteger } from "@ac-kit/core";
2
+ import { cubicHermite2Samples_ } from "./_hermite2-samples.js";
3
+ /**
4
+ * Samples the cubic Hermite curve from `p0` to `p1` with the tangents `m0` and
5
+ * `m1` (derivatives with respect to the parameter `u ∈ [0, 1]`, so a tangent
6
+ * equal to `p1 − p0` is the straight segment's): writes the points after `p0`
7
+ * at `u = 1/samples, 2/samples, …, 1`, the last one being exactly `p1`, so
8
+ * consecutive spans chain without a duplicate, as with the Bézier `…Flatten`.
9
+ * The same span as the Bézier with control points `p0`, `p0 + m0/3`, `p1 −
10
+ * m1/3`, `p1`.
11
+ *
12
+ * Evaluated relative to `p0` in a form that keeps a flat span (equal points,
13
+ * zero tangents) exactly flat and a straight span (both tangents `p1 − p0`)
14
+ * exactly evenly spaced. Non-finite input propagates `NaN` or `Infinity`.
15
+ * Accurate while the points' differences and the tangents lie within about
16
+ * [1e−150, 1e150] (S12); tangents near `Number.MAX_VALUE` overflow before they
17
+ * cancel.
18
+ *
19
+ * Complexity: O(samples) time, no allocation.
20
+ *
21
+ * @param out - Destination, 2 numbers (x, y) per point.
22
+ * @param offset - Index in `out` of the first number written.
23
+ * @param p0 - Start point (not written).
24
+ * @param m0 - Tangent at `p0`.
25
+ * @param p1 - End point.
26
+ * @param m1 - Tangent at `p1`.
27
+ * @param samples - Points written, a positive integer.
28
+ * @returns `samples`, the point count written (`2 · samples` numbers).
29
+ * @throws {RangeError} When `samples` is not a positive integer, `offset` is
30
+ * not a non-negative integer, or `out` has fewer than `offset + 2 · samples`
31
+ * numbers.
32
+ */
33
+ export function cubicHermite2Sample(out, offset, p0, m0, p1, m1, samples) {
34
+ assertInteger(samples, "samples", 1);
35
+ assertInteger(offset, "offset", 0);
36
+ if (offset + 2 * samples > out.length) {
37
+ throw new RangeError(`out needs ${offset + 2 * samples} numbers from offset ${offset} (${samples} points), has ${out.length}`);
38
+ }
39
+ cubicHermite2Samples_(out, offset, samples, p0[0], p0[1], m0[0], m0[1], p1[0], p1[1], m1[0], m1[1]);
40
+ return samples;
41
+ }
42
+ //# sourceMappingURL=hermite2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hermite2.js","sourceRoot":"","sources":["../src/hermite2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,mBAAmB,CAClC,GAAiB,EACjB,MAAc,EACd,EAAgB,EAChB,EAAgB,EAChB,EAAgB,EAChB,EAAgB,EAChB,OAAe;IAEf,aAAa,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;IACrC,aAAa,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;IAEnC,IAAI,MAAM,GAAG,CAAC,GAAG,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;QACvC,MAAM,IAAI,UAAU,CACnB,aAAa,MAAM,GAAG,CAAC,GAAG,OAAO,wBAAwB,MAAM,KAAK,OAAO,iBAAiB,GAAG,CAAC,MAAM,EAAE,CACxG,CAAC;IACH,CAAC;IAED,qBAAqB,CACpB,GAAG,EACH,MAAM,EACN,OAAO,EACP,EAAE,CAAC,CAAC,CAAC,EACL,EAAE,CAAC,CAAC,CAAC,EACL,EAAE,CAAC,CAAC,CAAC,EACL,EAAE,CAAC,CAAC,CAAC,EACL,EAAE,CAAC,CAAC,CAAC,EACL,EAAE,CAAC,CAAC,CAAC,EACL,EAAE,CAAC,CAAC,CAAC,EACL,EAAE,CAAC,CAAC,CAAC,CACL,CAAC;IAEF,OAAO,OAAO,CAAC;AAChB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
1
  export * from "./bezier2.js";
2
+ export * from "./bezier2-flatten.js";
3
+ export * from "./hermite2.js";
4
+ export * from "./spline2.js";
2
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,5 @@
1
1
  export * from "./bezier2.js";
2
+ export * from "./bezier2-flatten.js";
3
+ export * from "./hermite2.js";
4
+ export * from "./spline2.js";
2
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Samples the monotone cubic interpolant through points sorted by x: a
3
+ * piecewise cubic `y(x)` that is monotone on every run where the data is (no
4
+ * overshoot between points), with a continuous first derivative. Fritsch &
5
+ * Carlson, "Monotone piecewise cubic interpolation", SIAM J. Numer. Anal.
6
+ * 17(2), 1980: the tangent at a point is the mean of the two adjacent secant
7
+ * slopes, zero at a local extremum, then reduced where the pair of tangents
8
+ * leaves the monotonicity region (α² + β² > 9). End tangents are the end
9
+ * secants. The samples are evenly spaced in x within a span, and a flat run is
10
+ * exactly flat.
11
+ *
12
+ * Points must be sorted by non-decreasing x (not checked; unsorted input gives
13
+ * a curve that is not monotone). Two points with the same x make a vertical
14
+ * step: the secant slope there is taken as 0. Slopes are computed with x and y
15
+ * scaled by their largest step, so uniformly tiny or huge steps give a finite
16
+ * curve; steps whose ratio leaves [1e−150, 1e150] (a subnormal step beside a
17
+ * unit one) can overflow a slope.
18
+ *
19
+ * Complexity: O(n · samples) time, no allocation: the tangents are kept in
20
+ * `out` until the samples replace them (see `out` for the overlapping case).
21
+ *
22
+ * @param out - Destination, ((n − 1) · samples + 1) points; longer is allowed
23
+ * and the rest is left untouched. May share memory with `points`, even
24
+ * through two wrappers of one `SharedArrayBuffer`: the points are then copied
25
+ * first, into a buffer this module keeps and grows to the largest such input
26
+ * (the only allocation).
27
+ * @param points - N points, 2 numbers (x, y) each.
28
+ * @param samples - Points per span, a positive integer.
29
+ * @returns `out`.
30
+ * @throws {RangeError} When `points.length` is odd, `samples` is not a positive
31
+ * integer, or `out` is too short.
32
+ */
33
+ export declare function monotoneCubicSpline2<T extends Float64Array>(out: T, points: Float64Array, samples: number): T;
34
+ /**
35
+ * Samples the natural cubic spline through the points: the `C²` piecewise cubic
36
+ * that interpolates every point with zero second derivative at both ends, as a
37
+ * parametric curve `(x(s), y(s))` with the points at integer parameters (each
38
+ * coordinate is solved separately, the moments by the Thomas algorithm on the
39
+ * spline's (1, 4, 1) system; e.g. Burden & Faires, Numerical Analysis, §3.5).
40
+ * The points need not be sorted. It overshoots between points where the data is
41
+ * not smooth; use {@link monotoneCubicSpline2} to forbid that.
42
+ *
43
+ * Complexity: O(n · samples) time, no allocation: the elimination's
44
+ * intermediate values are kept in `out` until the samples replace them (see
45
+ * `out` for the overlapping case).
46
+ *
47
+ * @param out - Destination, ((n − 1) · samples + 1) points; longer is allowed
48
+ * and the rest is left untouched. May share memory with `points`, even
49
+ * through two wrappers of one `SharedArrayBuffer`: the points are then copied
50
+ * first, into a buffer this module keeps and grows to the largest such input
51
+ * (the only allocation).
52
+ * @param points - N points, 2 numbers (x, y) each.
53
+ * @param samples - Points per span, a positive integer.
54
+ * @returns `out`.
55
+ * @throws {RangeError} When `points.length` is odd, `samples` is not a positive
56
+ * integer, or `out` is too short.
57
+ */
58
+ export declare function naturalCubicSpline2<T extends Float64Array>(out: T, points: Float64Array, samples: number): T;
59
+ /**
60
+ * Samples the uniform cubic B-spline whose control points are the given points:
61
+ * a `C²` curve that approximates rather than interpolates (it is smoother than
62
+ * the polygon, the shape of d3's `curveBasis`). The curve is made to start at
63
+ * the first point and end at the last by extending the polygon with the
64
+ * reflections `2·P₀ − P₁` and `2·Pₙ₋₁ − Pₙ₋₂`, and runs over each span `Pᵢ →
65
+ * Pᵢ₊₁` with the control points `Pᵢ₋₁ … Pᵢ₊₂`; with two points it is the
66
+ * straight segment. (d3 instead starts with a chord to `(5·P₀ + P₁) / 6`.) The
67
+ * inner points are not interpolated: the curve passes through `(Pᵢ₋₁ + 4·Pᵢ +
68
+ * Pᵢ₊₁) / 6`. De Boor, "On calculating with B-splines", J. Approx. Theory 6, 1972.
69
+ *
70
+ * Complexity: O(n · samples) time, no allocation (see `out` for the overlapping
71
+ * case).
72
+ *
73
+ * @param out - Destination, ((n − 1) · samples + 1) points; longer is allowed
74
+ * and the rest is left untouched. May share memory with `points`, even
75
+ * through two wrappers of one `SharedArrayBuffer`: the points are then copied
76
+ * first, into a buffer this module keeps and grows to the largest such input
77
+ * (the only allocation).
78
+ * @param points - N control points, 2 numbers (x, y) each.
79
+ * @param samples - Points per span, a positive integer.
80
+ * @returns `out`.
81
+ * @throws {RangeError} When `points.length` is odd, `samples` is not a positive
82
+ * integer, or `out` is too short.
83
+ */
84
+ export declare function uniformBSpline2<T extends Float64Array>(out: T, points: Float64Array, samples: number): T;
85
+ /**
86
+ * Samples the cardinal spline through the points: a `C¹` piecewise cubic
87
+ * Hermite curve interpolating every point, whose tangent at `Pᵢ` is `(1 −
88
+ * tension) · (Pᵢ₊₁ − Pᵢ₋₁) / 2` (the end points are repeated, so the end
89
+ * tangents are `(1 − tension) · (P₁ − P₀) / 2`). `tension = 0` is the uniform
90
+ * Catmull–Rom spline, `tension = 1` zero tangents (an eased polyline), and a
91
+ * negative tension loosens the curve; d3's `curveCardinal` parameterisation.
92
+ * The points need not be sorted. Uniform parameterisation: unevenly spaced
93
+ * points can overshoot or form cusps (there is no centripetal variant yet).
94
+ * Catmull & Rom, "A class of local interpolating splines", 1974.
95
+ *
96
+ * Complexity: O(n · samples) time, no allocation (see `out` for the overlapping
97
+ * case).
98
+ *
99
+ * @param out - Destination, ((n − 1) · samples + 1) points; longer is allowed
100
+ * and the rest is left untouched. May share memory with `points`, even
101
+ * through two wrappers of one `SharedArrayBuffer`: the points are then copied
102
+ * first, into a buffer this module keeps and grows to the largest such input
103
+ * (the only allocation).
104
+ * @param points - N points, 2 numbers (x, y) each.
105
+ * @param samples - Points per span, a positive integer.
106
+ * @param tension - Tangent shrink, usually in [0, 1].
107
+ * @returns `out`.
108
+ * @throws {RangeError} When `points.length` is odd, `samples` is not a positive
109
+ * integer, or `out` is too short.
110
+ */
111
+ export declare function cardinalSpline2<T extends Float64Array>(out: T, points: Float64Array, samples: number, tension: number): T;
112
+ //# sourceMappingURL=spline2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spline2.d.ts","sourceRoot":"","sources":["../src/spline2.ts"],"names":[],"mappings":"AAkHA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,YAAY,EAC1D,GAAG,EAAE,CAAC,EACN,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,MAAM,GACb,CAAC,CAUH;AAwGD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,YAAY,EACzD,GAAG,EAAE,CAAC,EACN,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,MAAM,GACb,CAAC,CAUH;AAqFD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,YAAY,EACrD,GAAG,EAAE,CAAC,EACN,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,MAAM,GACb,CAAC,CAoDH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,YAAY,EACrD,GAAG,EAAE,CAAC,EACN,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACb,CAAC,CAiDH"}
@@ -0,0 +1,385 @@
1
+ import { assertInteger, viewsMayOverlap } from "@ac-kit/core";
2
+ import { cubicHermite2Samples_ } from "./_hermite2-samples.js";
3
+ // Sampled interpolating and approximating splines through `Vec2` buffers (x, y
4
+ // pairs), for the line interpolations of a chart. Every function writes the
5
+ // first point, then `samples` points per span between consecutive input points,
6
+ // the last of them exactly the span's end point, so `out` holds
7
+ // ((n − 1) · samples + 1) points.
8
+ //
9
+ // Every span is a cubic Hermite span sampled by `cubicHermite2Samples_`, which
10
+ // works on differences relative to the span's start: a flat run stays exactly
11
+ // flat, a straight span exactly evenly spaced, and huge coordinates keep their
12
+ // digits. The spline coefficients are built from differences of consecutive
13
+ // points too, never from the coordinates themselves. The arithmetic range is
14
+ // that of lengths (S12): results are guaranteed while the differences between
15
+ // consecutive points lie within about [1e−150, 1e150]; beyond (a subnormal step
16
+ // beside a unit one, a 1e308 bend), a slope or tangent can overflow to
17
+ // Infinity or NaN. Non-finite input propagates NaN or Infinity into the output
18
+ // (S13).
19
+ function expectedLength_(name, out, points, samples) {
20
+ if (points.length % 2 !== 0) {
21
+ throw new RangeError(`${name}: points must be a multiple of 2 long.`);
22
+ }
23
+ assertInteger(samples, "samples", 1);
24
+ const count = points.length / 2;
25
+ const length = count === 0 ? 0 : ((count - 1) * samples + 1) * 2;
26
+ if (out.length < length) {
27
+ throw new RangeError(`${name}: out needs ${length} numbers for ${count} points and ${samples} samples, has ${out.length}.`);
28
+ }
29
+ return count;
30
+ }
31
+ /**
32
+ * The points copied out of `out`'s memory when the two may overlap: every
33
+ * spline writes samples over a longer run than the points it still has to read
34
+ * (and the first two keep their tangents in `out`), so at some offset of `out`
35
+ * into `points` any evaluation order overwrites a point still to be read. Grown
36
+ * geometrically and kept, so a sampler allocates only for a larger overlapping
37
+ * input than any before; no sampler runs caller code while it holds the copy,
38
+ * so one buffer serves them all.
39
+ */
40
+ let pointsCopy_ = new Float64Array(0);
41
+ // `points` itself, or its copy in `pointsCopy_` (possibly longer: the samplers
42
+ // read only the first `points.length` numbers) when it may share memory with
43
+ // `out` (the same array, overlapping views, or wrappers of one shared memory).
44
+ function separate_(out, points) {
45
+ if (!viewsMayOverlap(out, points)) {
46
+ return points;
47
+ }
48
+ if (pointsCopy_.length < points.length) {
49
+ pointsCopy_ = new Float64Array(Math.max(points.length, 2 * pointsCopy_.length));
50
+ }
51
+ pointsCopy_.set(points);
52
+ return pointsCopy_;
53
+ }
54
+ // The first-row coefficients c′ of the Thomas algorithm on the natural
55
+ // spline's (1, 4, 1) system: c′₁ = 1/4, c′ⱼ = 1 / (4 − c′ⱼ₋₁). They depend on
56
+ // nothing else and reach a fixed point in about twenty steps (the ratio is
57
+ // (2 − √3)² per step), so they are tabulated once, the last entry standing for
58
+ // every later one.
59
+ function thomasCoefficients_() {
60
+ const values = [0, 0.25];
61
+ for (;;) {
62
+ const next = 1 / (4 - values.at(-1));
63
+ if (next === values.at(-1)) {
64
+ return Float64Array.from(values);
65
+ }
66
+ values.push(next);
67
+ }
68
+ }
69
+ const THOMAS_COEFFICIENTS_ = thomasCoefficients_();
70
+ function thomasCoefficient_(index) {
71
+ const last = THOMAS_COEFFICIENTS_.length - 1;
72
+ return THOMAS_COEFFICIENTS_[index < last ? index : last];
73
+ }
74
+ // The secant slope of span `index` in the scaled units (y / scaleY) /
75
+ // (x / scaleX), 0 for a vertical step.
76
+ function secant_(points, index, scaleX, scaleY) {
77
+ const dx = points[2 * index + 2] - points[2 * index];
78
+ return dx === 0
79
+ ? 0
80
+ : (points[2 * index + 3] - points[2 * index + 1]) /
81
+ scaleY /
82
+ (dx / scaleX);
83
+ }
84
+ /**
85
+ * Samples the monotone cubic interpolant through points sorted by x: a
86
+ * piecewise cubic `y(x)` that is monotone on every run where the data is (no
87
+ * overshoot between points), with a continuous first derivative. Fritsch &
88
+ * Carlson, "Monotone piecewise cubic interpolation", SIAM J. Numer. Anal.
89
+ * 17(2), 1980: the tangent at a point is the mean of the two adjacent secant
90
+ * slopes, zero at a local extremum, then reduced where the pair of tangents
91
+ * leaves the monotonicity region (α² + β² > 9). End tangents are the end
92
+ * secants. The samples are evenly spaced in x within a span, and a flat run is
93
+ * exactly flat.
94
+ *
95
+ * Points must be sorted by non-decreasing x (not checked; unsorted input gives
96
+ * a curve that is not monotone). Two points with the same x make a vertical
97
+ * step: the secant slope there is taken as 0. Slopes are computed with x and y
98
+ * scaled by their largest step, so uniformly tiny or huge steps give a finite
99
+ * curve; steps whose ratio leaves [1e−150, 1e150] (a subnormal step beside a
100
+ * unit one) can overflow a slope.
101
+ *
102
+ * Complexity: O(n · samples) time, no allocation: the tangents are kept in
103
+ * `out` until the samples replace them (see `out` for the overlapping case).
104
+ *
105
+ * @param out - Destination, ((n − 1) · samples + 1) points; longer is allowed
106
+ * and the rest is left untouched. May share memory with `points`, even
107
+ * through two wrappers of one `SharedArrayBuffer`: the points are then copied
108
+ * first, into a buffer this module keeps and grows to the largest such input
109
+ * (the only allocation).
110
+ * @param points - N points, 2 numbers (x, y) each.
111
+ * @param samples - Points per span, a positive integer.
112
+ * @returns `out`.
113
+ * @throws {RangeError} When `points.length` is odd, `samples` is not a positive
114
+ * integer, or `out` is too short.
115
+ */
116
+ export function monotoneCubicSpline2(out, points, samples) {
117
+ const count = expectedLength_("monotoneCubicSpline2", out, points, samples);
118
+ if (count === 0) {
119
+ return out;
120
+ }
121
+ monotoneSamples_(out, separate_(out, points), count, samples);
122
+ return out;
123
+ }
124
+ // The monotone spline of the first `count` points of `points`, which does not
125
+ // share memory with `out`; no check.
126
+ function monotoneSamples_(out, points, count, samples) {
127
+ if (count === 1) {
128
+ out[0] = points[0];
129
+ out[1] = points[1];
130
+ return;
131
+ }
132
+ let scaleX = 0;
133
+ let scaleY = 0;
134
+ for (let index = 0; index < count - 1; index++) {
135
+ scaleX = Math.max(scaleX, Math.abs(points[2 * index + 2] - points[2 * index]));
136
+ scaleY = Math.max(scaleY, Math.abs(points[2 * index + 3] - points[2 * index + 1]));
137
+ }
138
+ if (scaleX === 0) {
139
+ scaleX = 1;
140
+ }
141
+ if (scaleY === 0) {
142
+ scaleY = 1;
143
+ }
144
+ // The tangent at point i is kept in out[2i + 1] until the spans are
145
+ // sampled, last span first: span i writes from out[2(i·samples + 1)] on,
146
+ // past every tangent a span before it still reads.
147
+ let before = secant_(points, 0, scaleX, scaleY);
148
+ out[1] = before;
149
+ for (let index = 1; index < count - 1; index++) {
150
+ const after = secant_(points, index, scaleX, scaleY);
151
+ out[2 * index + 1] = before * after <= 0 ? 0 : (before + after) / 2;
152
+ before = after;
153
+ }
154
+ out[2 * count - 1] = before;
155
+ for (let index = 0; index < count - 1; index++) {
156
+ const secant = secant_(points, index, scaleX, scaleY);
157
+ if (secant === 0) {
158
+ out[2 * index + 1] = 0;
159
+ out[2 * index + 3] = 0;
160
+ continue;
161
+ }
162
+ const alpha = out[2 * index + 1] / secant;
163
+ const beta = out[2 * index + 3] / secant;
164
+ const radiusSquared = alpha * alpha + beta * beta;
165
+ if (radiusSquared > 9) {
166
+ const scale = (3 / Math.sqrt(radiusSquared)) * secant;
167
+ out[2 * index + 1] = scale * alpha;
168
+ out[2 * index + 3] = scale * beta;
169
+ }
170
+ }
171
+ for (let index = count - 2; index >= 0; index--) {
172
+ const x0 = points[2 * index];
173
+ const x1 = points[2 * index + 2];
174
+ const dx = x1 - x0;
175
+ const step = dx / scaleX;
176
+ const startTangent = out[2 * index + 1];
177
+ const endTangent = out[2 * index + 3];
178
+ cubicHermite2Samples_(out, 2 * (index * samples + 1), samples, x0, points[2 * index + 1], dx, startTangent * step * scaleY, x1, points[2 * index + 3], dx, endTangent * step * scaleY);
179
+ }
180
+ out[0] = points[0];
181
+ out[1] = points[1];
182
+ }
183
+ /**
184
+ * Samples the natural cubic spline through the points: the `C²` piecewise cubic
185
+ * that interpolates every point with zero second derivative at both ends, as a
186
+ * parametric curve `(x(s), y(s))` with the points at integer parameters (each
187
+ * coordinate is solved separately, the moments by the Thomas algorithm on the
188
+ * spline's (1, 4, 1) system; e.g. Burden & Faires, Numerical Analysis, §3.5).
189
+ * The points need not be sorted. It overshoots between points where the data is
190
+ * not smooth; use {@link monotoneCubicSpline2} to forbid that.
191
+ *
192
+ * Complexity: O(n · samples) time, no allocation: the elimination's
193
+ * intermediate values are kept in `out` until the samples replace them (see
194
+ * `out` for the overlapping case).
195
+ *
196
+ * @param out - Destination, ((n − 1) · samples + 1) points; longer is allowed
197
+ * and the rest is left untouched. May share memory with `points`, even
198
+ * through two wrappers of one `SharedArrayBuffer`: the points are then copied
199
+ * first, into a buffer this module keeps and grows to the largest such input
200
+ * (the only allocation).
201
+ * @param points - N points, 2 numbers (x, y) each.
202
+ * @param samples - Points per span, a positive integer.
203
+ * @returns `out`.
204
+ * @throws {RangeError} When `points.length` is odd, `samples` is not a positive
205
+ * integer, or `out` is too short.
206
+ */
207
+ export function naturalCubicSpline2(out, points, samples) {
208
+ const count = expectedLength_("naturalCubicSpline2", out, points, samples);
209
+ if (count === 0) {
210
+ return out;
211
+ }
212
+ naturalSamples_(out, separate_(out, points), count, samples);
213
+ return out;
214
+ }
215
+ // The natural spline of the first `count` points of `points`, which does not
216
+ // share memory with `out`; no check.
217
+ function naturalSamples_(out, points, count, samples) {
218
+ // The second derivatives M at the inner points satisfy
219
+ // M_{i−1} + 4·M_i + M_{i+1} = 6 · ((P_{i+1} − P_i) − (P_i − P_{i−1})),
220
+ // with M_0 = M_{n−1} = 0: strictly diagonally dominant, so the Thomas
221
+ // algorithm is stable and meets no zero pivot. Its forward sweep leaves d′ᵢ
222
+ // in out[2i], out[2i + 1]; the back substitution runs with the sampling,
223
+ // last span first, span i writing from out[2(i·samples + 1)] on, past every
224
+ // d′ a span before it still reads.
225
+ let previousX = 0;
226
+ let previousY = 0;
227
+ for (let index = 1; index < count - 1; index++) {
228
+ const coefficient = thomasCoefficient_(index);
229
+ previousX =
230
+ (6 *
231
+ (points[2 * index + 2] -
232
+ points[2 * index] -
233
+ (points[2 * index] - points[2 * index - 2])) -
234
+ previousX) *
235
+ coefficient;
236
+ previousY =
237
+ (6 *
238
+ (points[2 * index + 3] -
239
+ points[2 * index + 1] -
240
+ (points[2 * index + 1] - points[2 * index - 1])) -
241
+ previousY) *
242
+ coefficient;
243
+ out[2 * index] = previousX;
244
+ out[2 * index + 1] = previousY;
245
+ }
246
+ let endX = 0;
247
+ let endY = 0;
248
+ for (let index = count - 2; index >= 0; index--) {
249
+ let startX = 0;
250
+ let startY = 0;
251
+ if (index > 0) {
252
+ const coefficient = thomasCoefficient_(index);
253
+ startX = out[2 * index] - coefficient * endX;
254
+ startY = out[2 * index + 1] - coefficient * endY;
255
+ }
256
+ const x0 = points[2 * index];
257
+ const y0 = points[2 * index + 1];
258
+ const x1 = points[2 * index + 2];
259
+ const y1 = points[2 * index + 3];
260
+ const dx = x1 - x0;
261
+ const dy = y1 - y0;
262
+ // S(u) = (1 − u)·P_i + u·P_{i+1} + ((1 − u)³ − (1 − u))·M_i / 6 +
263
+ // (u³ − u)·M_{i+1} / 6, whose end derivatives are these tangents.
264
+ cubicHermite2Samples_(out, 2 * (index * samples + 1), samples, x0, y0, dx - (2 * startX + endX) / 6, dy - (2 * startY + endY) / 6, x1, y1, dx + (startX + 2 * endX) / 6, dy + (startY + 2 * endY) / 6);
265
+ endX = startX;
266
+ endY = startY;
267
+ }
268
+ out[0] = points[0];
269
+ out[1] = points[1];
270
+ }
271
+ /**
272
+ * Samples the uniform cubic B-spline whose control points are the given points:
273
+ * a `C²` curve that approximates rather than interpolates (it is smoother than
274
+ * the polygon, the shape of d3's `curveBasis`). The curve is made to start at
275
+ * the first point and end at the last by extending the polygon with the
276
+ * reflections `2·P₀ − P₁` and `2·Pₙ₋₁ − Pₙ₋₂`, and runs over each span `Pᵢ →
277
+ * Pᵢ₊₁` with the control points `Pᵢ₋₁ … Pᵢ₊₂`; with two points it is the
278
+ * straight segment. (d3 instead starts with a chord to `(5·P₀ + P₁) / 6`.) The
279
+ * inner points are not interpolated: the curve passes through `(Pᵢ₋₁ + 4·Pᵢ +
280
+ * Pᵢ₊₁) / 6`. De Boor, "On calculating with B-splines", J. Approx. Theory 6, 1972.
281
+ *
282
+ * Complexity: O(n · samples) time, no allocation (see `out` for the overlapping
283
+ * case).
284
+ *
285
+ * @param out - Destination, ((n − 1) · samples + 1) points; longer is allowed
286
+ * and the rest is left untouched. May share memory with `points`, even
287
+ * through two wrappers of one `SharedArrayBuffer`: the points are then copied
288
+ * first, into a buffer this module keeps and grows to the largest such input
289
+ * (the only allocation).
290
+ * @param points - N control points, 2 numbers (x, y) each.
291
+ * @param samples - Points per span, a positive integer.
292
+ * @returns `out`.
293
+ * @throws {RangeError} When `points.length` is odd, `samples` is not a positive
294
+ * integer, or `out` is too short.
295
+ */
296
+ export function uniformBSpline2(out, points, samples) {
297
+ const count = expectedLength_("uniformBSpline2", out, points, samples);
298
+ if (count === 0) {
299
+ return out;
300
+ }
301
+ const source = separate_(out, points);
302
+ out[0] = source[0];
303
+ out[1] = source[1];
304
+ if (count === 1) {
305
+ return out;
306
+ }
307
+ let offset = 2;
308
+ for (let index = 0; index < count - 1; index++) {
309
+ const x = source[2 * index];
310
+ const y = source[2 * index + 1];
311
+ const nextX = source[2 * index + 2];
312
+ const nextY = source[2 * index + 3];
313
+ // Steps of the control polygon around the span: P_{i−1} − P_i, P_{i+1} −
314
+ // P_i and P_{i+2} − P_{i+1}, the reflected end points giving −(P_1 − P_0)
315
+ // and P_{n−1} − P_{n−2}.
316
+ const afterX = nextX - x;
317
+ const afterY = nextY - y;
318
+ const beforeX = index === 0 ? -afterX : source[2 * index - 2] - x;
319
+ const beforeY = index === 0 ? -afterY : source[2 * index - 1] - y;
320
+ const farX = index + 2 < count ? source[2 * index + 4] - nextX : afterX;
321
+ const farY = index + 2 < count ? source[2 * index + 5] - nextY : afterY;
322
+ // The span from (P_{i−1} + 4·P_i + P_{i+1}) / 6 to (P_i + 4·P_{i+1} +
323
+ // P_{i+2}) / 6, with the end derivatives (P_{i+1} − P_{i−1}) / 2 and
324
+ // (P_{i+2} − P_i) / 2, all written through the steps.
325
+ offset = cubicHermite2Samples_(out, offset, samples, x + (beforeX + afterX) / 6, y + (beforeY + afterY) / 6, (afterX - beforeX) / 2, (afterY - beforeY) / 2, nextX + (farX - afterX) / 6, nextY + (farY - afterY) / 6, (afterX + farX) / 2, (afterY + farY) / 2);
326
+ }
327
+ return out;
328
+ }
329
+ /**
330
+ * Samples the cardinal spline through the points: a `C¹` piecewise cubic
331
+ * Hermite curve interpolating every point, whose tangent at `Pᵢ` is `(1 −
332
+ * tension) · (Pᵢ₊₁ − Pᵢ₋₁) / 2` (the end points are repeated, so the end
333
+ * tangents are `(1 − tension) · (P₁ − P₀) / 2`). `tension = 0` is the uniform
334
+ * Catmull–Rom spline, `tension = 1` zero tangents (an eased polyline), and a
335
+ * negative tension loosens the curve; d3's `curveCardinal` parameterisation.
336
+ * The points need not be sorted. Uniform parameterisation: unevenly spaced
337
+ * points can overshoot or form cusps (there is no centripetal variant yet).
338
+ * Catmull & Rom, "A class of local interpolating splines", 1974.
339
+ *
340
+ * Complexity: O(n · samples) time, no allocation (see `out` for the overlapping
341
+ * case).
342
+ *
343
+ * @param out - Destination, ((n − 1) · samples + 1) points; longer is allowed
344
+ * and the rest is left untouched. May share memory with `points`, even
345
+ * through two wrappers of one `SharedArrayBuffer`: the points are then copied
346
+ * first, into a buffer this module keeps and grows to the largest such input
347
+ * (the only allocation).
348
+ * @param points - N points, 2 numbers (x, y) each.
349
+ * @param samples - Points per span, a positive integer.
350
+ * @param tension - Tangent shrink, usually in [0, 1].
351
+ * @returns `out`.
352
+ * @throws {RangeError} When `points.length` is odd, `samples` is not a positive
353
+ * integer, or `out` is too short.
354
+ */
355
+ export function cardinalSpline2(out, points, samples, tension) {
356
+ const count = expectedLength_("cardinalSpline2", out, points, samples);
357
+ if (count === 0) {
358
+ return out;
359
+ }
360
+ const source = separate_(out, points);
361
+ out[0] = source[0];
362
+ out[1] = source[1];
363
+ if (count === 1) {
364
+ return out;
365
+ }
366
+ const scale = (1 - tension) / 2;
367
+ let offset = 2;
368
+ for (let index = 0; index < count - 1; index++) {
369
+ const x0 = source[2 * index];
370
+ const y0 = source[2 * index + 1];
371
+ const x1 = source[2 * index + 2];
372
+ const y1 = source[2 * index + 3];
373
+ const stepX = x1 - x0;
374
+ const stepY = y1 - y0;
375
+ // P_{i+1} − P_{i−1} as the sum of the two steps around each end; a
376
+ // repeated end point contributes a zero step.
377
+ const beforeX = index === 0 ? 0 : x0 - source[2 * index - 2];
378
+ const beforeY = index === 0 ? 0 : y0 - source[2 * index - 1];
379
+ const afterX = index + 2 < count ? source[2 * index + 4] - x1 : 0;
380
+ const afterY = index + 2 < count ? source[2 * index + 5] - y1 : 0;
381
+ offset = cubicHermite2Samples_(out, offset, samples, x0, y0, scale * (beforeX + stepX), scale * (beforeY + stepY), x1, y1, scale * (stepX + afterX), scale * (stepY + afterY));
382
+ }
383
+ return out;
384
+ }
385
+ //# sourceMappingURL=spline2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spline2.js","sourceRoot":"","sources":["../src/spline2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,+EAA+E;AAC/E,4EAA4E;AAC5E,gFAAgF;AAChF,gEAAgE;AAChE,kCAAkC;AAClC,EAAE;AACF,+EAA+E;AAC/E,8EAA8E;AAC9E,+EA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,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAE,CAAC;QAC9D,MAAM,OAAO,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAE,CAAC;QAC9D,MAAM,MAAM,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACnE,MAAM,MAAM,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAEnE,MAAM,GAAG,qBAAqB,CAC7B,GAAG,EACH,MAAM,EACN,OAAO,EACP,EAAE,EACF,EAAE,EACF,KAAK,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,EACzB,KAAK,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,EACzB,EAAE,EACF,EAAE,EACF,KAAK,GAAG,CAAC,KAAK,GAAG,MAAM,CAAC,EACxB,KAAK,GAAG,CAAC,KAAK,GAAG,MAAM,CAAC,CACxB,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACZ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ac-kit/math-curves",
3
- "version": "0.1.10",
3
+ "version": "0.2.1",
4
4
  "description": "Parametric curves: Bezier segments, splines, and evaluation, subdivision, arc length and closest point over them.",
5
5
  "keywords": [
6
6
  "bezier",
@@ -44,15 +44,17 @@
44
44
  "prepack": "yarn build"
45
45
  },
46
46
  "dependencies": {
47
- "@ac-kit/core": "^0.11.0",
48
- "@ac-kit/math-linear": "^0.2.1",
49
- "@ac-kit/math-scalar": "^0.2.3",
47
+ "@ac-kit/core": "^0.13.0",
48
+ "@ac-kit/math-linear": "^0.4.0",
50
49
  "@types/web": "^0.0.367"
51
50
  },
52
51
  "devDependencies": {
52
+ "@ac-kit/math-geometry": "0.4.0",
53
+ "@ac-kit/math-random": "0.4.1",
54
+ "@ac-kit/test-util": "0.5.0",
53
55
  "@ac-kit/tsconfig": "0.1.0",
54
56
  "@ac-kit/typedoc-config": "0.1.0",
55
- "@ac-kit/vitest-config": "0.1.1",
57
+ "@ac-kit/vitest-config": "0.2.0",
56
58
  "@typescript/native": "typescript@7.0.2",
57
59
  "rimraf": "6.1.4",
58
60
  "typedoc": "0.28.20",