@ac-kit/math-linear 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +257 -0
- package/README.md +229 -16
- package/dist/_brand.d.ts +14 -0
- package/dist/_brand.d.ts.map +1 -0
- package/dist/_brand.js +2 -0
- package/dist/_brand.js.map +1 -0
- package/dist/_invert.d.ts +19 -0
- package/dist/_invert.d.ts.map +1 -0
- package/dist/_invert.js +48 -0
- package/dist/_invert.js.map +1 -0
- package/dist/_slerp.d.ts +15 -0
- package/dist/_slerp.d.ts.map +1 -1
- package/dist/_slerp.js +47 -0
- package/dist/_slerp.js.map +1 -1
- package/dist/_strided-range.d.ts +23 -0
- package/dist/_strided-range.d.ts.map +1 -0
- package/dist/_strided-range.js +75 -0
- package/dist/_strided-range.js.map +1 -0
- package/dist/_trs.d.ts +38 -0
- package/dist/_trs.d.ts.map +1 -0
- package/dist/_trs.js +132 -0
- package/dist/_trs.js.map +1 -0
- package/dist/affine2-array.d.ts +53 -0
- package/dist/affine2-array.d.ts.map +1 -0
- package/dist/affine2-array.js +107 -0
- package/dist/affine2-array.js.map +1 -0
- package/dist/affine2-componentwise.d.ts +28 -0
- package/dist/affine2-componentwise.d.ts.map +1 -0
- package/dist/affine2-componentwise.js +66 -0
- package/dist/affine2-componentwise.js.map +1 -0
- package/dist/affine2.d.ts +144 -0
- package/dist/affine2.d.ts.map +1 -0
- package/dist/affine2.js +375 -0
- package/dist/affine2.js.map +1 -0
- package/dist/affine3-array.d.ts +53 -0
- package/dist/affine3-array.d.ts.map +1 -0
- package/dist/affine3-array.js +137 -0
- package/dist/affine3-array.js.map +1 -0
- package/dist/affine3-componentwise.d.ts +32 -0
- package/dist/affine3-componentwise.d.ts.map +1 -0
- package/dist/affine3-componentwise.js +100 -0
- package/dist/affine3-componentwise.js.map +1 -0
- package/dist/affine3.d.ts +192 -0
- package/dist/affine3.d.ts.map +1 -0
- package/dist/affine3.js +718 -0
- package/dist/affine3.js.map +1 -0
- package/dist/checked/index.d.ts +35 -0
- package/dist/checked/index.d.ts.map +1 -0
- package/dist/checked/index.js +58 -0
- package/dist/checked/index.js.map +1 -0
- package/dist/euler.d.ts +65 -0
- package/dist/euler.d.ts.map +1 -0
- package/dist/euler.js +217 -0
- package/dist/euler.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -1
- package/dist/kl-activations.d.ts.map +1 -1
- package/dist/kl-activations.js +4 -3
- package/dist/kl-activations.js.map +1 -1
- package/dist/mat2x2-array.d.ts +36 -0
- package/dist/mat2x2-array.d.ts.map +1 -0
- package/dist/mat2x2-array.js +71 -0
- package/dist/mat2x2-array.js.map +1 -0
- package/dist/mat2x2-componentwise.d.ts +86 -0
- package/dist/mat2x2-componentwise.d.ts.map +1 -0
- package/dist/mat2x2-componentwise.js +199 -0
- package/dist/mat2x2-componentwise.js.map +1 -0
- package/dist/mat2x2.d.ts +67 -25
- package/dist/mat2x2.d.ts.map +1 -1
- package/dist/mat2x2.js +150 -94
- package/dist/mat2x2.js.map +1 -1
- package/dist/mat3x3-array.d.ts +36 -0
- package/dist/mat3x3-array.d.ts.map +1 -0
- package/dist/mat3x3-array.js +91 -0
- package/dist/mat3x3-array.js.map +1 -0
- package/dist/mat3x3-componentwise.d.ts +86 -0
- package/dist/mat3x3-componentwise.d.ts.map +1 -0
- package/dist/mat3x3-componentwise.js +299 -0
- package/dist/mat3x3-componentwise.js.map +1 -0
- package/dist/mat3x3.d.ts +131 -48
- package/dist/mat3x3.d.ts.map +1 -1
- package/dist/mat3x3.js +434 -193
- package/dist/mat3x3.js.map +1 -1
- package/dist/mat4x4-array.d.ts +46 -0
- package/dist/mat4x4-array.d.ts.map +1 -0
- package/dist/mat4x4-array.js +133 -0
- package/dist/mat4x4-array.js.map +1 -0
- package/dist/mat4x4-componentwise.d.ts +87 -0
- package/dist/mat4x4-componentwise.d.ts.map +1 -0
- package/dist/mat4x4-componentwise.js +434 -0
- package/dist/mat4x4-componentwise.js.map +1 -0
- package/dist/mat4x4.d.ts +195 -67
- package/dist/mat4x4.d.ts.map +1 -1
- package/dist/mat4x4.js +849 -335
- package/dist/mat4x4.js.map +1 -1
- package/dist/projection.d.ts +98 -0
- package/dist/projection.d.ts.map +1 -0
- package/dist/projection.js +369 -0
- package/dist/projection.js.map +1 -0
- package/dist/quaternion-array.d.ts +47 -0
- package/dist/quaternion-array.d.ts.map +1 -0
- package/dist/quaternion-array.js +86 -0
- package/dist/quaternion-array.js.map +1 -0
- package/dist/quaternion.d.ts +104 -22
- package/dist/quaternion.d.ts.map +1 -1
- package/dist/quaternion.js +294 -181
- package/dist/quaternion.js.map +1 -1
- package/dist/transform.d.ts +220 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +412 -0
- package/dist/transform.js.map +1 -0
- package/dist/tridiagonal.d.ts +52 -0
- package/dist/tridiagonal.d.ts.map +1 -0
- package/dist/tridiagonal.js +90 -0
- package/dist/tridiagonal.js.map +1 -0
- package/dist/upload.d.ts +55 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +129 -0
- package/dist/upload.js.map +1 -0
- package/dist/vec2-array-componentwise.d.ts +189 -0
- package/dist/vec2-array-componentwise.d.ts.map +1 -0
- package/dist/vec2-array-componentwise.js +424 -0
- package/dist/vec2-array-componentwise.js.map +1 -0
- package/dist/vec2-array.d.ts +53 -0
- package/dist/vec2-array.d.ts.map +1 -0
- package/dist/vec2-array.js +123 -0
- package/dist/vec2-array.js.map +1 -0
- package/dist/vec2-componentwise.d.ts +311 -0
- package/dist/vec2-componentwise.d.ts.map +1 -0
- package/dist/vec2-componentwise.js +542 -0
- package/dist/vec2-componentwise.js.map +1 -0
- package/dist/vec2.d.ts +97 -82
- package/dist/vec2.d.ts.map +1 -1
- package/dist/vec2.js +121 -216
- package/dist/vec2.js.map +1 -1
- package/dist/vec3-array-componentwise.d.ts +189 -0
- package/dist/vec3-array-componentwise.d.ts.map +1 -0
- package/dist/vec3-array-componentwise.js +458 -0
- package/dist/vec3-array-componentwise.js.map +1 -0
- package/dist/vec3-array.d.ts +102 -0
- package/dist/vec3-array.d.ts.map +1 -0
- package/dist/vec3-array.js +299 -0
- package/dist/vec3-array.js.map +1 -0
- package/dist/vec3-componentwise.d.ts +310 -0
- package/dist/vec3-componentwise.d.ts.map +1 -0
- package/dist/vec3-componentwise.js +594 -0
- package/dist/vec3-componentwise.js.map +1 -0
- package/dist/vec3.d.ts +177 -87
- package/dist/vec3.d.ts.map +1 -1
- package/dist/vec3.js +366 -273
- package/dist/vec3.js.map +1 -1
- package/dist/vec4-array-componentwise.d.ts +155 -0
- package/dist/vec4-array-componentwise.d.ts.map +1 -0
- package/dist/vec4-array-componentwise.js +401 -0
- package/dist/vec4-array-componentwise.js.map +1 -0
- package/dist/vec4-array.d.ts +12 -0
- package/dist/vec4-array.d.ts.map +1 -0
- package/dist/vec4-array.js +43 -0
- package/dist/vec4-array.js.map +1 -0
- package/dist/vec4-componentwise.d.ts +299 -0
- package/dist/vec4-componentwise.d.ts.map +1 -0
- package/dist/vec4-componentwise.js +637 -0
- package/dist/vec4-componentwise.js.map +1 -0
- package/dist/vec4.d.ts +57 -53
- package/dist/vec4.d.ts.map +1 -1
- package/dist/vec4.js +94 -246
- package/dist/vec4.js.map +1 -1
- package/dist/view-basis.d.ts +15 -0
- package/dist/view-basis.d.ts.map +1 -0
- package/dist/view-basis.js +29 -0
- package/dist/view-basis.js.map +1 -0
- package/dist/viewport.d.ts +114 -0
- package/dist/viewport.d.ts.map +1 -0
- package/dist/viewport.js +250 -0
- package/dist/viewport.js.map +1 -0
- package/package.json +18 -9
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Generated from scripts/templates/affine-componentwise.liquid by scripts/generate-componentwise.ts. Do not edit.
|
|
2
|
+
import { isCloseTo } from "@ac-kit/core";
|
|
3
|
+
/**
|
|
4
|
+
* Writes the entries in storage order into `out`: the columns of the matrix one
|
|
5
|
+
* after the other, `a, b, c, d, e, f`.
|
|
6
|
+
*/
|
|
7
|
+
export function affine2Set(out, m00, m10, m01, m11, m02, m12) {
|
|
8
|
+
out[0] = m00;
|
|
9
|
+
out[1] = m10;
|
|
10
|
+
out[2] = m01;
|
|
11
|
+
out[3] = m11;
|
|
12
|
+
out[4] = m02;
|
|
13
|
+
out[5] = m12;
|
|
14
|
+
return out;
|
|
15
|
+
}
|
|
16
|
+
/** Writes a copy of `a` into `out`. `out` may be `a`. */
|
|
17
|
+
export function affine2Copy(out, a) {
|
|
18
|
+
out[0] = a[0];
|
|
19
|
+
out[1] = a[1];
|
|
20
|
+
out[2] = a[2];
|
|
21
|
+
out[3] = a[3];
|
|
22
|
+
out[4] = a[4];
|
|
23
|
+
out[5] = a[5];
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
/** Writes the identity transform `[1, 0, 0, 1, 0, 0]` into `out`. */
|
|
27
|
+
export function affine2Identity(out) {
|
|
28
|
+
out[0] = 1;
|
|
29
|
+
out[1] = 0;
|
|
30
|
+
out[2] = 0;
|
|
31
|
+
out[3] = 1;
|
|
32
|
+
out[4] = 0;
|
|
33
|
+
out[5] = 0;
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Exact entry-wise equality: `−0` equals `+0`, and `NaN` equals nothing, itself
|
|
38
|
+
* included. See {@link affine2IsClose} for a tolerant test.
|
|
39
|
+
*/
|
|
40
|
+
export function affine2Equals(a, b) {
|
|
41
|
+
return (a[0] === b[0] &&
|
|
42
|
+
a[1] === b[1] &&
|
|
43
|
+
a[2] === b[2] &&
|
|
44
|
+
a[3] === b[3] &&
|
|
45
|
+
a[4] === b[4] &&
|
|
46
|
+
a[5] === b[5]);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Entry-wise approximate equality, each pair compared by `@ac-kit/core`'s
|
|
50
|
+
* `isCloseTo` with `options`: none means exact.
|
|
51
|
+
*
|
|
52
|
+
* Not transitive, so it is not an equality in the sense a `Set` or `Map` needs,
|
|
53
|
+
* and never a basis for ordering — use {@link affine2Equals} there. The
|
|
54
|
+
* tolerance is required: a transform carries no units of its own, so only the
|
|
55
|
+
* caller knows what counts as close (and the same tolerance covers a matrix
|
|
56
|
+
* entry and a translation).
|
|
57
|
+
*/
|
|
58
|
+
export function affine2IsClose(a, b, options) {
|
|
59
|
+
return (isCloseTo(a[0], b[0], options) &&
|
|
60
|
+
isCloseTo(a[1], b[1], options) &&
|
|
61
|
+
isCloseTo(a[2], b[2], options) &&
|
|
62
|
+
isCloseTo(a[3], b[3], options) &&
|
|
63
|
+
isCloseTo(a[4], b[4], options) &&
|
|
64
|
+
isCloseTo(a[5], b[5], options));
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=affine2-componentwise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"affine2-componentwise.js","sourceRoot":"","sources":["../src/affine2-componentwise.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAElH,OAAO,EAAE,SAAS,EAAyB,MAAM,cAAc,CAAC;AAIhE;;;GAGG;AACH,MAAM,UAAU,UAAU,CACzB,GAAY,EACZ,GAAW,EACX,GAAW,EACX,GAAW,EACX,GAAW,EACX,GAAW,EACX,GAAW;IAEX,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IACb,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IACb,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IACb,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IACb,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IACb,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IACb,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,yDAAyD;AACzD,MAAM,UAAU,WAAW,CAAC,GAAY,EAAE,CAAkB;IAC3D,GAAG,CAAC,CAAC,CA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GASG;AACH,MAAM,UAAU,cAAc,CAC7B,CAAkB,EAClB,CAAkB,EAClB,OAAyB;IAEzB,OAAO,CACN,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC;QAC9B,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC;QAC9B,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC;QAC9B,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC;QAC9B,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC;QAC9B,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAC9B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { Brand_ } from "./_brand.js";
|
|
2
|
+
import type { ReadonlyMat3x3 } from "./mat3x3.js";
|
|
3
|
+
import type { ReadonlyVec2 } from "./vec2.js";
|
|
4
|
+
/**
|
|
5
|
+
* A 2D affine transform in the order of Canvas, SVG and `DOMMatrix`, `a, b, c,
|
|
6
|
+
* d, e, f`: the columns `(a, b)`, `(c, d)` and `(e, f)` of the 3 × 3 matrix
|
|
7
|
+
* whose bottom row is `0, 0, 1` and is not stored, so `[a, b, c, d, e, f]` is
|
|
8
|
+
* `[m00, m10, m01, m11, m02, m12]`, the translation in the last two. A plain
|
|
9
|
+
* array of six binary64 numbers carrying a type-level brand; a buffer of them
|
|
10
|
+
* is a `Float64Array` of `count × 6` numbers.
|
|
11
|
+
*
|
|
12
|
+
* Only {@link affine2Create}, {@link affine2Of}, {@link affine2Clone},
|
|
13
|
+
* {@link affine2FromArray} and the functions that write an `out` make one; see
|
|
14
|
+
* {@link Vec3} for the rules that bind callers who bypass the types.
|
|
15
|
+
*/
|
|
16
|
+
export type Affine2 = [
|
|
17
|
+
m00: number,
|
|
18
|
+
m10: number,
|
|
19
|
+
m01: number,
|
|
20
|
+
m11: number,
|
|
21
|
+
m02: number,
|
|
22
|
+
m12: number
|
|
23
|
+
] & Brand_<"Affine2">;
|
|
24
|
+
/** An {@link Affine2} that is only read. */
|
|
25
|
+
export type ReadonlyAffine2 = readonly [
|
|
26
|
+
m00: number,
|
|
27
|
+
m10: number,
|
|
28
|
+
m01: number,
|
|
29
|
+
m11: number,
|
|
30
|
+
m02: number,
|
|
31
|
+
m12: number
|
|
32
|
+
] & Brand_<"Affine2">;
|
|
33
|
+
/**
|
|
34
|
+
* Creates the identity transform `[1, 0, 0, 1, 0, 0]`.
|
|
35
|
+
*
|
|
36
|
+
* Allocates; keep it out of hot loops.
|
|
37
|
+
*/
|
|
38
|
+
export declare function affine2Create(): Affine2;
|
|
39
|
+
/**
|
|
40
|
+
* Creates the transform with the entries in storage order, the columns of the
|
|
41
|
+
* matrix one after the other: `a, b, c, d, e, f`.
|
|
42
|
+
*
|
|
43
|
+
* Allocates; keep it out of hot loops.
|
|
44
|
+
*/
|
|
45
|
+
export declare function affine2Of(m00: number, m10: number, m01: number, m11: number, m02: number, m12: number): Affine2;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a copy of `a`. Like every creator it starts from a clean array.
|
|
48
|
+
*
|
|
49
|
+
* Allocates; keep it out of hot loops.
|
|
50
|
+
*/
|
|
51
|
+
export declare function affine2Clone(a: ReadonlyAffine2): Affine2;
|
|
52
|
+
/**
|
|
53
|
+
* The checked way in from untyped data (JSON, messages, arrays of unknown
|
|
54
|
+
* origin): `source[offset … offset + 6)` copied into `out`, each element that
|
|
55
|
+
* is not a number written as `NaN`, an index past the end of `source` too, so
|
|
56
|
+
* `out` never holds a non-number. A cold path. O(1).
|
|
57
|
+
*
|
|
58
|
+
* `source` may be `out` itself: the six elements are read before the first
|
|
59
|
+
* write.
|
|
60
|
+
*
|
|
61
|
+
* @param out The transform to fill.
|
|
62
|
+
* @param source The array to read, of any length and any content.
|
|
63
|
+
* @param offset The index of the first entry in `source`.
|
|
64
|
+
* @returns `out`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function affine2FromArray(out: Affine2, source: ArrayLike<number>, offset?: number): Affine2;
|
|
67
|
+
/**
|
|
68
|
+
* Whether every entry is a finite number: the check to run after parsing
|
|
69
|
+
* untrusted data or before an upload, as operations never check. An entry that
|
|
70
|
+
* is not a number at all counts as not finite.
|
|
71
|
+
*/
|
|
72
|
+
export declare function affine2IsFinite(a: ReadonlyAffine2): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Writes the composition `a · b` into `out`: `b` is applied first, then `a`.
|
|
75
|
+
* Not commutative. Plain arithmetic, straight-line. `out` may be `a` or `b`.
|
|
76
|
+
*/
|
|
77
|
+
export declare function affine2Multiply(out: Affine2, a: ReadonlyAffine2, b: ReadonlyAffine2): Affine2;
|
|
78
|
+
/**
|
|
79
|
+
* The determinant of the linear part, `a · d − b · c`: the signed area scale of
|
|
80
|
+
* the transform, negative for a reflection.
|
|
81
|
+
*/
|
|
82
|
+
export declare function affine2Determinant(a: ReadonlyAffine2): number;
|
|
83
|
+
/**
|
|
84
|
+
* Writes the inverse transform of `a` into `out` and returns `true`. When the
|
|
85
|
+
* determinant is zero or not finite, or the inverse does not fit in binary64,
|
|
86
|
+
* the transform has no usable inverse: `out` is filled with `NaN` and the
|
|
87
|
+
* result is `false`: `true` always comes with a finite `out`, never a stale or
|
|
88
|
+
* partial transform, and nothing throws. A transform whose linear part is of
|
|
89
|
+
* one very large or very small magnitude, whose determinant overflows or
|
|
90
|
+
* underflows, is inverted all the same (a uniform scale of `1e-200` gives
|
|
91
|
+
* `1e200`), by scaling the linear part by a power of two first. Plain
|
|
92
|
+
* arithmetic (the adjugate over the determinant). `out` may be `a`.
|
|
93
|
+
*/
|
|
94
|
+
export declare function affine2Invert(out: Affine2, a: ReadonlyAffine2): boolean;
|
|
95
|
+
/** Writes the translation by `translation` into `out`. */
|
|
96
|
+
export declare function affine2FromTranslation(out: Affine2, translation: ReadonlyVec2): Affine2;
|
|
97
|
+
/** Writes the scale `diag(scale)` into `out`. */
|
|
98
|
+
export declare function affine2FromScale(out: Affine2, scale: ReadonlyVec2): Affine2;
|
|
99
|
+
/**
|
|
100
|
+
* Writes the rotation by `angle` radians, counter-clockwise with `y` up (so
|
|
101
|
+
* clockwise on a screen with `y` down), about the origin into `out`: `[cos,
|
|
102
|
+
* sin, −sin, cos, 0, 0]`.
|
|
103
|
+
*/
|
|
104
|
+
export declare function affine2FromRotation(out: Affine2, angle: number): Affine2;
|
|
105
|
+
/**
|
|
106
|
+
* Writes `T(center) · S(scale) · T(−center)` into `out`: the scale that leaves
|
|
107
|
+
* the point `center` where it is, the zoom about the pointer.
|
|
108
|
+
*/
|
|
109
|
+
export declare function affine2FromScaleAbout(out: Affine2, scale: ReadonlyVec2, center: ReadonlyVec2): Affine2;
|
|
110
|
+
/**
|
|
111
|
+
* Writes `T(center) · R(angle) · T(−center)` into `out`: the rotation by
|
|
112
|
+
* `angle` radians that leaves the point `center` where it is.
|
|
113
|
+
*/
|
|
114
|
+
export declare function affine2FromRotationAbout(out: Affine2, angle: number, center: ReadonlyVec2): Affine2;
|
|
115
|
+
/**
|
|
116
|
+
* Writes the 2D affine of a 3 × 3 matrix into `out`, dropping its bottom row,
|
|
117
|
+
* which an {@link Affine2} does not store (`0, 0, 1` for an affine matrix).
|
|
118
|
+
*/
|
|
119
|
+
export declare function affine2FromMat3x3(out: Affine2, m: ReadonlyMat3x3): Affine2;
|
|
120
|
+
/**
|
|
121
|
+
* Writes `a · T(translation)` into `out`: the translation applied first, in the
|
|
122
|
+
* local space of `a`, as Canvas's `translate`. `out` may be `a`.
|
|
123
|
+
*/
|
|
124
|
+
export declare function affine2Translate(out: Affine2, a: ReadonlyAffine2, translation: ReadonlyVec2): Affine2;
|
|
125
|
+
/**
|
|
126
|
+
* Writes `a · R(angle)` into `out`: the rotation by `angle` radians applied
|
|
127
|
+
* first, in the local space of `a`, as Canvas's `rotate`. `out` may be `a`.
|
|
128
|
+
*/
|
|
129
|
+
export declare function affine2Rotate(out: Affine2, a: ReadonlyAffine2, angle: number): Affine2;
|
|
130
|
+
/**
|
|
131
|
+
* Writes `a · S(scale)` into `out`: the scale applied first, in the local space
|
|
132
|
+
* of `a`, as Canvas's `scale`. `out` may be `a`.
|
|
133
|
+
*/
|
|
134
|
+
export declare function affine2Scale(out: Affine2, a: ReadonlyAffine2, scale: ReadonlyVec2): Affine2;
|
|
135
|
+
/**
|
|
136
|
+
* Writes into `out` the transform that maps the rectangle `[left, right] ×
|
|
137
|
+
* [bottom, top]` to clip space `[−1, 1]²`, `y` up: `left` to −1 and `right` to
|
|
138
|
+
* 1, `bottom` to −1 and `top` to 1. For a pixel canvas with its origin at the
|
|
139
|
+
* top left, `y` down, call it as `(0, width, height, 0)`. An empty rectangle
|
|
140
|
+
* (`left = right` or `bottom = top`) gives non-finite entries and nothing
|
|
141
|
+
* throws, so a canvas of size zero during a resize is harmless.
|
|
142
|
+
*/
|
|
143
|
+
export declare function affine2Orthographic(out: Affine2, left: number, right: number, bottom: number, top: number): Affine2;
|
|
144
|
+
//# sourceMappingURL=affine2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"affine2.d.ts","sourceRoot":"","sources":["../src/affine2.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,OAAO,GAAG;IACrB,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,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
|
|
|
1
|
+
import { numberAtOrNaN } from "@ac-kit/core";
|
|
2
|
+
import { scaleForInversion_, unscaleInverse_ } from "./_invert.js";
|
|
3
|
+
/**
|
|
4
|
+
* Every creator copies this array, which holds non-integer doubles and is never
|
|
5
|
+
* exposed: nothing a caller does can change the element kind it copies.
|
|
6
|
+
*/
|
|
7
|
+
const TEMPLATE_ = [0.5, 0.5, 0.5, 0.5, 0.5, 0.5];
|
|
8
|
+
/**
|
|
9
|
+
* Creates the identity transform `[1, 0, 0, 1, 0, 0]`.
|
|
10
|
+
*
|
|
11
|
+
* Allocates; keep it out of hot loops.
|
|
12
|
+
*/
|
|
13
|
+
export function affine2Create() {
|
|
14
|
+
const out = TEMPLATE_.slice();
|
|
15
|
+
out[0] = 1;
|
|
16
|
+
out[1] = 0;
|
|
17
|
+
out[2] = 0;
|
|
18
|
+
out[3] = 1;
|
|
19
|
+
out[4] = 0;
|
|
20
|
+
out[5] = 0;
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates the transform with the entries in storage order, the columns of the
|
|
25
|
+
* matrix one after the other: `a, b, c, d, e, f`.
|
|
26
|
+
*
|
|
27
|
+
* Allocates; keep it out of hot loops.
|
|
28
|
+
*/
|
|
29
|
+
export function affine2Of(m00, m10, m01, m11, m02, m12) {
|
|
30
|
+
const out = TEMPLATE_.slice();
|
|
31
|
+
out[0] = m00;
|
|
32
|
+
out[1] = m10;
|
|
33
|
+
out[2] = m01;
|
|
34
|
+
out[3] = m11;
|
|
35
|
+
out[4] = m02;
|
|
36
|
+
out[5] = m12;
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates a copy of `a`. Like every creator it starts from a clean array.
|
|
41
|
+
*
|
|
42
|
+
* Allocates; keep it out of hot loops.
|
|
43
|
+
*/
|
|
44
|
+
export function affine2Clone(a) {
|
|
45
|
+
const out = TEMPLATE_.slice();
|
|
46
|
+
out[0] = a[0];
|
|
47
|
+
out[1] = a[1];
|
|
48
|
+
out[2] = a[2];
|
|
49
|
+
out[3] = a[3];
|
|
50
|
+
out[4] = a[4];
|
|
51
|
+
out[5] = a[5];
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The checked way in from untyped data (JSON, messages, arrays of unknown
|
|
56
|
+
* origin): `source[offset … offset + 6)` copied into `out`, each element that
|
|
57
|
+
* is not a number written as `NaN`, an index past the end of `source` too, so
|
|
58
|
+
* `out` never holds a non-number. A cold path. O(1).
|
|
59
|
+
*
|
|
60
|
+
* `source` may be `out` itself: the six elements are read before the first
|
|
61
|
+
* write.
|
|
62
|
+
*
|
|
63
|
+
* @param out The transform to fill.
|
|
64
|
+
* @param source The array to read, of any length and any content.
|
|
65
|
+
* @param offset The index of the first entry in `source`.
|
|
66
|
+
* @returns `out`.
|
|
67
|
+
*/
|
|
68
|
+
export function affine2FromArray(out, source, offset = 0) {
|
|
69
|
+
const m00 = numberAtOrNaN(source, offset);
|
|
70
|
+
const m10 = numberAtOrNaN(source, offset + 1);
|
|
71
|
+
const m01 = numberAtOrNaN(source, offset + 2);
|
|
72
|
+
const m11 = numberAtOrNaN(source, offset + 3);
|
|
73
|
+
const m02 = numberAtOrNaN(source, offset + 4);
|
|
74
|
+
const m12 = numberAtOrNaN(source, offset + 5);
|
|
75
|
+
out[0] = m00;
|
|
76
|
+
out[1] = m10;
|
|
77
|
+
out[2] = m01;
|
|
78
|
+
out[3] = m11;
|
|
79
|
+
out[4] = m02;
|
|
80
|
+
out[5] = m12;
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Whether every entry is a finite number: the check to run after parsing
|
|
85
|
+
* untrusted data or before an upload, as operations never check. An entry that
|
|
86
|
+
* is not a number at all counts as not finite.
|
|
87
|
+
*/
|
|
88
|
+
export function affine2IsFinite(a) {
|
|
89
|
+
return (Number.isFinite(a[0]) &&
|
|
90
|
+
Number.isFinite(a[1]) &&
|
|
91
|
+
Number.isFinite(a[2]) &&
|
|
92
|
+
Number.isFinite(a[3]) &&
|
|
93
|
+
Number.isFinite(a[4]) &&
|
|
94
|
+
Number.isFinite(a[5]));
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Writes the composition `a · b` into `out`: `b` is applied first, then `a`.
|
|
98
|
+
* Not commutative. Plain arithmetic, straight-line. `out` may be `a` or `b`.
|
|
99
|
+
*/
|
|
100
|
+
export function affine2Multiply(out, a, b) {
|
|
101
|
+
const a0 = a[0];
|
|
102
|
+
const a1 = a[1];
|
|
103
|
+
const a2 = a[2];
|
|
104
|
+
const a3 = a[3];
|
|
105
|
+
const a4 = a[4];
|
|
106
|
+
const a5 = a[5];
|
|
107
|
+
const b0 = b[0];
|
|
108
|
+
const b1 = b[1];
|
|
109
|
+
const b2 = b[2];
|
|
110
|
+
const b3 = b[3];
|
|
111
|
+
const b4 = b[4];
|
|
112
|
+
const b5 = b[5];
|
|
113
|
+
out[0] = a0 * b0 + a2 * b1;
|
|
114
|
+
out[1] = a1 * b0 + a3 * b1;
|
|
115
|
+
out[2] = a0 * b2 + a2 * b3;
|
|
116
|
+
out[3] = a1 * b2 + a3 * b3;
|
|
117
|
+
out[4] = a0 * b4 + a2 * b5 + a4;
|
|
118
|
+
out[5] = a1 * b4 + a3 * b5 + a5;
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The determinant of the linear part, `a · d − b · c`: the signed area scale of
|
|
123
|
+
* the transform, negative for a reflection.
|
|
124
|
+
*/
|
|
125
|
+
export function affine2Determinant(a) {
|
|
126
|
+
return a[0] * a[3] - a[2] * a[1];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Scratch for the linear part of {@link affine2Invert}'s second attempt: one
|
|
130
|
+
* call at a time, no callback inside it.
|
|
131
|
+
*/
|
|
132
|
+
const LINEAR_PART_ = [0.5, 0.5, 0.5, 0.5];
|
|
133
|
+
/**
|
|
134
|
+
* Writes the inverse transform of `a` into `out` and returns `true`. When the
|
|
135
|
+
* determinant is zero or not finite, or the inverse does not fit in binary64,
|
|
136
|
+
* the transform has no usable inverse: `out` is filled with `NaN` and the
|
|
137
|
+
* result is `false`: `true` always comes with a finite `out`, never a stale or
|
|
138
|
+
* partial transform, and nothing throws. A transform whose linear part is of
|
|
139
|
+
* one very large or very small magnitude, whose determinant overflows or
|
|
140
|
+
* underflows, is inverted all the same (a uniform scale of `1e-200` gives
|
|
141
|
+
* `1e200`), by scaling the linear part by a power of two first. Plain
|
|
142
|
+
* arithmetic (the adjugate over the determinant). `out` may be `a`.
|
|
143
|
+
*/
|
|
144
|
+
export function affine2Invert(out, a) {
|
|
145
|
+
if (invert_(out, a, false)) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
const a4 = a[4];
|
|
149
|
+
const a5 = a[5];
|
|
150
|
+
const exponent = scaleForInversion_(LINEAR_PART_, a);
|
|
151
|
+
if (!Number.isNaN(exponent)) {
|
|
152
|
+
out[0] = LINEAR_PART_[0];
|
|
153
|
+
out[1] = LINEAR_PART_[1];
|
|
154
|
+
out[2] = LINEAR_PART_[2];
|
|
155
|
+
out[3] = LINEAR_PART_[3];
|
|
156
|
+
out[4] = a4;
|
|
157
|
+
out[5] = a5;
|
|
158
|
+
if (invert_(out, out, true) && unscaleInverse_(out, exponent)) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
out[0] = Number.NaN;
|
|
163
|
+
out[1] = Number.NaN;
|
|
164
|
+
out[2] = Number.NaN;
|
|
165
|
+
out[3] = Number.NaN;
|
|
166
|
+
out[4] = Number.NaN;
|
|
167
|
+
out[5] = Number.NaN;
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The inverse by the adjugate over the determinant, written to `out` only when
|
|
172
|
+
* every entry is finite. The reciprocal of the determinant multiplies the
|
|
173
|
+
* adjugate; when it overflows (a subnormal determinant) the adjugate is divided
|
|
174
|
+
* by the determinant instead, if `divide`, and not otherwise.
|
|
175
|
+
*/
|
|
176
|
+
function invert_(out, a, divide) {
|
|
177
|
+
const a0 = a[0];
|
|
178
|
+
const a1 = a[1];
|
|
179
|
+
const a2 = a[2];
|
|
180
|
+
const a3 = a[3];
|
|
181
|
+
const a4 = a[4];
|
|
182
|
+
const a5 = a[5];
|
|
183
|
+
const determinant = a0 * a3 - a2 * a1;
|
|
184
|
+
if (determinant === 0 || !Number.isFinite(determinant)) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
const scale = 1 / determinant;
|
|
188
|
+
const reciprocal = Number.isFinite(scale);
|
|
189
|
+
if (!reciprocal && !divide) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
const o0 = reciprocal ? a3 * scale : a3 / determinant;
|
|
193
|
+
const o1 = reciprocal ? -a1 * scale : -a1 / determinant;
|
|
194
|
+
const o2 = reciprocal ? -a2 * scale : -a2 / determinant;
|
|
195
|
+
const o3 = reciprocal ? a0 * scale : a0 / determinant;
|
|
196
|
+
const o4 = reciprocal
|
|
197
|
+
? (a2 * a5 - a3 * a4) * scale
|
|
198
|
+
: (a2 * a5 - a3 * a4) / determinant;
|
|
199
|
+
const o5 = reciprocal
|
|
200
|
+
? (a1 * a4 - a0 * a5) * scale
|
|
201
|
+
: (a1 * a4 - a0 * a5) / determinant;
|
|
202
|
+
if (!(Number.isFinite(o0) &&
|
|
203
|
+
Number.isFinite(o1) &&
|
|
204
|
+
Number.isFinite(o2) &&
|
|
205
|
+
Number.isFinite(o3) &&
|
|
206
|
+
Number.isFinite(o4) &&
|
|
207
|
+
Number.isFinite(o5))) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
out[0] = o0;
|
|
211
|
+
out[1] = o1;
|
|
212
|
+
out[2] = o2;
|
|
213
|
+
out[3] = o3;
|
|
214
|
+
out[4] = o4;
|
|
215
|
+
out[5] = o5;
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
/** Writes the translation by `translation` into `out`. */
|
|
219
|
+
export function affine2FromTranslation(out, translation) {
|
|
220
|
+
out[0] = 1;
|
|
221
|
+
out[1] = 0;
|
|
222
|
+
out[2] = 0;
|
|
223
|
+
out[3] = 1;
|
|
224
|
+
out[4] = translation[0];
|
|
225
|
+
out[5] = translation[1];
|
|
226
|
+
return out;
|
|
227
|
+
}
|
|
228
|
+
/** Writes the scale `diag(scale)` into `out`. */
|
|
229
|
+
export function affine2FromScale(out, scale) {
|
|
230
|
+
out[0] = scale[0];
|
|
231
|
+
out[1] = 0;
|
|
232
|
+
out[2] = 0;
|
|
233
|
+
out[3] = scale[1];
|
|
234
|
+
out[4] = 0;
|
|
235
|
+
out[5] = 0;
|
|
236
|
+
return out;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Writes the rotation by `angle` radians, counter-clockwise with `y` up (so
|
|
240
|
+
* clockwise on a screen with `y` down), about the origin into `out`: `[cos,
|
|
241
|
+
* sin, −sin, cos, 0, 0]`.
|
|
242
|
+
*/
|
|
243
|
+
export function affine2FromRotation(out, angle) {
|
|
244
|
+
const cos = Math.cos(angle);
|
|
245
|
+
const sin = Math.sin(angle);
|
|
246
|
+
out[0] = cos;
|
|
247
|
+
out[1] = sin;
|
|
248
|
+
out[2] = -sin;
|
|
249
|
+
out[3] = cos;
|
|
250
|
+
out[4] = 0;
|
|
251
|
+
out[5] = 0;
|
|
252
|
+
return out;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Writes `T(center) · S(scale) · T(−center)` into `out`: the scale that leaves
|
|
256
|
+
* the point `center` where it is, the zoom about the pointer.
|
|
257
|
+
*/
|
|
258
|
+
export function affine2FromScaleAbout(out, scale, center) {
|
|
259
|
+
const sx = scale[0];
|
|
260
|
+
const sy = scale[1];
|
|
261
|
+
const cx = center[0];
|
|
262
|
+
const cy = center[1];
|
|
263
|
+
out[0] = sx;
|
|
264
|
+
out[1] = 0;
|
|
265
|
+
out[2] = 0;
|
|
266
|
+
out[3] = sy;
|
|
267
|
+
out[4] = cx - sx * cx;
|
|
268
|
+
out[5] = cy - sy * cy;
|
|
269
|
+
return out;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Writes `T(center) · R(angle) · T(−center)` into `out`: the rotation by
|
|
273
|
+
* `angle` radians that leaves the point `center` where it is.
|
|
274
|
+
*/
|
|
275
|
+
export function affine2FromRotationAbout(out, angle, center) {
|
|
276
|
+
const cx = center[0];
|
|
277
|
+
const cy = center[1];
|
|
278
|
+
const cos = Math.cos(angle);
|
|
279
|
+
const sin = Math.sin(angle);
|
|
280
|
+
out[0] = cos;
|
|
281
|
+
out[1] = sin;
|
|
282
|
+
out[2] = -sin;
|
|
283
|
+
out[3] = cos;
|
|
284
|
+
out[4] = cx - (cos * cx - sin * cy);
|
|
285
|
+
out[5] = cy - (sin * cx + cos * cy);
|
|
286
|
+
return out;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Writes the 2D affine of a 3 × 3 matrix into `out`, dropping its bottom row,
|
|
290
|
+
* which an {@link Affine2} does not store (`0, 0, 1` for an affine matrix).
|
|
291
|
+
*/
|
|
292
|
+
export function affine2FromMat3x3(out, m) {
|
|
293
|
+
out[0] = m[0];
|
|
294
|
+
out[1] = m[1];
|
|
295
|
+
out[2] = m[3];
|
|
296
|
+
out[3] = m[4];
|
|
297
|
+
out[4] = m[6];
|
|
298
|
+
out[5] = m[7];
|
|
299
|
+
return out;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Writes `a · T(translation)` into `out`: the translation applied first, in the
|
|
303
|
+
* local space of `a`, as Canvas's `translate`. `out` may be `a`.
|
|
304
|
+
*/
|
|
305
|
+
export function affine2Translate(out, a, translation) {
|
|
306
|
+
const a0 = a[0];
|
|
307
|
+
const a1 = a[1];
|
|
308
|
+
const a2 = a[2];
|
|
309
|
+
const a3 = a[3];
|
|
310
|
+
const x = translation[0];
|
|
311
|
+
const y = translation[1];
|
|
312
|
+
const e = a0 * x + a2 * y + a[4];
|
|
313
|
+
const f = a1 * x + a3 * y + a[5];
|
|
314
|
+
out[0] = a0;
|
|
315
|
+
out[1] = a1;
|
|
316
|
+
out[2] = a2;
|
|
317
|
+
out[3] = a3;
|
|
318
|
+
out[4] = e;
|
|
319
|
+
out[5] = f;
|
|
320
|
+
return out;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Writes `a · R(angle)` into `out`: the rotation by `angle` radians applied
|
|
324
|
+
* first, in the local space of `a`, as Canvas's `rotate`. `out` may be `a`.
|
|
325
|
+
*/
|
|
326
|
+
export function affine2Rotate(out, a, angle) {
|
|
327
|
+
const a0 = a[0];
|
|
328
|
+
const a1 = a[1];
|
|
329
|
+
const a2 = a[2];
|
|
330
|
+
const a3 = a[3];
|
|
331
|
+
const cos = Math.cos(angle);
|
|
332
|
+
const sin = Math.sin(angle);
|
|
333
|
+
out[0] = a0 * cos + a2 * sin;
|
|
334
|
+
out[1] = a1 * cos + a3 * sin;
|
|
335
|
+
out[2] = a2 * cos - a0 * sin;
|
|
336
|
+
out[3] = a3 * cos - a1 * sin;
|
|
337
|
+
out[4] = a[4];
|
|
338
|
+
out[5] = a[5];
|
|
339
|
+
return out;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Writes `a · S(scale)` into `out`: the scale applied first, in the local space
|
|
343
|
+
* of `a`, as Canvas's `scale`. `out` may be `a`.
|
|
344
|
+
*/
|
|
345
|
+
export function affine2Scale(out, a, scale) {
|
|
346
|
+
const sx = scale[0];
|
|
347
|
+
const sy = scale[1];
|
|
348
|
+
out[0] = a[0] * sx;
|
|
349
|
+
out[1] = a[1] * sx;
|
|
350
|
+
out[2] = a[2] * sy;
|
|
351
|
+
out[3] = a[3] * sy;
|
|
352
|
+
out[4] = a[4];
|
|
353
|
+
out[5] = a[5];
|
|
354
|
+
return out;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Writes into `out` the transform that maps the rectangle `[left, right] ×
|
|
358
|
+
* [bottom, top]` to clip space `[−1, 1]²`, `y` up: `left` to −1 and `right` to
|
|
359
|
+
* 1, `bottom` to −1 and `top` to 1. For a pixel canvas with its origin at the
|
|
360
|
+
* top left, `y` down, call it as `(0, width, height, 0)`. An empty rectangle
|
|
361
|
+
* (`left = right` or `bottom = top`) gives non-finite entries and nothing
|
|
362
|
+
* throws, so a canvas of size zero during a resize is harmless.
|
|
363
|
+
*/
|
|
364
|
+
export function affine2Orthographic(out, left, right, bottom, top) {
|
|
365
|
+
const width = right - left;
|
|
366
|
+
const height = top - bottom;
|
|
367
|
+
out[0] = 2 / width;
|
|
368
|
+
out[1] = 0;
|
|
369
|
+
out[2] = 0;
|
|
370
|
+
out[3] = 2 / height;
|
|
371
|
+
out[4] = -(right + left) / width;
|
|
372
|
+
out[5] = -(top + bottom) / height;
|
|
373
|
+
return out;
|
|
374
|
+
}
|
|
375
|
+
//# sourceMappingURL=affine2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"affine2.js","sourceRoot":"","sources":["../src/affine2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAqCnE;;;GAGG;AACH,MAAM,SAAS,GAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAEpE;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC5B,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,EAAa,CAAC;IACzC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACX,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACX,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACX,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,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ED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAClC,GAAY,EACZ,IAAY,EACZ,KAAa,EACb,MAAc,EACd,GAAW;IAEX,MAAM,KAAK,GAAG,KAAK,GAAG,IAAI,CAAC;IAC3B,MAAM,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC;IAC5B,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACnB,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACX,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACX,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;IACpB,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,KAAK,CAAC;IACjC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;IAClC,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ReadonlyAffine3, Affine3 } from "./affine3.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a buffer for `count` affine3 elements: a zero-filled `Float64Array`
|
|
4
|
+
* of `count × 12` numbers, element `i` at `[i·12, i·12 + 12)`, a zero element
|
|
5
|
+
* being the all-zero transform (use {@link affine3Store} with the identity to
|
|
6
|
+
* fill it with identities). Allocates.
|
|
7
|
+
*
|
|
8
|
+
* @throws {RangeError} When `count` is not a non-negative safe integer or
|
|
9
|
+
* `count × 12` is not a valid typed array length.
|
|
10
|
+
*/
|
|
11
|
+
export declare function affine3ArrayCreate(count: number): Float64Array<ArrayBuffer>;
|
|
12
|
+
/**
|
|
13
|
+
* Writes element `index` of `array`, the numbers at `[index·12, index·12 +
|
|
14
|
+
* 12)`, into `out`. Each component is written as `+array[i]`, so an index past
|
|
15
|
+
* the end of `array` gives `NaN`, never `undefined`: the transform stays clean
|
|
16
|
+
* whatever the caller does. Checking the index is the job of the checked
|
|
17
|
+
* layer.
|
|
18
|
+
*
|
|
19
|
+
* The transform is copied: it is never a view of `array`. O(1).
|
|
20
|
+
*/
|
|
21
|
+
export declare function affine3Load(out: Affine3, array: Float64Array, index: number): Affine3;
|
|
22
|
+
/**
|
|
23
|
+
* Writes `value` into `array` as element `index`, at `[index·12, index·12 +
|
|
24
|
+
* 12)`. An element past the end of `array` writes nothing, as a typed array
|
|
25
|
+
* drops an out-of-range write. O(1).
|
|
26
|
+
*/
|
|
27
|
+
export declare function affine3Store(array: Float64Array, index: number, value: ReadonlyAffine3): void;
|
|
28
|
+
/**
|
|
29
|
+
* Like {@link affine3Load} for interleaved data: element `index` starts at
|
|
30
|
+
* `offset + index·stride`, both counted in numbers, and its 12 components
|
|
31
|
+
* follow one another. An index past the end gives `NaN` components. O(1).
|
|
32
|
+
*/
|
|
33
|
+
export declare function affine3LoadStrided(out: Affine3, array: Float64Array, offset: number, stride: number, index: number): Affine3;
|
|
34
|
+
/**
|
|
35
|
+
* Like {@link affine3Store} for interleaved data: element `index` starts at
|
|
36
|
+
* `offset + index·stride`, both counted in numbers. A component past the end of
|
|
37
|
+
* `array` writes nothing. O(1).
|
|
38
|
+
*/
|
|
39
|
+
export declare function affine3StoreStrided(array: Float64Array, offset: number, stride: number, index: number, value: ReadonlyAffine3): void;
|
|
40
|
+
/**
|
|
41
|
+
* Narrows `value` to binary32 and writes its 12 components into `array` from
|
|
42
|
+
* element `offset` on, unrolled: the way to stage a vertex, instance or uniform
|
|
43
|
+
* value for the GPU, where `array.set` costs several times as much for one
|
|
44
|
+
* value. A component past the end of `array` writes nothing. O(1).
|
|
45
|
+
*/
|
|
46
|
+
export declare function affine3StoreFloat32(array: Float32Array, offset: number, value: ReadonlyAffine3): void;
|
|
47
|
+
/**
|
|
48
|
+
* Whether every number of `array` is finite: the check for a buffer of affine3
|
|
49
|
+
* elements read from untrusted data or about to be uploaded. The length is not
|
|
50
|
+
* required to be a multiple of 12 (see `assertFiniteBuffer` for that). O(n).
|
|
51
|
+
*/
|
|
52
|
+
export declare function affine3ArrayIsFinite(array: Float64Array): boolean;
|
|
53
|
+
//# sourceMappingURL=affine3-array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"affine3-array.d.ts","sourceRoot":"","sources":["../src/affine3-array.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE7D;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,CAG3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAC1B,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,YAAY,EACnB,KAAK,EAAE,MAAM,GACX,OAAO,CAgBT;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAC3B,KAAK,EAAE,YAAY,EACnB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,eAAe,GACpB,IAAI,CAcN;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CACjC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACX,OAAO,CAgBT;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,eAAe,GACpB,IAAI,CAcN;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,eAAe,GACpB,IAAI,CAaN;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAOjE"}
|