curve-ops 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +437 -14
  2. package/index.d.ts +705 -134
  3. package/index.js +1 -1
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -9,21 +9,56 @@ code removal) for minimal deployed code size.
9
9
 
10
10
  ## Features
11
11
 
12
- - 2D point / vector operations
13
- - Type-safe matrix operations
14
- - multiplication
15
- - inversion (up to size 4x4)
16
- - Polynomial root finding (1st, 2nd, 3rd, and 6th order)
17
12
  - Various shapes
18
- - Axis-Aligned Bounding Boxes
19
- - Rectangles
20
- - Circles
21
- - Lines (line segments)
22
- - Quadratic Béziers
23
- - Cubic Béziers
13
+ - `AxisAlignedBox` (`aaBox`): 2D Axis-Aligned Boxes (typically bounding boxes)
14
+ - `Rectangle` (`rect`): 2D Rectangles with orientation
15
+ - `Circle` (`circ`): 2D Circles
16
+ - `LineSegment` (`line`): 2D Line Segments
17
+ - `Polygon` (`polygon`): 2D closed shapes formed of straight line segments
18
+ - `Polyline<Dim>`: Any dimension (`Dim`) open shapes formed of straight line
19
+ segments
20
+ - `Polyline2D`: Optimisations and extra features for 2D polylines
21
+ - Béziers
22
+ - `Bezier<N, Dim>` (`bezier`): Any degree (`N-1`), any dimension (`Dim`)
23
+ - `QuadraticBezier` (`bezier2`) / `CubicBezier` (`bezier3`): Optimisations
24
+ and extra features for 2D quadratic and cubic Béziers
24
25
  - Shape overlap detection
25
- - Shape intersection
26
- - Least squares curve fitting with optional fixed endpoints and direction
26
+ - Shape intersection, subtraction
27
+ - Least squares curve fitting
28
+ - optional fixed endpoints and direction
29
+ - `Vector<N>` (`vec`): n-D point / vector operations
30
+ - `Pt`: Optimisations and extra features for 2D vectors
31
+ - `Matrix<M, N>` (`mat`): Type-safe matrix operations
32
+ - multiplication / addition / subtraction / etc.
33
+ - inversion (up to size 4x4)
34
+ - optimised implementations for 1x1, 2x2, 3x3, and 4x4 matrices
35
+ - `Quaternion` (`quat`): Quaternion operations
36
+ - multiplication / addition / subtraction / etc.
37
+ - linear (`lerp`) and spherical linear (`slerp`) interpolation
38
+ - 3D rotation matrix conversions
39
+ - `Polynomial<N>` (`polynomial`): Polynomial operations of any order (`N-1`)
40
+ - multiplication / addition / subtraction / etc.
41
+ - integration / differentiation
42
+ - root finding (1st, 2nd, 3rd, 4th, and 6th order)
43
+ - `ComplexNumber` (`z`): Complex numbers
44
+ - multiplication / addition / subtraction / etc.
45
+ - exponentiation
46
+ - Mathematical functions
47
+ - `erf` / `erfc` (+ complex erfc)
48
+ - Fresnel S and C integrals
49
+ - binomial coefficients
50
+ - Typescript type helpers
51
+ - Numerical
52
+ - `Increment<N>` / `Decrement<N>`
53
+ - `Multiply<A, B>` / `DivideWhole<N, D>`
54
+ - `Max<A, B>`
55
+ - `Sign`
56
+ - Array / tuple
57
+ - `SizedArray<T, N>`: a tuple containing `N` items of type `T`
58
+ - `SizedArrayWithLength<T, N>`: same as `SizedArray` but with an explicit
59
+ `length` property, which can be useful for some type inference (but
60
+ detremental in other situations)
61
+ - `SizeOf`: extract the size of a tuple or array
27
62
 
28
63
  ## Installing
29
64
 
@@ -33,7 +68,395 @@ npm install --save curve-ops
33
68
 
34
69
  ## Usage
35
70
 
