@ac-kit/math-linear 0.2.1 → 0.4.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 +337 -0
- package/README.md +232 -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 +214 -0
- package/dist/_invert.d.ts.map +1 -0
- package/dist/_invert.js +884 -0
- package/dist/_invert.js.map +1 -0
- package/dist/_slerp.d.ts +29 -0
- package/dist/_slerp.d.ts.map +1 -1
- package/dist/_slerp.js +103 -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 +156 -0
- package/dist/affine2.d.ts.map +1 -0
- package/dist/affine2.js +437 -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 +205 -0
- package/dist/affine3.d.ts.map +1 -0
- package/dist/affine3.js +792 -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 +79 -25
- package/dist/mat2x2.d.ts.map +1 -1
- package/dist/mat2x2.js +192 -93
- 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 +153 -48
- package/dist/mat3x3.d.ts.map +1 -1
- package/dist/mat3x3.js +470 -192
- 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 +221 -67
- package/dist/mat4x4.d.ts.map +1 -1
- package/dist/mat4x4.js +972 -334
- package/dist/mat4x4.js.map +1 -1
- package/dist/projection.d.ts +113 -0
- package/dist/projection.d.ts.map +1 -0
- package/dist/projection.js +418 -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 +106 -22
- package/dist/quaternion.d.ts.map +1 -1
- package/dist/quaternion.js +253 -182
- 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 +207 -0
- package/dist/vec2-array-componentwise.d.ts.map +1 -0
- package/dist/vec2-array-componentwise.js +472 -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 +207 -0
- package/dist/vec3-array-componentwise.d.ts.map +1 -0
- package/dist/vec3-array-componentwise.js +510 -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 +391 -272
- package/dist/vec3.js.map +1 -1
- package/dist/vec4-array-componentwise.d.ts +198 -0
- package/dist/vec4-array-componentwise.d.ts.map +1 -0
- package/dist/vec4-array-componentwise.js +521 -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 +59 -53
- package/dist/vec4.d.ts.map +1 -1
- package/dist/vec4.js +74 -249
- 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 +19 -9
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import { numberAtOrNaN } from "@ac-kit/core";
|
|
2
|
+
import { quaternionCreate, quaternionSet, } from "@ac-kit/math-complex";
|
|
3
|
+
import { angleLerpRad, lerp } from "@ac-kit/math-scalar";
|
|
4
|
+
import { SHEAR_TOLERANCE_ } from "./_trs.js";
|
|
5
|
+
import { affine3Compose, affine3Decompose, } from "./affine3.js";
|
|
6
|
+
import { quaternionSlerp } from "./quaternion.js";
|
|
7
|
+
import { vec2Create, vec2LengthScaled, vec2NormalizeScaled, vec2Set, } from "./vec2-componentwise.js";
|
|
8
|
+
import { vec3Create, vec3Set } from "./vec3-componentwise.js";
|
|
9
|
+
/**
|
|
10
|
+
* Every creator copies one of these arrays, which hold non-integer doubles and
|
|
11
|
+
* are never exposed: nothing a caller does can change the element kind they
|
|
12
|
+
* copy.
|
|
13
|
+
*/
|
|
14
|
+
const TEMPLATE_2_ = [0.5, 0.5, 0.5, 0.5, 0.5];
|
|
15
|
+
const TEMPLATE_3_ = [
|
|
16
|
+
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Scratch for the 3D conversions and {@link transform3Lerp}: one call at a time,
|
|
20
|
+
* no callback inside it.
|
|
21
|
+
*/
|
|
22
|
+
const FROM_ROTATION_ = quaternionCreate();
|
|
23
|
+
const TO_ROTATION_ = quaternionCreate();
|
|
24
|
+
const MIDDLE_ROTATION_ = quaternionCreate();
|
|
25
|
+
const PART_TRANSLATION_ = vec3Create();
|
|
26
|
+
const PART_SCALE_ = vec3Create();
|
|
27
|
+
/** The two columns of a 2D affine in {@link transform2FromAffine2}. */
|
|
28
|
+
const COLUMN_X_ = vec2Create();
|
|
29
|
+
const COLUMN_Y_ = vec2Create();
|
|
30
|
+
/**
|
|
31
|
+
* `lerp`, exact at the ends: `a` at `t = 0` and `b` at `t = 1`, whatever `a`
|
|
32
|
+
* and `b`.
|
|
33
|
+
*/
|
|
34
|
+
function lerpExact_(a, b, t) {
|
|
35
|
+
if (t === 0) {
|
|
36
|
+
return a;
|
|
37
|
+
}
|
|
38
|
+
return t === 1 ? b : lerp(a, b, t);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates the identity record `[0, 0, 0, 1, 1]`: no translation, no rotation,
|
|
42
|
+
* unit scale.
|
|
43
|
+
*
|
|
44
|
+
* Allocates; keep it out of hot loops.
|
|
45
|
+
*/
|
|
46
|
+
export function transform2Create() {
|
|
47
|
+
const out = TEMPLATE_2_.slice();
|
|
48
|
+
out[0] = 0;
|
|
49
|
+
out[1] = 0;
|
|
50
|
+
out[2] = 0;
|
|
51
|
+
out[3] = 1;
|
|
52
|
+
out[4] = 1;
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates the record with the translation `[tx, ty]`, the rotation `angle` in
|
|
57
|
+
* radians and the scale `[sx, sy]`.
|
|
58
|
+
*
|
|
59
|
+
* Allocates; keep it out of hot loops.
|
|
60
|
+
*/
|
|
61
|
+
export function transform2Of(tx, ty, angle, sx, sy) {
|
|
62
|
+
const out = TEMPLATE_2_.slice();
|
|
63
|
+
out[0] = tx;
|
|
64
|
+
out[1] = ty;
|
|
65
|
+
out[2] = angle;
|
|
66
|
+
out[3] = sx;
|
|
67
|
+
out[4] = sy;
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates a copy of `transform`. Like every creator it starts from a clean
|
|
72
|
+
* array.
|
|
73
|
+
*
|
|
74
|
+
* Allocates; keep it out of hot loops.
|
|
75
|
+
*/
|
|
76
|
+
export function transform2Clone(transform) {
|
|
77
|
+
const out = TEMPLATE_2_.slice();
|
|
78
|
+
out[0] = transform[0];
|
|
79
|
+
out[1] = transform[1];
|
|
80
|
+
out[2] = transform[2];
|
|
81
|
+
out[3] = transform[3];
|
|
82
|
+
out[4] = transform[4];
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The checked way in from untyped data (JSON, messages, arrays of unknown
|
|
87
|
+
* origin): `source[offset … offset + 5)` copied into `out`, each element that
|
|
88
|
+
* is not a number written as `NaN`, an index past the end of `source` too, so
|
|
89
|
+
* `out` never holds a non-number. A cold path. O(1).
|
|
90
|
+
*
|
|
91
|
+
* `source` may be `out` itself: the five elements are read before the first
|
|
92
|
+
* write.
|
|
93
|
+
*
|
|
94
|
+
* @param out The record to fill.
|
|
95
|
+
* @param source The array to read, of any length and any content.
|
|
96
|
+
* @param offset The index of the first entry in `source`.
|
|
97
|
+
* @returns `out`.
|
|
98
|
+
*/
|
|
99
|
+
export function transform2FromArray(out, source, offset = 0) {
|
|
100
|
+
const tx = numberAtOrNaN(source, offset);
|
|
101
|
+
const ty = numberAtOrNaN(source, offset + 1);
|
|
102
|
+
const angle = numberAtOrNaN(source, offset + 2);
|
|
103
|
+
const sx = numberAtOrNaN(source, offset + 3);
|
|
104
|
+
const sy = numberAtOrNaN(source, offset + 4);
|
|
105
|
+
out[0] = tx;
|
|
106
|
+
out[1] = ty;
|
|
107
|
+
out[2] = angle;
|
|
108
|
+
out[3] = sx;
|
|
109
|
+
out[4] = sy;
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Whether every entry is a finite number: the check to run after parsing
|
|
114
|
+
* untrusted data or before an upload, as operations never check. An entry that
|
|
115
|
+
* is not a number at all counts as not finite.
|
|
116
|
+
*/
|
|
117
|
+
export function transform2IsFinite(transform) {
|
|
118
|
+
return (Number.isFinite(transform[0]) &&
|
|
119
|
+
Number.isFinite(transform[1]) &&
|
|
120
|
+
Number.isFinite(transform[2]) &&
|
|
121
|
+
Number.isFinite(transform[3]) &&
|
|
122
|
+
Number.isFinite(transform[4]));
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Creates the identity record: no translation, the identity rotation `[0, 0, 0,
|
|
126
|
+
* 1]`, unit scale.
|
|
127
|
+
*
|
|
128
|
+
* Allocates; keep it out of hot loops.
|
|
129
|
+
*/
|
|
130
|
+
export function transform3Create() {
|
|
131
|
+
const out = TEMPLATE_3_.slice();
|
|
132
|
+
out[0] = 0;
|
|
133
|
+
out[1] = 0;
|
|
134
|
+
out[2] = 0;
|
|
135
|
+
out[3] = 0;
|
|
136
|
+
out[4] = 0;
|
|
137
|
+
out[5] = 0;
|
|
138
|
+
out[6] = 1;
|
|
139
|
+
out[7] = 1;
|
|
140
|
+
out[8] = 1;
|
|
141
|
+
out[9] = 1;
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Creates a record from its three parts, copying them: the translation, the
|
|
146
|
+
* rotation (a unit quaternion, not normalised here) and the scale along the
|
|
147
|
+
* rotated axes.
|
|
148
|
+
*
|
|
149
|
+
* Allocates; keep it out of hot loops.
|
|
150
|
+
*/
|
|
151
|
+
export function transform3Of(translation, rotation, scale) {
|
|
152
|
+
const out = TEMPLATE_3_.slice();
|
|
153
|
+
out[0] = translation[0];
|
|
154
|
+
out[1] = translation[1];
|
|
155
|
+
out[2] = translation[2];
|
|
156
|
+
out[3] = rotation[0];
|
|
157
|
+
out[4] = rotation[1];
|
|
158
|
+
out[5] = rotation[2];
|
|
159
|
+
out[6] = rotation[3];
|
|
160
|
+
out[7] = scale[0];
|
|
161
|
+
out[8] = scale[1];
|
|
162
|
+
out[9] = scale[2];
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Creates a copy of `transform`. Like every creator it starts from a clean
|
|
167
|
+
* array.
|
|
168
|
+
*
|
|
169
|
+
* Allocates; keep it out of hot loops.
|
|
170
|
+
*/
|
|
171
|
+
export function transform3Clone(transform) {
|
|
172
|
+
const out = TEMPLATE_3_.slice();
|
|
173
|
+
out[0] = transform[0];
|
|
174
|
+
out[1] = transform[1];
|
|
175
|
+
out[2] = transform[2];
|
|
176
|
+
out[3] = transform[3];
|
|
177
|
+
out[4] = transform[4];
|
|
178
|
+
out[5] = transform[5];
|
|
179
|
+
out[6] = transform[6];
|
|
180
|
+
out[7] = transform[7];
|
|
181
|
+
out[8] = transform[8];
|
|
182
|
+
out[9] = transform[9];
|
|
183
|
+
return out;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* The checked way in from untyped data (JSON, messages, arrays of unknown
|
|
187
|
+
* origin): `source[offset … offset + 10)` copied into `out`, each element that
|
|
188
|
+
* is not a number written as `NaN`, an index past the end of `source` too, so
|
|
189
|
+
* `out` never holds a non-number. A cold path. O(1).
|
|
190
|
+
*
|
|
191
|
+
* `source` may be `out` itself: the ten elements are read before the first
|
|
192
|
+
* write.
|
|
193
|
+
*
|
|
194
|
+
* @param out The record to fill.
|
|
195
|
+
* @param source The array to read, of any length and any content.
|
|
196
|
+
* @param offset The index of the first entry in `source`.
|
|
197
|
+
* @returns `out`.
|
|
198
|
+
*/
|
|
199
|
+
export function transform3FromArray(out, source, offset = 0) {
|
|
200
|
+
const tx = numberAtOrNaN(source, offset);
|
|
201
|
+
const ty = numberAtOrNaN(source, offset + 1);
|
|
202
|
+
const tz = numberAtOrNaN(source, offset + 2);
|
|
203
|
+
const qx = numberAtOrNaN(source, offset + 3);
|
|
204
|
+
const qy = numberAtOrNaN(source, offset + 4);
|
|
205
|
+
const qz = numberAtOrNaN(source, offset + 5);
|
|
206
|
+
const qw = numberAtOrNaN(source, offset + 6);
|
|
207
|
+
const sx = numberAtOrNaN(source, offset + 7);
|
|
208
|
+
const sy = numberAtOrNaN(source, offset + 8);
|
|
209
|
+
const sz = numberAtOrNaN(source, offset + 9);
|
|
210
|
+
out[0] = tx;
|
|
211
|
+
out[1] = ty;
|
|
212
|
+
out[2] = tz;
|
|
213
|
+
out[3] = qx;
|
|
214
|
+
out[4] = qy;
|
|
215
|
+
out[5] = qz;
|
|
216
|
+
out[6] = qw;
|
|
217
|
+
out[7] = sx;
|
|
218
|
+
out[8] = sy;
|
|
219
|
+
out[9] = sz;
|
|
220
|
+
return out;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Whether every entry is a finite number: the check to run after parsing
|
|
224
|
+
* untrusted data or before an upload, as operations never check. An entry that
|
|
225
|
+
* is not a number at all counts as not finite.
|
|
226
|
+
*/
|
|
227
|
+
export function transform3IsFinite(transform) {
|
|
228
|
+
return (Number.isFinite(transform[0]) &&
|
|
229
|
+
Number.isFinite(transform[1]) &&
|
|
230
|
+
Number.isFinite(transform[2]) &&
|
|
231
|
+
Number.isFinite(transform[3]) &&
|
|
232
|
+
Number.isFinite(transform[4]) &&
|
|
233
|
+
Number.isFinite(transform[5]) &&
|
|
234
|
+
Number.isFinite(transform[6]) &&
|
|
235
|
+
Number.isFinite(transform[7]) &&
|
|
236
|
+
Number.isFinite(transform[8]) &&
|
|
237
|
+
Number.isFinite(transform[9]));
|
|
238
|
+
}
|
|
239
|
+
/** Writes the identity record `[0, 0, 0, 1, 1]` into `out`. */
|
|
240
|
+
export function transform2Identity(out) {
|
|
241
|
+
out[0] = 0;
|
|
242
|
+
out[1] = 0;
|
|
243
|
+
out[2] = 0;
|
|
244
|
+
out[3] = 1;
|
|
245
|
+
out[4] = 1;
|
|
246
|
+
return out;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Writes the interpolation from `a` to `b` into `out`: the translation and the
|
|
250
|
+
* scale linearly (`@ac-kit/math-scalar`'s `lerp`, but exactly `a` at `t = 0`
|
|
251
|
+
* and exactly `b` at `t = 1`, which `lerp` is not where `a` and `b` differ
|
|
252
|
+
* greatly in magnitude: a translation of `1e16` to `1` would end at `0`), the
|
|
253
|
+
* angle along the shorter arc (`angleLerpRad`, the result in `(−π, π]`), so a
|
|
254
|
+
* key at 350° and one at 10° meet at 0°; at `t = 0` and `t = 1` the angle is
|
|
255
|
+
* that of `a` and of `b`, normalised. A `t` outside `[0, 1]` extrapolates.
|
|
256
|
+
* `out` may be `a` or `b`.
|
|
257
|
+
*/
|
|
258
|
+
export function transform2Lerp(out, a, b, t) {
|
|
259
|
+
out[0] = lerpExact_(a[0], b[0], t);
|
|
260
|
+
out[1] = lerpExact_(a[1], b[1], t);
|
|
261
|
+
out[2] = angleLerpRad(a[2], b[2], t);
|
|
262
|
+
out[3] = lerpExact_(a[3], b[3], t);
|
|
263
|
+
out[4] = lerpExact_(a[4], b[4], t);
|
|
264
|
+
return out;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Writes the affine transform `T · R · S` of `transform` into `out`: the scale
|
|
268
|
+
* first, then the rotation, then the translation.
|
|
269
|
+
*/
|
|
270
|
+
export function affine2FromTransform2(out, transform) {
|
|
271
|
+
const cos = Math.cos(transform[2]);
|
|
272
|
+
const sin = Math.sin(transform[2]);
|
|
273
|
+
const sx = transform[3];
|
|
274
|
+
const sy = transform[4];
|
|
275
|
+
out[0] = cos * sx;
|
|
276
|
+
out[1] = sin * sx;
|
|
277
|
+
out[2] = -sin * sy;
|
|
278
|
+
out[3] = cos * sy;
|
|
279
|
+
out[4] = transform[0];
|
|
280
|
+
out[5] = transform[1];
|
|
281
|
+
return out;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Splits the affine transform `a` into the translation, rotation and scale that
|
|
285
|
+
* {@link affine2FromTransform2} composes it from: the translation is the last
|
|
286
|
+
* column, the angle is that of the first column (in `(−π, π]`), the x scale is
|
|
287
|
+
* its length and the y scale is the length of the second, negative for a
|
|
288
|
+
* reflection.
|
|
289
|
+
*
|
|
290
|
+
* Returns `false` when there is no such split: a column of zero length or not
|
|
291
|
+
* finite, the two columns further from perpendicular than about `1e-6` in
|
|
292
|
+
* cosine (a shear), or a translation that is not finite. `out` then holds
|
|
293
|
+
* `NaN`, never a stale or partial record, and nothing throws.
|
|
294
|
+
*/
|
|
295
|
+
export function transform2FromAffine2(out, a) {
|
|
296
|
+
const a0 = a[0];
|
|
297
|
+
const a1 = a[1];
|
|
298
|
+
const a2 = a[2];
|
|
299
|
+
const a3 = a[3];
|
|
300
|
+
const x = a[4];
|
|
301
|
+
const y = a[5];
|
|
302
|
+
const lengthX = vec2LengthScaled(vec2Set(COLUMN_X_, a0, a1));
|
|
303
|
+
const lengthY = vec2LengthScaled(vec2Set(COLUMN_Y_, a2, a3));
|
|
304
|
+
// The unit columns come from the scaled normalisation, not from dividing by
|
|
305
|
+
// the rounded length: a column of subnormal numbers has a length that rounds
|
|
306
|
+
// to a coarse multiple of the smallest one.
|
|
307
|
+
vec2NormalizeScaled(COLUMN_X_, COLUMN_X_);
|
|
308
|
+
vec2NormalizeScaled(COLUMN_Y_, COLUMN_Y_);
|
|
309
|
+
const ux = COLUMN_X_[0];
|
|
310
|
+
const uy = COLUMN_X_[1];
|
|
311
|
+
const vx = COLUMN_Y_[0];
|
|
312
|
+
const vy = COLUMN_Y_[1];
|
|
313
|
+
if (lengthX > 0 &&
|
|
314
|
+
lengthY > 0 &&
|
|
315
|
+
lengthX < Infinity &&
|
|
316
|
+
lengthY < Infinity &&
|
|
317
|
+
Number.isFinite(x) &&
|
|
318
|
+
Number.isFinite(y) &&
|
|
319
|
+
Math.abs(ux * vx + uy * vy) <= SHEAR_TOLERANCE_) {
|
|
320
|
+
out[0] = x;
|
|
321
|
+
out[1] = y;
|
|
322
|
+
// Adding zero turns −0 into +0, so a half turn is π and not −π.
|
|
323
|
+
out[2] = Math.atan2(a1 + 0, a0);
|
|
324
|
+
out[3] = lengthX;
|
|
325
|
+
out[4] = ux * vy - uy * vx < 0 ? -lengthY : lengthY;
|
|
326
|
+
return true;
|
|
327
|
+
}
|
|
328
|
+
out[0] = Number.NaN;
|
|
329
|
+
out[1] = Number.NaN;
|
|
330
|
+
out[2] = Number.NaN;
|
|
331
|
+
out[3] = Number.NaN;
|
|
332
|
+
out[4] = Number.NaN;
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Writes the identity record into `out`: no translation, the identity rotation,
|
|
337
|
+
* unit scale.
|
|
338
|
+
*/
|
|
339
|
+
export function transform3Identity(out) {
|
|
340
|
+
out[0] = 0;
|
|
341
|
+
out[1] = 0;
|
|
342
|
+
out[2] = 0;
|
|
343
|
+
out[3] = 0;
|
|
344
|
+
out[4] = 0;
|
|
345
|
+
out[5] = 0;
|
|
346
|
+
out[6] = 1;
|
|
347
|
+
out[7] = 1;
|
|
348
|
+
out[8] = 1;
|
|
349
|
+
out[9] = 1;
|
|
350
|
+
return out;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Writes the interpolation from `a` to `b` into `out`: the translation and the
|
|
354
|
+
* scale linearly (`@ac-kit/math-scalar`'s `lerp`, but exactly `a` at `t = 0`
|
|
355
|
+
* and exactly `b` at `t = 1`, which `lerp` is not where `a` and `b` differ
|
|
356
|
+
* greatly in magnitude: a translation of `1e16` to `1` would end at `0`), the
|
|
357
|
+
* rotation by {@link quaternionSlerp} along the shorter arc (the quaternions
|
|
358
|
+
* must be unit length). A `t` outside `[0, 1]` extrapolates. `out` may be `a`
|
|
359
|
+
* or `b`.
|
|
360
|
+
*/
|
|
361
|
+
export function transform3Lerp(out, a, b, t) {
|
|
362
|
+
quaternionSet(FROM_ROTATION_, a[3], a[4], a[5], a[6]);
|
|
363
|
+
quaternionSet(TO_ROTATION_, b[3], b[4], b[5], b[6]);
|
|
364
|
+
quaternionSlerp(MIDDLE_ROTATION_, FROM_ROTATION_, TO_ROTATION_, t);
|
|
365
|
+
out[0] = lerpExact_(a[0], b[0], t);
|
|
366
|
+
out[1] = lerpExact_(a[1], b[1], t);
|
|
367
|
+
out[2] = lerpExact_(a[2], b[2], t);
|
|
368
|
+
out[3] = MIDDLE_ROTATION_[0];
|
|
369
|
+
out[4] = MIDDLE_ROTATION_[1];
|
|
370
|
+
out[5] = MIDDLE_ROTATION_[2];
|
|
371
|
+
out[6] = MIDDLE_ROTATION_[3];
|
|
372
|
+
out[7] = lerpExact_(a[7], b[7], t);
|
|
373
|
+
out[8] = lerpExact_(a[8], b[8], t);
|
|
374
|
+
out[9] = lerpExact_(a[9], b[9], t);
|
|
375
|
+
return out;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Writes the affine transform `T · R · S` of `transform` into `out`:
|
|
379
|
+
* {@link affine3Compose} of its three parts, the rotation a unit quaternion.
|
|
380
|
+
*/
|
|
381
|
+
export function affine3FromTransform3(out, transform) {
|
|
382
|
+
vec3Set(PART_TRANSLATION_, transform[0], transform[1], transform[2]);
|
|
383
|
+
quaternionSet(FROM_ROTATION_, transform[3], transform[4], transform[5], transform[6]);
|
|
384
|
+
vec3Set(PART_SCALE_, transform[7], transform[8], transform[9]);
|
|
385
|
+
return affine3Compose(out, PART_TRANSLATION_, FROM_ROTATION_, PART_SCALE_);
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Splits the affine transform `a` into the record that
|
|
389
|
+
* {@link affine3FromTransform3} composes it from, by {@link affine3Decompose}:
|
|
390
|
+
* the translation is the last column, the scale the length of each of the
|
|
391
|
+
* others (the x scale negative for a reflection) and the rotation their unit
|
|
392
|
+
* quaternion.
|
|
393
|
+
*
|
|
394
|
+
* Returns `false` when there is no such split (a column of zero length or not
|
|
395
|
+
* finite, a shear, a translation that is not finite): `out` then holds `NaN`,
|
|
396
|
+
* never a stale or partial record, and nothing throws.
|
|
397
|
+
*/
|
|
398
|
+
export function transform3FromAffine3(out, a) {
|
|
399
|
+
const split = affine3Decompose(PART_TRANSLATION_, FROM_ROTATION_, PART_SCALE_, a);
|
|
400
|
+
out[0] = PART_TRANSLATION_[0];
|
|
401
|
+
out[1] = PART_TRANSLATION_[1];
|
|
402
|
+
out[2] = PART_TRANSLATION_[2];
|
|
403
|
+
out[3] = FROM_ROTATION_[0];
|
|
404
|
+
out[4] = FROM_ROTATION_[1];
|
|
405
|
+
out[5] = FROM_ROTATION_[2];
|
|
406
|
+
out[6] = FROM_ROTATION_[3];
|
|
407
|
+
out[7] = PART_SCALE_[0];
|
|
408
|
+
out[8] = PART_SCALE_[1];
|
|
409
|
+
out[9] = PART_SCALE_[2];
|
|
410
|
+
return split;
|
|
411
|
+
}
|
|
412
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../src/transform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,qBAAqB,CACpC,GAAe,EACf,CAAkB;IAElB,MAAM,KAAK,GAAG,gBAAgB,CAC7B,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,CAAC,CACD,CAAC;IACF,GAAG,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC9B,GAAG,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC9B,GAAG,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC9B,GAAG,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;IAC3B,GAAG,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;IAC3B,GAAG,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;IAC3B,GAAG,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;IAC3B,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;IACxB,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;IACxB,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;IACxB,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Solves the tridiagonal system `A · x = right` by the Thomas algorithm
|
|
3
|
+
* (Gaussian elimination without pivoting, restricted to the three diagonals; L.
|
|
4
|
+
* H. Thomas, 1949; Golub & Van Loan, _Matrix Computations_, 4th ed., §4.3.6).
|
|
5
|
+
* Row `i` of `A` is
|
|
6
|
+
*
|
|
7
|
+
* ```text
|
|
8
|
+
* lower[i − 1] · x[i − 1] + diagonal[i] · x[i] + upper[i] · x[i + 1] = right[i]
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* With the out-of-range terms absent, so `lower` and `upper` hold `n − 1`
|
|
12
|
+
* numbers each (LAPACK's `dl`, `d`, `du` layout).
|
|
13
|
+
*
|
|
14
|
+
* Stability: elimination without pivoting is backward stable, and meets no zero
|
|
15
|
+
* pivot, when `A` is diagonally dominant by rows (`|diagonal[i]| ≥ |lower[i −
|
|
16
|
+
* 1]| + |upper[i]|`, strictly in at least one row of every irreducible block)
|
|
17
|
+
* or by columns, or symmetric positive definite (Higham, _Accuracy and
|
|
18
|
+
* Stability of Numerical Algorithms_, 2nd ed., §9.6). Spline and
|
|
19
|
+
* finite-difference systems are of that kind. Other non-singular matrices can
|
|
20
|
+
* meet a zero pivot, which returns `false`, or a tiny one that loses accuracy:
|
|
21
|
+
* solve them with a pivoting LU.
|
|
22
|
+
*
|
|
23
|
+
* Checks, in this order: the lengths (a `RangeError`), then each pivot as the
|
|
24
|
+
* elimination reaches it, which is the only test on the values: the first zero
|
|
25
|
+
* pivot returns `false` with `out` all `NaN`, whatever the other entries hold
|
|
26
|
+
* (a `NaN` anywhere included). Non-finite entries are not checked otherwise:
|
|
27
|
+
* with no zero pivot met they propagate into `out` and the call returns `true`
|
|
28
|
+
* (S13; checking finiteness belongs at the caller's boundary, S13a). Plain
|
|
29
|
+
* arithmetic, so the range is that of the rest of the package: entries and
|
|
30
|
+
* intermediate products within about [1e−150, 1e150]; beyond (a 1e308
|
|
31
|
+
* diagonal), the elimination can overflow to `Infinity` and still return
|
|
32
|
+
* `true`.
|
|
33
|
+
*
|
|
34
|
+
* Complexity: O(n) time, no allocation.
|
|
35
|
+
*
|
|
36
|
+
* @param out - The solution `x`, `n` numbers. May be `right` itself.
|
|
37
|
+
* @param lower - The sub-diagonal, `n − 1` numbers: `lower[i]` is `A[i +
|
|
38
|
+
* 1][i]`.
|
|
39
|
+
* @param diagonal - The diagonal, `n` numbers.
|
|
40
|
+
* @param upper - The super-diagonal, `n − 1` numbers: `upper[i]` is `A[i][i +
|
|
41
|
+
* 1]`.
|
|
42
|
+
* @param right - The right-hand side, `n` numbers.
|
|
43
|
+
* @param scratch - Working space of `n − 1` numbers, overwritten. May be
|
|
44
|
+
* `upper` itself, which is then overwritten.
|
|
45
|
+
* @returns `false` when the elimination meets a zero pivot, `out` then all
|
|
46
|
+
* `NaN`; `true` otherwise, non-finite values propagating into `out`.
|
|
47
|
+
* @throws {RangeError} When `out`, `right` and `diagonal` do not have the same
|
|
48
|
+
* length `n`, or `lower`, `upper` and `scratch` do not have `max(n − 1, 0)`
|
|
49
|
+
* numbers.
|
|
50
|
+
*/
|
|
51
|
+
export declare function tridiagonalSolve(out: Float64Array, lower: Float64Array, diagonal: Float64Array, upper: Float64Array, right: Float64Array, scratch: Float64Array): boolean;
|
|
52
|
+
//# sourceMappingURL=tridiagonal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tridiagonal.d.ts","sourceRoot":"","sources":["../src/tridiagonal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,YAAY,EACnB,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,YAAY,GACnB,OAAO,CAuDT"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Solves the tridiagonal system `A · x = right` by the Thomas algorithm
|
|
3
|
+
* (Gaussian elimination without pivoting, restricted to the three diagonals; L.
|
|
4
|
+
* H. Thomas, 1949; Golub & Van Loan, _Matrix Computations_, 4th ed., §4.3.6).
|
|
5
|
+
* Row `i` of `A` is
|
|
6
|
+
*
|
|
7
|
+
* ```text
|
|
8
|
+
* lower[i − 1] · x[i − 1] + diagonal[i] · x[i] + upper[i] · x[i + 1] = right[i]
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* With the out-of-range terms absent, so `lower` and `upper` hold `n − 1`
|
|
12
|
+
* numbers each (LAPACK's `dl`, `d`, `du` layout).
|
|
13
|
+
*
|
|
14
|
+
* Stability: elimination without pivoting is backward stable, and meets no zero
|
|
15
|
+
* pivot, when `A` is diagonally dominant by rows (`|diagonal[i]| ≥ |lower[i −
|
|
16
|
+
* 1]| + |upper[i]|`, strictly in at least one row of every irreducible block)
|
|
17
|
+
* or by columns, or symmetric positive definite (Higham, _Accuracy and
|
|
18
|
+
* Stability of Numerical Algorithms_, 2nd ed., §9.6). Spline and
|
|
19
|
+
* finite-difference systems are of that kind. Other non-singular matrices can
|
|
20
|
+
* meet a zero pivot, which returns `false`, or a tiny one that loses accuracy:
|
|
21
|
+
* solve them with a pivoting LU.
|
|
22
|
+
*
|
|
23
|
+
* Checks, in this order: the lengths (a `RangeError`), then each pivot as the
|
|
24
|
+
* elimination reaches it, which is the only test on the values: the first zero
|
|
25
|
+
* pivot returns `false` with `out` all `NaN`, whatever the other entries hold
|
|
26
|
+
* (a `NaN` anywhere included). Non-finite entries are not checked otherwise:
|
|
27
|
+
* with no zero pivot met they propagate into `out` and the call returns `true`
|
|
28
|
+
* (S13; checking finiteness belongs at the caller's boundary, S13a). Plain
|
|
29
|
+
* arithmetic, so the range is that of the rest of the package: entries and
|
|
30
|
+
* intermediate products within about [1e−150, 1e150]; beyond (a 1e308
|
|
31
|
+
* diagonal), the elimination can overflow to `Infinity` and still return
|
|
32
|
+
* `true`.
|
|
33
|
+
*
|
|
34
|
+
* Complexity: O(n) time, no allocation.
|
|
35
|
+
*
|
|
36
|
+
* @param out - The solution `x`, `n` numbers. May be `right` itself.
|
|
37
|
+
* @param lower - The sub-diagonal, `n − 1` numbers: `lower[i]` is `A[i +
|
|
38
|
+
* 1][i]`.
|
|
39
|
+
* @param diagonal - The diagonal, `n` numbers.
|
|
40
|
+
* @param upper - The super-diagonal, `n − 1` numbers: `upper[i]` is `A[i][i +
|
|
41
|
+
* 1]`.
|
|
42
|
+
* @param right - The right-hand side, `n` numbers.
|
|
43
|
+
* @param scratch - Working space of `n − 1` numbers, overwritten. May be
|
|
44
|
+
* `upper` itself, which is then overwritten.
|
|
45
|
+
* @returns `false` when the elimination meets a zero pivot, `out` then all
|
|
46
|
+
* `NaN`; `true` otherwise, non-finite values propagating into `out`.
|
|
47
|
+
* @throws {RangeError} When `out`, `right` and `diagonal` do not have the same
|
|
48
|
+
* length `n`, or `lower`, `upper` and `scratch` do not have `max(n − 1, 0)`
|
|
49
|
+
* numbers.
|
|
50
|
+
*/
|
|
51
|
+
export function tridiagonalSolve(out, lower, diagonal, upper, right, scratch) {
|
|
52
|
+
const size = diagonal.length;
|
|
53
|
+
const offSize = size === 0 ? 0 : size - 1;
|
|
54
|
+
if (out.length !== size ||
|
|
55
|
+
right.length !== size ||
|
|
56
|
+
lower.length !== offSize ||
|
|
57
|
+
upper.length !== offSize ||
|
|
58
|
+
scratch.length !== offSize) {
|
|
59
|
+
throw new RangeError(`tridiagonalSolve: out, right and diagonal need one length n and lower, upper and scratch n − 1, got out ${out.length}, lower ${lower.length}, diagonal ${size}, upper ${upper.length}, right ${right.length}, scratch ${scratch.length}`);
|
|
60
|
+
}
|
|
61
|
+
if (size === 0) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
let pivot = diagonal[0];
|
|
65
|
+
if (pivot === 0) {
|
|
66
|
+
out.fill(Number.NaN);
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
if (size > 1) {
|
|
70
|
+
scratch[0] = upper[0] / pivot;
|
|
71
|
+
}
|
|
72
|
+
out[0] = right[0] / pivot;
|
|
73
|
+
for (let index = 1; index < size; index++) {
|
|
74
|
+
const factor = lower[index - 1];
|
|
75
|
+
pivot = diagonal[index] - factor * scratch[index - 1];
|
|
76
|
+
if (pivot === 0) {
|
|
77
|
+
out.fill(Number.NaN);
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
if (index < offSize) {
|
|
81
|
+
scratch[index] = upper[index] / pivot;
|
|
82
|
+
}
|
|
83
|
+
out[index] = (right[index] - factor * out[index - 1]) / pivot;
|
|
84
|
+
}
|
|
85
|
+
for (let index = size - 2; index >= 0; index--) {
|
|
86
|
+
out[index] = out[index] - scratch[index] * out[index + 1];
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=tridiagonal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tridiagonal.js","sourceRoot":"","sources":["../src/tridiagonal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,MAAM,UAAU,gBAAgB,CAC/B,GAAiB,EACjB,KAAmB,EACnB,QAAsB,EACtB,KAAmB,EACnB,KAAmB,EACnB,OAAqB;IAErB,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC7B,MAAM,OAAO,GAAG,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;IAE1C,IACC,GAAG,CAAC,MAAM,KAAK,IAAI;QACnB,KAAK,CAAC,MAAM,KAAK,IAAI;QACrB,KAAK,CAAC,MAAM,KAAK,OAAO;QACxB,KAAK,CAAC,MAAM,KAAK,OAAO;QACxB,OAAO,CAAC,MAAM,KAAK,OAAO,EACzB,CAAC;QACF,MAAM,IAAI,UAAU,CACnB,2GAA2G,GAAG,CAAC,MAAM,WAAW,KAAK,CAAC,MAAM,cAAc,IAAI,WAAW,KAAK,CAAC,MAAM,WAAW,KAAK,CAAC,MAAM,aAAa,OAAO,CAAC,MAAM,EAAE,CACzO,CAAC;IACH,CAAC;IAED,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAI,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAE,CAAC;IAEzB,IAAI,KAAK,K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,CAAC,CAAE,CAAC;IAC9D,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC"}
|
package/dist/upload.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ReadonlyQuaternion } from "@ac-kit/math-complex";
|
|
2
|
+
import type { ReadonlyAffine2 } from "./affine2.js";
|
|
3
|
+
import type { ReadonlyAffine3 } from "./affine3.js";
|
|
4
|
+
import type { ReadonlyMat2x2 } from "./mat2x2.js";
|
|
5
|
+
import type { ReadonlyMat3x3 } from "./mat3x3.js";
|
|
6
|
+
import type { ReadonlyMat4x4 } from "./mat4x4.js";
|
|
7
|
+
/**
|
|
8
|
+
* Writes the four entries of `m`, in storage (column) order, narrowed to 32
|
|
9
|
+
* bits, into `array` from `offset`: unrolled stores, which cost a few
|
|
10
|
+
* nanoseconds where `Float32Array.prototype.set` on an array costs fifteen. An
|
|
11
|
+
* entry past the end of `array` is dropped, as for any typed array store. Not a
|
|
12
|
+
* uniform layout: see {@link mat3x3StoreStd140Float32} for the types a uniform
|
|
13
|
+
* block pads.
|
|
14
|
+
*/
|
|
15
|
+
export declare function mat2x2StoreFloat32(array: Float32Array, offset: number, m: ReadonlyMat2x2): void;
|
|
16
|
+
/**
|
|
17
|
+
* Writes the nine entries of `m`, in storage (column) order, narrowed to 32
|
|
18
|
+
* bits, into `array` from `offset`, tight. A uniform block pads each column to
|
|
19
|
+
* four floats instead: use {@link mat3x3StoreStd140Float32} for one.
|
|
20
|
+
*/
|
|
21
|
+
export declare function mat3x3StoreFloat32(array: Float32Array, offset: number, m: ReadonlyMat3x3): void;
|
|
22
|
+
/**
|
|
23
|
+
* Writes the sixteen entries of `m`, in storage (column) order, narrowed to 32
|
|
24
|
+
* bits, into `array` from `offset`. The columns are four floats apart, so this
|
|
25
|
+
* is also the layout of a `mat4x4f` in a uniform block.
|
|
26
|
+
*/
|
|
27
|
+
export declare function mat4x4StoreFloat32(array: Float32Array, offset: number, m: ReadonlyMat4x4): void;
|
|
28
|
+
/**
|
|
29
|
+
* Writes the four components `x, y, z, w` of `q`, narrowed to 32 bits, into
|
|
30
|
+
* `array` from `offset`: an instance rotation or a `vec4f` uniform.
|
|
31
|
+
*/
|
|
32
|
+
export declare function quaternionStoreFloat32(array: Float32Array, offset: number, q: ReadonlyQuaternion): void;
|
|
33
|
+
/**
|
|
34
|
+
* Writes `m` as a `mat3x3f` of a uniform block, narrowed to 32 bits: three
|
|
35
|
+
* columns of three floats, each followed by a padding `0`, twelve floats from
|
|
36
|
+
* `offset` (std140, and WGSL's uniform layout, which `@ac-kit/graphics-gpu`
|
|
37
|
+
* makes identical). Every float of the field is written, the padding too.
|
|
38
|
+
*/
|
|
39
|
+
export declare function mat3x3StoreStd140Float32(array: Float32Array, offset: number, m: ReadonlyMat3x3): void;
|
|
40
|
+
/**
|
|
41
|
+
* Writes `transform` as a `mat4x3f` of a uniform block, narrowed to 32 bits:
|
|
42
|
+
* four columns of three floats (the axes, then the translation), each followed
|
|
43
|
+
* by a padding `0`, sixteen floats from `offset`. Every float of the field is
|
|
44
|
+
* written, the padding too.
|
|
45
|
+
*/
|
|
46
|
+
export declare function affine3StoreStd140Float32(array: Float32Array, offset: number, transform: ReadonlyAffine3): void;
|
|
47
|
+
/**
|
|
48
|
+
* Writes the 2D affine `transform` as a `mat3x3f` of a uniform block holding
|
|
49
|
+
* the homogeneous matrix, narrowed to 32 bits: the columns `(a, b, 0)`, `(c, d,
|
|
50
|
+
* 0)` and `(e, f, 1)`, each followed by a padding `0`, twelve floats from
|
|
51
|
+
* `offset`: what `@ac-kit/graphics-gpu` does with a 2-row source. Every float
|
|
52
|
+
* of the field is written, the padding too.
|
|
53
|
+
*/
|
|
54
|
+
export declare function affine2StoreStd140Float32(array: Float32Array, offset: number, transform: ReadonlyAffine2): void;
|
|
55
|
+
//# sourceMappingURL=upload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../src/upload.ts"],"names":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