36
- TODO
71
+ All functions, types, and constants can be imported by name from `'curve-ops'`,
72
+ for example:
73
+
74
+ ```js
75
+ import { aaBoxSVG, bezier3Bounds, bezier3FromPts, bezier3SVG } from 'curve-ops';
76
+
77
+ const curve = bezier3FromPts(
78
+ { x: 50, y: 50 },
79
+ { x: 500, y: 450 },
80
+ { x: 0, y: 400 },
81
+ { x: 300, y: 100 },
82
+ );
83
+ const bounds = bezier3Bounds(curve);
84
+
85
+ // Display as an SVG:
86
+
87
+ const SVGNS = 'http://www.w3.org/2000/svg';
88
+ const svg = document.createElementNS(SVGNS, 'svg');
89
+ svg.setAttribute('version', '1.1');
90
+ svg.setAttribute('viewBox', '0 0 500 500');
91
+ svg.setAttribute('width', '500');
92
+ svg.setAttribute('height', '500');
93
+ document.body.append(svg);
94
+
95
+ const bbPath = document.createElementNS(SVGNS, 'path');
96
+ bbPath.setAttribute('stroke', 'green');
97
+ bbPath.setAttribute('fill', 'none');
98
+ bbPath.setAttribute('d', aaBoxSVG(bounds));
99
+ svg.append(bbPath);
100
+
101
+ const curvePath = document.createElementNS(SVGNS, 'path');
102
+ curvePath.setAttribute('stroke', 'black');
103
+ curvePath.setAttribute('fill', 'none');
104
+ curvePath.setAttribute('d', bezier3SVG(curve));
105
+ svg.append(curvePath);
106
+ ```
107
+
108
+ ### Functions
109
+
110
+ Functions are named accodring to the type of entity they work with. For example,
111
+ functions which work with `AxisAlignedBox` entities contain `aaBox` in their
112
+ name.
113
+
114
+ Unless otherwise noted, all functions leave their arguments unchanged, returning
115
+ a new entity for the result.
116
+
117
+ - `aaBoxArea(box)`
118
+ - `aaBoxContains(box, pt)`
119
+ - `aaBoxFromXY(xs, ys)`
120
+ - `aaBoxMidpoint(box)`
121
+ - `aaBoxSVG(box)`
122
+ - `addZ(a, b)`
123
+ - `addZR(a, b)`
124
+ - `bezier2At(curve, t)`
125
+ - `bezier2Bisect(curve, t = 0.5)`
126
+ - `bezier2Bounds(curve)`
127
+ - `bezier2Derivative(curve)`
128
+ - `bezier2FromBezier(curve)`
129
+ - `bezier2FromLine(line)`
130
+ - `bezier2FromPolylinePtsLeastSquares(pts)`
131
+ - `bezier2FromPolylinePtsLeastSquaresFixEnds(pts, previous?)`
132
+ - `bezier2FromPts(pts)`
133
+ - `bezier2LengthEstimate(curve)`
134
+ - `bezier2NormalAt(curve, t)`
135
+ - `bezier2PolynomialX(curve)`
136
+ - `bezier2PolynomialY(curve)`
137
+ - `bezier2RMSDistance(curve, pts)`
138
+ - `bezier2Split(curve, ts)`
139
+ - `bezier2SVG(curve)`
140
+ - `bezier2TangentAt(curve, t)`
141
+ - `bezier2Translate(curve, delta)`
142
+ - `bezier2TsAtXEq(curve, x)`
143
+ - `bezier2TsAtYEq(curve, y)`
144
+ - `bezier2XAt(curve, t)`
145
+ - `bezier2XTurningPointTs(curve)`
146
+ - `bezier2YAt(curve, t)`
147
+ - `bezier2YTurningPointTs(curve)`
148
+ - `bezier3At(curve, t)`
149
+ - `bezier3Bisect(curve, t = 0.5)`
150
+ - `bezier3Bounds(curve)`
151
+ - `bezier3Derivative(curve)`
152
+ - `bezier3FromBezier(curve)`
153
+ - `bezier3FromBezier2(curve)`
154
+ - `bezier3FromLine(line)`
155
+ - `bezier3FromPolylinePtsLeastSquares(pts)`
156
+ - `bezier3FromPolylinePtsLeastSquaresFixEnds(pts, previous?)`
157
+ - `bezier3FromPts(pts)`
158
+ - `bezier3FromQuad(p0, c1, c2, p3)`
159
+ - `bezier3LengthEstimate(curve)`
160
+ - `bezier3NormalAt(curve, t)`
161
+ - `bezier3Normalise(curve)`
162
+ - `bezier3PolynomialX(curve)`
163
+ - `bezier3PolynomialY(curve)`
164
+ - `bezier3RMSDistance(curve, pts)`
165
+ - `bezier3Split(curve, ts)`
166
+ - `bezier3SVG(curve)`
167
+ - `bezier3TangentAt(curve, t)`
168
+ - `bezier3Translate(curve, delta)`
169
+ - `bezier3TsAtXEq(curve, x)`
170
+ - `bezier3TsAtYEq(curve, y)`
171
+ - `bezier3XAt(curve, t)`
172
+ - `bezier3XTurningPointTs(curve)`
173
+ - `bezier3YAt(curve, t)`
174
+ - `bezier3YTurningPointTs(curve)`
175
+ - `bezierAt(curve, t)`
176
+ - `bezierAtMulti(curve, ts)`
177
+ - `bezierBisect(curve, t = 0.5)`
178
+ - `bezierDerivative(curve)`
179
+ - `bezierElevateOrder(curve)`
180
+ - `bezierElevateOrderTo(curve, target)`
181
+ - `bezierFrenetNormalAt(curve, t)`
182
+ - `bezierFromBezier2(curve)`
183
+ - `bezierFromBezier3(curve)`
184
+ - `bezierFromEndpoints(p0, p1)`
185
+ - `bezierFromLine(line)`
186
+ - `bezierFromPolylineVertsLeastSquares(polyline)`
187
+ - `bezierFromPolylineVertsLeastSquaresFixEnds(polyline)`
188
+ - `bezierFromQuad(p0, c1, c2, p3)`
189
+ - `bezierFromVecs([p0, c1, c2, p3])`
190
+ - `bezierLowerOrder(curve)`
191
+ - `bezierM(n)`
192
+ - `bezierMInv(n)`
193
+ - `bezierNormalAt(curve, t)`
194
+ - `bezierOrder(curve)`
195
+ - `bezierPolynomials(curve)`
196
+ - `bezierSplit(curve, ts)`
197
+ - `bezierSVG(curve)`
198
+ - `bezierTangentAt(curve, t)`
199
+ - `bezierTranslate(curve, delta)`
200
+ - `binomial(a, b)`
201
+ - `circleArea(circle)`
202
+ - `circleBounds(circle)`
203
+ - `circleCircumference(circle)`
204
+ - `circleContains(circle, pt)`
205
+ - `circleSVG(circle)`
206
+ - `complexCompanionMat(z)`
207
+ - `conjugateZ(z)`
208
+ - `divRZ(num, den)`
209
+ - `divZ(num, den)`
210
+ - `erf(x)`
211
+ - `erfc(x)`
212
+ - `erfcZ(z)`
213
+ - `erfZ(z)`
214
+ - `expZ(z)`
215
+ - `fresnelCIntegral(x)`
216
+ - `fresnelSIntegral(x)`
217
+ - `intersectBezier3Circle`
218
+ - `intersectBezier3CircleFn`
219
+ - `intersectBezier3Line`
220
+ - `intersectBezier3Rect`
221
+ - `intersectLineLine`
222
+ - `intersectNBezier3Circle`
223
+ - `intersectNBezier3CircleFn`
224
+ - `invZ`
225
+ - `isOverlapAABox`
226
+ - `isOverlapAABoxCircle`
227
+ - `isOverlapAABoxCircleR2`
228
+ - `lineAt`
229
+ - `lineBisect`
230
+ - `lineBounds`
231
+ - `lineDerivative`
232
+ - `lineFromBezier`
233
+ - `lineFromPts`
234
+ - `lineLength`
235
+ - `lineMidpoint`
236
+ - `lineNormal`
237
+ - `linePolynomialX`
238
+ - `linePolynomialY`
239
+ - `lineSplit`
240
+ - `lineSVG`
241
+ - `lineTangent`
242
+ - `lineTranslate`
243
+ - `lineTsAtXEq`
244
+ - `lineTsAtYEq`
245
+ - `lineXAt`
246
+ - `lineYAt`
247
+ - `mat1Determinant`
248
+ - `mat1Eigenvalues`
249
+ - `mat1Eigenvector`
250
+ - `mat1Inverse`
251
+ - `mat1LeftInverse`
252
+ - `mat1RightInverse`
253
+ - `mat1Trace`
254
+ - `mat2Determinant`
255
+ - `mat2Eigenvalues`
256
+ - `mat2Eigenvector`
257
+ - `mat2Inverse`
258
+ - `mat2LeftInverse`
259
+ - `mat2RightInverse`
260
+ - `mat2Trace`
261
+ - `mat3Determinant`
262
+ - `mat3Eigenvalues`
263
+ - `mat3Eigenvector`
264
+ - `mat3FromQuat`
265
+ - `mat3FromUnitQuat`
266
+ - `mat3Inverse`
267
+ - `mat3LeftInverse`
268
+ - `mat3RightInverse`
269
+ - `mat3Trace`
270
+ - `mat4Determinant`
271
+ - `mat4Eigenvalues`
272
+ - `mat4Eigenvector`
273
+ - `mat4Inverse`
274
+ - `mat4LeftInverse`
275
+ - `mat4RightInverse`
276
+ - `mat4Trace`
277
+ - `matAdd`
278
+ - `matAddColumnwise`
279
+ - `matBinaryOp`
280
+ - `matDeterminant`
281
+ - `matEigenvalues`
282
+ - `matEigenvector`
283
+ - `matElementNorm`
284
+ - `matElementNorm2`
285
+ - `matFrom`
286
+ - `matFromArray`
287
+ - `matFromArrayFn`
288
+ - `matFromDiag`
289
+ - `matFromEyeTargetUp`
290
+ - `matFromPts`
291
+ - `matFromRotationBetween`
292
+ - `matFromVecArray`
293
+ - `matIdent`
294
+ - `matInverse`
295
+ - `matLeftInverse`
296
+ - `matLerp`
297
+ - `matMid`
298
+ - `matMinor`
299
+ - `matMul`
300
+ - `matMulABTranspose`
301
+ - `matMulATransposeB`
302
+ - `matPadIdent`
303
+ - `matPrint`
304
+ - `matProjectVec3`
305
+ - `matReshape`
306
+ - `matRightInverse`
307
+ - `matScale`
308
+ - `matScaleAdd`
309
+ - `matSkewSymmetricCrossProduct`
310
+ - `matSub`
311
+ - `matSumDiagDeterminant2`
312
+ - `matSumDiagDeterminant3`
313
+ - `matTrace`
314
+ - `matTranspose`
315
+ - `matUnaryOp`
316
+ - `matWindow`
317
+ - `matZero`
318
+ - `mulZ`
319
+ - `mulZR`
320
+ - `nBezier3Area`
321
+ - `nBezier3At`
322
+ - `nBezier3Curvature`
323
+ - `nBezier3Derivative`
324
+ - `nBezier3InflectionTs`
325
+ - `nBezier3Moment`
326
+ - `nBezier3XAt`
327
+ - `nBezier3YAt`
328
+ - `negZ`
329
+ - `polygonContains`
330
+ - `polygonSignedArea`
331
+ - `polyline2DFromPolyline`
332
+ - `polyline2DFromPts`
333
+ - `polyline2DSVG`
334
+ - `polylineFromPolyline2D`
335
+ - `polylineFromVecs`
336
+ - `polynomial2Roots`
337
+ - `polynomial3Roots`
338
+ - `polynomial3SignedRoots`
339
+ - `polynomial4Roots`
340
+ - `polynomial4SignedRoots`
341
+ - `polynomial5Roots`
342
+ - `polynomial5SignedRoots`
343
+ - `polynomial7SignedRoots`
344
+ - `polynomialAdd`
345
+ - `polynomialAt`
346
+ - `polynomialCompanionMat`
347
+ - `polynomialDerivative`
348
+ - `polynomialFromBezier2Values`
349
+ - `polynomialFromBezier3Values`
350
+ - `polynomialFromBezierValues`
351
+ - `polynomialIntegral`
352
+ - `polynomialMul`
353
+ - `polynomialRoots`
354
+ - `polynomialScale`
355
+ - `polynomialShift`
356
+ - `polynomialSub`
357
+ - `polynomialWithSolutions`
358
+ - `ptAdd`
359
+ - `ptAngle`
360
+ - `ptCross`
361
+ - `ptDist`
362
+ - `ptDist2`
363
+ - `ptDot`
364
+ - `ptFromVec`
365
+ - `ptLen`
366
+ - `ptLen2`
367
+ - `ptLerp`
368
+ - `ptMad`
369
+ - `ptMid`
370
+ - `ptMul`
371
+ - `ptNorm`
372
+ - `ptReflect`
373
+ - `ptRot90`
374
+ - `ptsFromMat`
375
+ - `ptSignedAngle`
376
+ - `ptSub`
377
+ - `ptSVG`
378
+ - `ptTransform`
379
+ - `quatAdd`
380
+ - `quatConjugate`
381
+ - `quatDist`
382
+ - `quatDist2`
383
+ - `quatDiv`
384
+ - `quatDot`
385
+ - `quatExp`
386
+ - `quatFrom`
387
+ - `quatFromMat3BestFit`
388
+ - `quatFromMat3Exact`
389
+ - `quatFromRotationAround`
390
+ - `quatInv`
391
+ - `quatLerp`
392
+ - `quatLerpShortestPath`
393
+ - `quatLerpShortestPathUnit`
394
+ - `quatLerpUnit`
395
+ - `quatLog`
396
+ - `quatMad`
397
+ - `quatMul`
398
+ - `quatNearest`
399
+ - `quatNorm`
400
+ - `quatNorm2`
401
+ - `quatPrint`
402
+ - `quatScale`
403
+ - `quatSlerp`
404
+ - `quatSlerpShortestPath`
405
+ - `quatSquad`
406
+ - `quatSub`
407
+ - `quatUnit`
408
+ - `quatVectorNorm`
409
+ - `quatVectorNorm2`
410
+ - `rectArea`
411
+ - `rectBounds`
412
+ - `rectContains`
413
+ - `rectFromAABox`
414
+ - `rectFromLine`
415
+ - `rectSVG`
416
+ - `subRZ`
417
+ - `subtractBezier3Circle`
418
+ - `subtractBezier3Rect`
419
+ - `subZ`
420
+ - `unscaledFresnelCIntegral`
421
+ - `unscaledFresnelSIntegral`
422
+ - `vec2Cross`
423
+ - `vec3Cross`
424
+ - `vecAdd`
425
+ - `vecAngle`
426
+ - `vecArrayFromMat`
427
+ - `vecDist`
428
+ - `vecDist2`
429
+ - `vecDot`
430
+ - `vecFrom`
431
+ - `vecFromPt`
432
+ - `vecLen`
433
+ - `vecLen2`
434
+ - `vecLerp`
435
+ - `vecMad`
436
+ - `vecMid`
437
+ - `vecMul`
438
+ - `vecNorm`
439
+ - `vecPrint`
440
+ - `vecReflect`
441
+ - `vecSub`
442
+ - `zeros(count)`
443
+
444
+ ### Classes
445
+
446
+ - `CurveDrawer`
447
+
448
+ ### Constants
449
+
450
+ - `bezier2M`: Constant for `bezierM(3)`.
451
+ - `bezier2MInv`: Constant for `matInverse(bezierM(3))`.
452
+ - `bezier3M`: Constant for `bezierM(4)`.
453
+ - `bezier3MInv`: Constant for `matInverse(bezierM(4))`.
454
+ - `MAT1IDENT`: Constant for `matIdent(1)`.
455
+ - `MAT2IDENT`: Constant for `matIdent(2)`.
456
+ - `MAT2ROT90`: Constant for `matFrom([[0, 1], [-1, 0]])`.
457
+ - `MAT3IDENT`: Constant for `matIdent(3)`.
458
+ - `MAT4IDENT`: Constant for `matIdent(4)`.
459
+ - `PT0`: Constant for `{ x: 0, y: 0 }`.
37
460
 
38
461
  ## References
39
462