typegpu 0.11.9 → 0.12.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.
Files changed (362) hide show
  1. package/builtin.d.ts +51 -53
  2. package/builtin.js +30 -34
  3. package/common/fullScreenTriangle.d.ts +2 -10
  4. package/common/fullScreenTriangle.js +20 -28
  5. package/common/index.d.ts +2 -9
  6. package/common/index.js +3 -12
  7. package/common/writeSoA.d.ts +11 -12
  8. package/common/writeSoA.js +88 -76
  9. package/core/buffer/buffer.d.ts +79 -62
  10. package/core/buffer/buffer.js +279 -205
  11. package/core/buffer/bufferBinding.d.ts +71 -0
  12. package/core/buffer/bufferBinding.js +154 -0
  13. package/core/buffer/bufferUsage.d.ts +14 -45
  14. package/core/buffer/bufferUsage.js +1 -171
  15. package/core/buffer/laidOutBuffer.d.ts +25 -0
  16. package/core/buffer/laidOutBuffer.js +55 -0
  17. package/core/commandEncoder/attachments.d.ts +125 -0
  18. package/core/commandEncoder/attachments.js +29 -0
  19. package/core/commandEncoder/commandEncoder.d.ts +53 -0
  20. package/core/commandEncoder/commandEncoder.js +56 -0
  21. package/core/commandEncoder/computePass.d.ts +58 -0
  22. package/core/commandEncoder/computePass.js +63 -0
  23. package/core/commandEncoder/renderPass.d.ts +121 -0
  24. package/core/commandEncoder/renderPass.js +196 -0
  25. package/core/constant/tgpuConstant.d.ts +26 -26
  26. package/core/constant/tgpuConstant.js +76 -65
  27. package/core/declare/tgpuDeclare.d.ts +3 -6
  28. package/core/declare/tgpuDeclare.js +36 -36
  29. package/core/function/autoIO.d.ts +61 -33
  30. package/core/function/autoIO.js +68 -73
  31. package/core/function/comptime.d.ts +11 -13
  32. package/core/function/comptime.js +60 -52
  33. package/core/function/createCallableSchema.d.ts +16 -0
  34. package/core/function/createCallableSchema.js +50 -40
  35. package/core/function/dualImpl.d.ts +44 -0
  36. package/core/function/dualImpl.js +71 -50
  37. package/core/function/entryInputRouter.d.ts +26 -0
  38. package/core/function/entryInputRouter.js +31 -33
  39. package/core/function/extractArgs.d.ts +38 -0
  40. package/core/function/extractArgs.js +202 -200
  41. package/core/function/fnCore.d.ts +44 -5
  42. package/core/function/fnCore.js +148 -93
  43. package/core/function/fnTypes.d.ts +31 -29
  44. package/core/function/fnTypes.js +1 -0
  45. package/core/function/ioSchema.d.ts +12 -10
  46. package/core/function/ioSchema.js +65 -47
  47. package/core/function/shelllessImpl.d.ts +9 -12
  48. package/core/function/shelllessImpl.js +17 -22
  49. package/core/function/templateUtils.d.ts +2 -0
  50. package/core/function/templateUtils.js +9 -8
  51. package/core/function/tgpuComputeFn.d.ts +26 -28
  52. package/core/function/tgpuComputeFn.js +47 -48
  53. package/core/function/tgpuFn.d.ts +34 -37
  54. package/core/function/tgpuFn.js +179 -153
  55. package/core/function/tgpuFragmentFn.d.ts +52 -53
  56. package/core/function/tgpuFragmentFn.js +63 -56
  57. package/core/function/tgpuVertexFn.d.ts +36 -39
  58. package/core/function/tgpuVertexFn.js +56 -53
  59. package/core/pipeline/computePipeline.d.ts +141 -53
  60. package/core/pipeline/computePipeline.js +291 -225
  61. package/core/pipeline/connectAttachmentToShader.d.ts +4 -0
  62. package/core/pipeline/connectAttachmentToShader.js +25 -22
  63. package/core/pipeline/connectTargetsToShader.d.ts +3 -0
  64. package/core/pipeline/connectTargetsToShader.js +29 -27
  65. package/core/pipeline/drawState.d.ts +52 -0
  66. package/core/pipeline/drawState.js +225 -0
  67. package/core/pipeline/limitsOverflow.d.ts +2 -0
  68. package/core/pipeline/limitsOverflow.js +13 -10
  69. package/core/pipeline/performanceTracker.d.ts +14 -0
  70. package/core/pipeline/performanceTracker.js +34 -0
  71. package/core/pipeline/pipelineUtils.d.ts +18 -0
  72. package/core/pipeline/pipelineUtils.js +54 -25
  73. package/core/pipeline/priors.d.ts +1 -0
  74. package/core/pipeline/priors.js +12 -0
  75. package/core/pipeline/renderPipeline.d.ts +246 -261
  76. package/core/pipeline/renderPipeline.js +487 -480
  77. package/core/pipeline/timeable.d.ts +28 -18
  78. package/core/pipeline/timeable.js +90 -52
  79. package/core/pipeline/typeGuards.d.ts +17 -0
  80. package/core/pipeline/typeGuards.js +52 -22
  81. package/core/querySet/querySet.d.ts +26 -21
  82. package/core/querySet/querySet.js +127 -103
  83. package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +13 -18
  84. package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +89 -90
  85. package/core/resolve/externals.d.ts +25 -8
  86. package/core/resolve/externals.js +78 -54
  87. package/core/resolve/namespace.d.ts +22 -25
  88. package/core/resolve/namespace.js +16 -21
  89. package/core/resolve/resolvableString.d.ts +7 -0
  90. package/core/resolve/resolvableString.js +13 -0
  91. package/core/resolve/resolveData.d.ts +10 -0
  92. package/core/resolve/resolveData.js +162 -121
  93. package/core/resolve/stitch.d.ts +8 -0
  94. package/core/resolve/stitch.js +23 -21
  95. package/core/resolve/tgpuResolve.d.ts +55 -53
  96. package/core/resolve/tgpuResolve.js +106 -53
  97. package/core/root/configurableImpl.d.ts +10 -0
  98. package/core/root/configurableImpl.js +17 -19
  99. package/core/root/init.d.ts +76 -38
  100. package/core/root/init.js +346 -455
  101. package/core/root/rootTypes.d.ts +461 -636
  102. package/core/root/rootTypes.js +1 -0
  103. package/core/sampler/sampler.d.ts +50 -31
  104. package/core/sampler/sampler.js +120 -113
  105. package/core/simulate/tgpuSimulate.d.ts +9 -12
  106. package/core/simulate/tgpuSimulate.js +68 -71
  107. package/core/slot/accessor.d.ts +36 -13
  108. package/core/slot/accessor.js +138 -91
  109. package/core/slot/internalSlots.d.ts +2 -0
  110. package/core/slot/internalSlots.js +1 -6
  111. package/core/slot/lazy.d.ts +2 -6
  112. package/core/slot/lazy.js +71 -39
  113. package/core/slot/slot.d.ts +2 -6
  114. package/core/slot/slot.js +45 -38
  115. package/core/slot/slotTypes.d.ts +78 -80
  116. package/core/slot/slotTypes.js +11 -16
  117. package/core/texture/externalTexture.d.ts +20 -11
  118. package/core/texture/externalTexture.js +46 -46
  119. package/core/texture/texture.d.ts +152 -97
  120. package/core/texture/texture.js +407 -314
  121. package/core/texture/textureFormats.d.ts +42 -23
  122. package/core/texture/textureFormats.js +104 -75
  123. package/core/texture/textureProps.d.ts +7 -10
  124. package/core/texture/textureProps.js +1 -0
  125. package/core/texture/textureUtils.d.ts +8 -0
  126. package/core/texture/textureUtils.js +185 -179
  127. package/core/texture/usageExtension.d.ts +21 -18
  128. package/core/texture/usageExtension.js +13 -17
  129. package/core/unroll/tgpuUnroll.d.ts +20 -19
  130. package/core/unroll/tgpuUnroll.js +82 -91
  131. package/core/valueProxyUtils.d.ts +3 -0
  132. package/core/valueProxyUtils.js +52 -41
  133. package/core/variable/tgpuVariable.d.ts +26 -27
  134. package/core/variable/tgpuVariable.js +93 -96
  135. package/core/vertexLayout/connectAttributesToShader.d.ts +9 -0
  136. package/core/vertexLayout/connectAttributesToShader.js +61 -56
  137. package/core/vertexLayout/vertexAttribute.d.ts +21 -17
  138. package/core/vertexLayout/vertexAttribute.js +1 -0
  139. package/core/vertexLayout/vertexLayout.d.ts +24 -18
  140. package/core/vertexLayout/vertexLayout.js +130 -99
  141. package/core/whitespaces.d.ts +2 -0
  142. package/core/whitespaces.js +16 -0
  143. package/data/alignIO.d.ts +7 -0
  144. package/data/alignIO.js +13 -13
  145. package/data/alignmentOf.d.ts +5 -8
  146. package/data/alignmentOf.js +90 -75
  147. package/data/array.d.ts +6 -9
  148. package/data/array.js +48 -40
  149. package/data/atomic.d.ts +2 -7
  150. package/data/atomic.js +26 -23
  151. package/data/attributes.d.ts +19 -21
  152. package/data/attributes.js +192 -132
  153. package/data/autoStruct.d.ts +36 -3
  154. package/data/autoStruct.js +84 -81
  155. package/data/compiledIO.d.ts +5 -0
  156. package/data/compiledIO.js +231 -215
  157. package/data/dataIO.d.ts +13 -11
  158. package/data/dataIO.js +643 -589
  159. package/data/dataTypes.d.ts +83 -65
  160. package/data/dataTypes.js +66 -68
  161. package/data/deepEqual.d.ts +2 -7
  162. package/data/deepEqual.js +80 -55
  163. package/data/disarray.d.ts +6 -10
  164. package/data/disarray.js +52 -46
  165. package/data/float16Conversion.d.ts +4 -0
  166. package/data/float16Conversion.js +7 -0
  167. package/data/getLongestContiguousPrefix.d.ts +4 -8
  168. package/data/getLongestContiguousPrefix.js +6 -11
  169. package/data/index.d.ts +30 -31
  170. package/data/index.js +39 -172
  171. package/data/instanceToSchema.d.ts +24 -27
  172. package/data/instanceToSchema.js +1 -0
  173. package/data/isContiguous.d.ts +4 -8
  174. package/data/isContiguous.js +6 -11
  175. package/data/matrix.d.ts +21 -21
  176. package/data/matrix.js +513 -505
  177. package/data/numberOps.d.ts +6 -0
  178. package/data/numberOps.js +26 -20
  179. package/data/numeric.d.ts +21 -12
  180. package/data/numeric.js +287 -197
  181. package/data/offsetUtils.d.ts +9 -13
  182. package/data/offsetUtils.js +204 -144
  183. package/data/offsets.d.ts +8 -0
  184. package/data/offsets.js +33 -33
  185. package/data/partialIO.d.ts +13 -8
  186. package/data/partialIO.js +124 -113
  187. package/data/ptr.d.ts +12 -12
  188. package/data/ptr.js +42 -44
  189. package/data/ref.d.ts +40 -27
  190. package/data/ref.js +125 -95
  191. package/data/sampler.d.ts +99 -101
  192. package/data/sampler.js +17 -21
  193. package/data/schemaCallWrapper.d.ts +19 -0
  194. package/data/schemaCallWrapper.js +31 -26
  195. package/data/schemaMemoryLayout.d.ts +8 -0
  196. package/data/schemaMemoryLayout.js +213 -185
  197. package/data/sizeOf.d.ts +4 -8
  198. package/data/sizeOf.js +6 -11
  199. package/data/snippet.d.ts +96 -20
  200. package/data/snippet.js +75 -86
  201. package/data/struct.d.ts +4 -7
  202. package/data/struct.js +51 -39
  203. package/data/texture.d.ts +253 -250
  204. package/data/texture.js +238 -200
  205. package/data/unstruct.d.ts +2 -7
  206. package/data/unstruct.js +43 -37
  207. package/data/vector.d.ts +33 -21
  208. package/data/vector.js +234 -221
  209. package/data/vectorImpl.d.ts +231 -0
  210. package/data/vectorImpl.js +563 -515
  211. package/data/vectorOps.d.ts +63 -0
  212. package/data/vectorOps.js +642 -630
  213. package/data/vertexFormatData.d.ts +181 -184
  214. package/data/vertexFormatData.js +104 -106
  215. package/data/wgslTypes.d.ts +665 -600
  216. package/data/wgslTypes.js +220 -198
  217. package/errors.d.ts +50 -24
  218. package/errors.js +146 -126
  219. package/execMode.d.ts +16 -0
  220. package/execMode.js +47 -40
  221. package/extension.d.ts +13 -8
  222. package/extension.js +10 -16
  223. package/getGPUValue.d.ts +1 -0
  224. package/getGPUValue.js +2 -7
  225. package/index.d.ts +28 -68
  226. package/index.js +8 -28
  227. package/indexNamedExports.d.ts +69 -42
  228. package/indexNamedExports.js +25 -0
  229. package/internal.d.ts +16 -0
  230. package/internal.js +12 -0
  231. package/mathUtils.d.ts +5 -0
  232. package/mathUtils.js +7 -11
  233. package/memo.d.ts +11 -0
  234. package/memo.js +20 -22
  235. package/minify.d.ts +5 -0
  236. package/minify.js +93 -0
  237. package/nameUtils.d.ts +29 -0
  238. package/nameUtils.js +427 -394
  239. package/package.json +5 -1
  240. package/resolutionCtx.d.ts +162 -22
  241. package/resolutionCtx.js +911 -629
  242. package/serial/registry.d.ts +15 -0
  243. package/serial/registry.js +106 -0
  244. package/serial/restore.d.ts +49 -0
  245. package/serial/restore.js +68 -0
  246. package/serial/schema.d.ts +58 -0
  247. package/serial/schema.js +209 -0
  248. package/serial/types.d.ts +5 -0
  249. package/serial/types.js +1 -0
  250. package/shared/env.d.ts +9 -0
  251. package/shared/env.js +9 -12
  252. package/shared/generators.d.ts +4 -0
  253. package/shared/generators.js +10 -12
  254. package/shared/meta.d.ts +29 -14
  255. package/shared/meta.js +71 -55
  256. package/shared/normalizeMetadata.d.ts +32 -27
  257. package/shared/normalizeMetadata.js +23 -36
  258. package/shared/repr.d.ts +73 -55
  259. package/shared/repr.js +1 -0
  260. package/shared/soul.d.ts +17 -0
  261. package/shared/soul.js +1 -0
  262. package/shared/stringify.d.ts +2 -0
  263. package/shared/stringify.js +29 -20
  264. package/shared/symbols.d.ts +26 -20
  265. package/shared/symbols.js +79 -79
  266. package/shared/tseynit.d.ts +2 -0
  267. package/shared/tseynit.js +160 -75
  268. package/shared/utilityTypes.d.ts +30 -14
  269. package/shared/utilityTypes.js +2 -6
  270. package/shared/vertexFormat.d.ts +41 -43
  271. package/shared/vertexFormat.js +59 -62
  272. package/std/array.d.ts +2 -7
  273. package/std/array.js +18 -23
  274. package/std/atomic.d.ts +14 -18
  275. package/std/atomic.js +96 -95
  276. package/std/bitcast.d.ts +193 -10
  277. package/std/bitcast.js +309 -39
  278. package/std/boolean.d.ts +19 -33
  279. package/std/boolean.js +296 -288
  280. package/std/copy.d.ts +2 -7
  281. package/std/copy.js +27 -24
  282. package/std/derivative.d.ts +11 -15
  283. package/std/derivative.js +56 -79
  284. package/std/discard.d.ts +1 -6
  285. package/std/discard.js +7 -14
  286. package/std/environment.d.ts +19 -14
  287. package/std/environment.js +71 -51
  288. package/std/extensions.d.ts +2 -8
  289. package/std/extensions.js +10 -11
  290. package/std/index.d.ts +20 -24
  291. package/std/index.js +32 -187
  292. package/std/matrix.d.ts +6 -12
  293. package/std/matrix.js +60 -69
  294. package/std/numeric.d.ts +143 -146
  295. package/std/numeric.js +858 -749
  296. package/std/operators.d.ts +19 -27
  297. package/std/operators.js +227 -193
  298. package/std/packing.d.ts +5 -11
  299. package/std/packing.js +67 -75
  300. package/std/range.d.ts +6 -11
  301. package/std/range.js +48 -36
  302. package/std/subgroup.d.ts +33 -37
  303. package/std/subgroup.js +180 -217
  304. package/std/texture.d.ts +70 -38
  305. package/std/texture.js +176 -172
  306. package/taskQueue.d.ts +6 -0
  307. package/taskQueue.js +30 -0
  308. package/tgpu.d.ts +16 -0
  309. package/tgpu.js +17 -44
  310. package/tgpuBindGroupLayout.d.ts +132 -152
  311. package/tgpuBindGroupLayout.js +346 -268
  312. package/tgpuLogger.d.ts +34 -0
  313. package/tgpuLogger.js +63 -0
  314. package/tgpuUnstable.d.ts +16 -22
  315. package/tgpuUnstable.js +13 -35
  316. package/tgsl/accessIndex.d.ts +2 -0
  317. package/tgsl/accessIndex.js +76 -33
  318. package/tgsl/accessProp.d.ts +2 -0
  319. package/tgsl/accessProp.js +142 -101
  320. package/tgsl/accessStructProp.d.ts +5 -0
  321. package/tgsl/accessStructProp.js +13 -15
  322. package/tgsl/consoleLog/deserializers.d.ts +13 -0
  323. package/tgsl/consoleLog/deserializers.js +119 -103
  324. package/tgsl/consoleLog/logGenerator.d.ts +21 -0
  325. package/tgsl/consoleLog/logGenerator.js +85 -80
  326. package/tgsl/consoleLog/serializers.d.ts +21 -0
  327. package/tgsl/consoleLog/serializers.js +119 -100
  328. package/tgsl/consoleLog/types.d.ts +40 -39
  329. package/tgsl/consoleLog/types.js +1 -0
  330. package/tgsl/conversion.d.ts +33 -0
  331. package/tgsl/conversion.js +271 -216
  332. package/tgsl/forOfUtils.d.ts +15 -0
  333. package/tgsl/forOfUtils.js +85 -70
  334. package/tgsl/generationHelpers.d.ts +22 -39
  335. package/tgsl/generationHelpers.js +85 -58
  336. package/tgsl/infixDispatch.d.ts +70 -0
  337. package/tgsl/infixDispatch.js +48 -46
  338. package/tgsl/jsPolyfills.d.ts +16 -19
  339. package/tgsl/jsPolyfills.js +44 -42
  340. package/tgsl/makeDereferenceable.d.ts +48 -0
  341. package/tgsl/makeDereferenceable.js +86 -0
  342. package/tgsl/makeResolvable.d.ts +22 -0
  343. package/tgsl/makeResolvable.js +33 -0
  344. package/tgsl/shaderGenerator.d.ts +77 -17
  345. package/tgsl/shaderGenerator.js +1 -0
  346. package/tgsl/shellless.d.ts +6 -9
  347. package/tgsl/shellless.js +73 -43
  348. package/tgsl/wgslGenerator.d.ts +66 -59
  349. package/tgsl/wgslGenerator.js +1344 -760
  350. package/types.d.ts +287 -222
  351. package/types.js +61 -44
  352. package/unwrapper.d.ts +31 -26
  353. package/unwrapper.js +1 -0
  354. package/wgslExtensions.d.ts +3 -5
  355. package/wgslExtensions.js +12 -16
  356. package/_virtual/rolldown_runtime.js +0 -13
  357. package/core/buffer/bufferShorthand.d.ts +0 -50
  358. package/core/buffer/bufferShorthand.js +0 -55
  359. package/core/pipeline/applyPipelineState.js +0 -37
  360. package/package.js +0 -5
  361. package/tgsl/shaderGenerator_members.d.ts +0 -33
  362. package/tgsl/shaderGenerator_members.js +0 -12
package/data/matrix.js CHANGED
@@ -1,533 +1,541 @@
1
- import { $internal, $resolve } from "../shared/symbols.js";
2
- import { isVec } from "./wgslTypes.js";
3
- import { stitch } from "../core/resolve/stitch.js";
1
+ import { comptime } from "../core/function/comptime.js";
4
2
  import { callableSchema } from "../core/function/createCallableSchema.js";
5
- import { f32 } from "./numeric.js";
3
+ import { dualImpl } from "../core/function/dualImpl.js";
4
+ import { stitch } from "../core/resolve/stitch.js";
5
+ import { $repr } from "../shared/symbols.js";
6
+ import { $internal, $resolve } from "../shared/symbols.js";
6
7
  import { numericLiteralToSnippet } from "../tgsl/generationHelpers.js";
8
+ import { f32 } from "./numeric.js";
9
+ import {} from "./snippet.js";
7
10
  import { vec2f, vec3f, vec4f } from "./vector.js";
8
- import { dualImpl } from "../core/function/dualImpl.js";
9
- import { comptime } from "../core/function/comptime.js";
10
-
11
- //#region src/data/matrix.ts
12
- var MatBase = class {};
11
+ import { isVec, } from "./wgslTypes.js";
12
+ export class MatBase {
13
+ }
13
14
  function createMatSchema(options) {
14
- const construct = callableSchema({
15
- name: options.type,
16
- schema: () => schema,
17
- normalImpl: (...args) => {
18
- const elements = [];
19
- for (const arg of args) if (typeof arg === "number") elements.push(arg);
20
- else for (let i = 0; i < arg.length; ++i) elements.push(arg[i]);
21
- if (elements.length !== 0 && elements.length !== options.columns * options.rows) throw new Error(`'${options.type}' constructor called with invalid number of arguments.`);
22
- for (let i = elements.length; i < options.columns * options.rows; ++i) elements.push(0);
23
- return new options.MatImpl(...elements);
24
- },
25
- argTypes: (...args) => args.map((arg) => isVec(arg) ? arg : f32),
26
- codegenImpl: (ctx, args) => ctx.gen.typeInstantiation(schema, args)
27
- });
28
- const schema = Object.assign(construct, {
29
- [$internal]: {},
30
- type: options.type,
31
- primitive: f32,
32
- identity: identityFunctions[options.columns],
33
- translation: options.columns === 4 ? translation4 : void 0,
34
- scaling: options.columns === 4 ? scaling4 : void 0,
35
- rotationX: options.columns === 4 ? rotationX4 : void 0,
36
- rotationY: options.columns === 4 ? rotationY4 : void 0,
37
- rotationZ: options.columns === 4 ? rotationZ4 : void 0
38
- });
39
- options.MatImpl.prototype.schema = schema;
40
- return schema;
15
+ const construct = callableSchema({
16
+ name: options.type,
17
+ schema: () => schema,
18
+ normalImpl: (...args) => {
19
+ const elements = [];
20
+ for (const arg of args) {
21
+ if (typeof arg === 'number') {
22
+ elements.push(arg);
23
+ }
24
+ else {
25
+ for (let i = 0; i < arg.length; ++i) {
26
+ elements.push(arg[i]);
27
+ }
28
+ }
29
+ }
30
+ if (elements.length !== 0 && elements.length !== options.columns * options.rows) {
31
+ throw new Error(`'${options.type}' constructor called with invalid number of arguments.`);
32
+ }
33
+ for (let i = elements.length; i < options.columns * options.rows; ++i) {
34
+ elements.push(0);
35
+ }
36
+ return new options.MatImpl(...elements);
37
+ },
38
+ argTypes: (...args) => args.map((arg) => (isVec(arg) ? arg : f32)),
39
+ codegenImpl: (ctx, args) => ctx.gen.typeInstantiation(schema, args),
40
+ });
41
+ const schema = Object.assign(construct, {
42
+ [$internal]: {},
43
+ type: options.type,
44
+ primitive: f32,
45
+ identity: identityFunctions[options.columns],
46
+ translation: options.columns === 4 ? translation4 : undefined,
47
+ scaling: options.columns === 4 ? scaling4 : undefined,
48
+ rotationX: options.columns === 4 ? rotationX4 : undefined,
49
+ rotationY: options.columns === 4 ? rotationY4 : undefined,
50
+ rotationZ: options.columns === 4 ? rotationZ4 : undefined,
51
+ });
52
+ // TODO: Remove workaround
53
+ // it's a workaround for circular dependencies caused by us using schemas in the shader generator
54
+ options.MatImpl.prototype.schema = schema;
55
+ return schema;
56
+ }
57
+ const VALID_MAT2x2_ELEMENTS = [0, 1, 2, 3];
58
+ class mat2x2Impl extends MatBase {
59
+ [$internal] = true;
60
+ columns;
61
+ length = 4;
62
+ constructor(...elements) {
63
+ super();
64
+ this.columns = [
65
+ this.makeColumn(elements[0], elements[1]),
66
+ this.makeColumn(elements[2], elements[3]),
67
+ ];
68
+ }
69
+ get 0() {
70
+ return this.columns[0].x;
71
+ }
72
+ get 1() {
73
+ return this.columns[0].y;
74
+ }
75
+ get 2() {
76
+ return this.columns[1].x;
77
+ }
78
+ get 3() {
79
+ return this.columns[1].y;
80
+ }
81
+ set 0(value) {
82
+ this.columns[0].x = value;
83
+ }
84
+ set 1(value) {
85
+ this.columns[0].y = value;
86
+ }
87
+ set 2(value) {
88
+ this.columns[1].x = value;
89
+ }
90
+ set 3(value) {
91
+ this.columns[1].y = value;
92
+ }
93
+ *[Symbol.iterator]() {
94
+ yield this[0];
95
+ yield this[1];
96
+ yield this[2];
97
+ yield this[3];
98
+ }
99
+ [$resolve](ctx) {
100
+ return ctx.gen.typeInstantiation(mat2x2f,
101
+ // oxlint-disable-next-line typescript-eslint(no-non-null-assertion)
102
+ VALID_MAT2x2_ELEMENTS.map((i) => numericLiteralToSnippet(this[i])));
103
+ }
104
+ toString() {
105
+ return `${this.kind}(${VALID_MAT2x2_ELEMENTS.map((i) => this[i]).join(', ')})`;
106
+ }
107
+ }
108
+ class mat2x2fImpl extends mat2x2Impl {
109
+ kind = 'mat2x2f';
110
+ makeColumn(e0, e1) {
111
+ return vec2f(e0, e1);
112
+ }
113
+ }
114
+ const VALID_MAT3x3_ELEMENTS = [0, 1, 2, 4, 5, 6, 8, 9, 10];
115
+ class mat3x3Impl extends MatBase {
116
+ [$internal] = true;
117
+ columns;
118
+ length = 12;
119
+ constructor(...elements) {
120
+ super();
121
+ this.columns = [
122
+ this.makeColumn(elements[0], elements[1], elements[2]),
123
+ this.makeColumn(elements[3], elements[4], elements[5]),
124
+ this.makeColumn(elements[6], elements[7], elements[8]),
125
+ ];
126
+ }
127
+ get 0() {
128
+ return this.columns[0].x;
129
+ }
130
+ get 1() {
131
+ return this.columns[0].y;
132
+ }
133
+ get 2() {
134
+ return this.columns[0].z;
135
+ }
136
+ get 3() {
137
+ return 0;
138
+ }
139
+ get 4() {
140
+ return this.columns[1].x;
141
+ }
142
+ get 5() {
143
+ return this.columns[1].y;
144
+ }
145
+ get 6() {
146
+ return this.columns[1].z;
147
+ }
148
+ get 7() {
149
+ return 0;
150
+ }
151
+ get 8() {
152
+ return this.columns[2].x;
153
+ }
154
+ get 9() {
155
+ return this.columns[2].y;
156
+ }
157
+ get 10() {
158
+ return this.columns[2].z;
159
+ }
160
+ get 11() {
161
+ return 0;
162
+ }
163
+ set 0(value) {
164
+ this.columns[0].x = value;
165
+ }
166
+ set 1(value) {
167
+ this.columns[0].y = value;
168
+ }
169
+ set 2(value) {
170
+ this.columns[0].z = value;
171
+ }
172
+ set 3(_) { }
173
+ set 4(value) {
174
+ this.columns[1].x = value;
175
+ }
176
+ set 5(value) {
177
+ this.columns[1].y = value;
178
+ }
179
+ set 6(value) {
180
+ this.columns[1].z = value;
181
+ }
182
+ set 7(_) { }
183
+ set 8(value) {
184
+ this.columns[2].x = value;
185
+ }
186
+ set 9(value) {
187
+ this.columns[2].y = value;
188
+ }
189
+ set 10(value) {
190
+ this.columns[2].z = value;
191
+ }
192
+ set 11(_) { }
193
+ *[Symbol.iterator]() {
194
+ for (let i = 0; i < 12; i++) {
195
+ yield this[i];
196
+ }
197
+ }
198
+ [$resolve](ctx) {
199
+ return ctx.gen.typeInstantiation(mat3x3f,
200
+ // oxlint-disable-next-line typescript-eslint(no-non-null-assertion)
201
+ VALID_MAT3x3_ELEMENTS.map((i) => numericLiteralToSnippet(this[i])));
202
+ }
203
+ toString() {
204
+ return `${this.kind}(${VALID_MAT3x3_ELEMENTS.map((i) => this[i]).join(', ')})`;
205
+ }
206
+ }
207
+ class mat3x3fImpl extends mat3x3Impl {
208
+ kind = 'mat3x3f';
209
+ makeColumn(x, y, z) {
210
+ return vec3f(x, y, z);
211
+ }
41
212
  }
42
- const VALID_MAT2x2_ELEMENTS = [
43
- 0,
44
- 1,
45
- 2,
46
- 3
47
- ];
48
- var mat2x2Impl = class extends MatBase {
49
- [$internal] = true;
50
- columns;
51
- length = 4;
52
- constructor(...elements) {
53
- super();
54
- this.columns = [this.makeColumn(elements[0], elements[1]), this.makeColumn(elements[2], elements[3])];
55
- }
56
- get 0() {
57
- return this.columns[0].x;
58
- }
59
- get 1() {
60
- return this.columns[0].y;
61
- }
62
- get 2() {
63
- return this.columns[1].x;
64
- }
65
- get 3() {
66
- return this.columns[1].y;
67
- }
68
- set 0(value) {
69
- this.columns[0].x = value;
70
- }
71
- set 1(value) {
72
- this.columns[0].y = value;
73
- }
74
- set 2(value) {
75
- this.columns[1].x = value;
76
- }
77
- set 3(value) {
78
- this.columns[1].y = value;
79
- }
80
- *[Symbol.iterator]() {
81
- yield this[0];
82
- yield this[1];
83
- yield this[2];
84
- yield this[3];
85
- }
86
- [$resolve](ctx) {
87
- return ctx.gen.typeInstantiation(mat2x2f, VALID_MAT2x2_ELEMENTS.map((i) => numericLiteralToSnippet(this[i])));
88
- }
89
- toString() {
90
- return `${this.kind}(${VALID_MAT2x2_ELEMENTS.map((i) => this[i]).join(", ")})`;
91
- }
92
- };
93
- var mat2x2fImpl = class extends mat2x2Impl {
94
- kind = "mat2x2f";
95
- makeColumn(e0, e1) {
96
- return vec2f(e0, e1);
97
- }
98
- };
99
- const VALID_MAT3x3_ELEMENTS = [
100
- 0,
101
- 1,
102
- 2,
103
- 4,
104
- 5,
105
- 6,
106
- 8,
107
- 9,
108
- 10
109
- ];
110
- var mat3x3Impl = class extends MatBase {
111
- [$internal] = true;
112
- columns;
113
- length = 12;
114
- constructor(...elements) {
115
- super();
116
- this.columns = [
117
- this.makeColumn(elements[0], elements[1], elements[2]),
118
- this.makeColumn(elements[3], elements[4], elements[5]),
119
- this.makeColumn(elements[6], elements[7], elements[8])
120
- ];
121
- }
122
- get 0() {
123
- return this.columns[0].x;
124
- }
125
- get 1() {
126
- return this.columns[0].y;
127
- }
128
- get 2() {
129
- return this.columns[0].z;
130
- }
131
- get 3() {
132
- return 0;
133
- }
134
- get 4() {
135
- return this.columns[1].x;
136
- }
137
- get 5() {
138
- return this.columns[1].y;
139
- }
140
- get 6() {
141
- return this.columns[1].z;
142
- }
143
- get 7() {
144
- return 0;
145
- }
146
- get 8() {
147
- return this.columns[2].x;
148
- }
149
- get 9() {
150
- return this.columns[2].y;
151
- }
152
- get 10() {
153
- return this.columns[2].z;
154
- }
155
- get 11() {
156
- return 0;
157
- }
158
- set 0(value) {
159
- this.columns[0].x = value;
160
- }
161
- set 1(value) {
162
- this.columns[0].y = value;
163
- }
164
- set 2(value) {
165
- this.columns[0].z = value;
166
- }
167
- set 3(_) {}
168
- set 4(value) {
169
- this.columns[1].x = value;
170
- }
171
- set 5(value) {
172
- this.columns[1].y = value;
173
- }
174
- set 6(value) {
175
- this.columns[1].z = value;
176
- }
177
- set 7(_) {}
178
- set 8(value) {
179
- this.columns[2].x = value;
180
- }
181
- set 9(value) {
182
- this.columns[2].y = value;
183
- }
184
- set 10(value) {
185
- this.columns[2].z = value;
186
- }
187
- set 11(_) {}
188
- *[Symbol.iterator]() {
189
- for (let i = 0; i < 12; i++) yield this[i];
190
- }
191
- [$resolve](ctx) {
192
- return ctx.gen.typeInstantiation(mat3x3f, VALID_MAT3x3_ELEMENTS.map((i) => numericLiteralToSnippet(this[i])));
193
- }
194
- toString() {
195
- return `${this.kind}(${VALID_MAT3x3_ELEMENTS.map((i) => this[i]).join(", ")})`;
196
- }
197
- };
198
- var mat3x3fImpl = class extends mat3x3Impl {
199
- kind = "mat3x3f";
200
- makeColumn(x, y, z) {
201
- return vec3f(x, y, z);
202
- }
203
- };
204
213
  const VALID_MAT4x4_ELEMENTS = Array.from({ length: 16 }, (_, i) => i);
205
- var mat4x4Impl = class extends MatBase {
206
- [$internal] = true;
207
- columns;
208
- constructor(...elements) {
209
- super();
210
- this.columns = [
211
- this.makeColumn(elements[0], elements[1], elements[2], elements[3]),
212
- this.makeColumn(elements[4], elements[5], elements[6], elements[7]),
213
- this.makeColumn(elements[8], elements[9], elements[10], elements[11]),
214
- this.makeColumn(elements[12], elements[13], elements[14], elements[15])
215
- ];
216
- }
217
- length = 16;
218
- get 0() {
219
- return this.columns[0].x;
220
- }
221
- get 1() {
222
- return this.columns[0].y;
223
- }
224
- get 2() {
225
- return this.columns[0].z;
226
- }
227
- get 3() {
228
- return this.columns[0].w;
229
- }
230
- get 4() {
231
- return this.columns[1].x;
232
- }
233
- get 5() {
234
- return this.columns[1].y;
235
- }
236
- get 6() {
237
- return this.columns[1].z;
238
- }
239
- get 7() {
240
- return this.columns[1].w;
241
- }
242
- get 8() {
243
- return this.columns[2].x;
244
- }
245
- get 9() {
246
- return this.columns[2].y;
247
- }
248
- get 10() {
249
- return this.columns[2].z;
250
- }
251
- get 11() {
252
- return this.columns[2].w;
253
- }
254
- get 12() {
255
- return this.columns[3].x;
256
- }
257
- get 13() {
258
- return this.columns[3].y;
259
- }
260
- get 14() {
261
- return this.columns[3].z;
262
- }
263
- get 15() {
264
- return this.columns[3].w;
265
- }
266
- set 0(value) {
267
- this.columns[0].x = value;
268
- }
269
- set 1(value) {
270
- this.columns[0].y = value;
271
- }
272
- set 2(value) {
273
- this.columns[0].z = value;
274
- }
275
- set 3(value) {
276
- this.columns[0].w = value;
277
- }
278
- set 4(value) {
279
- this.columns[1].x = value;
280
- }
281
- set 5(value) {
282
- this.columns[1].y = value;
283
- }
284
- set 6(value) {
285
- this.columns[1].z = value;
286
- }
287
- set 7(value) {
288
- this.columns[1].w = value;
289
- }
290
- set 8(value) {
291
- this.columns[2].x = value;
292
- }
293
- set 9(value) {
294
- this.columns[2].y = value;
295
- }
296
- set 10(value) {
297
- this.columns[2].z = value;
298
- }
299
- set 11(value) {
300
- this.columns[2].w = value;
301
- }
302
- set 12(value) {
303
- this.columns[3].x = value;
304
- }
305
- set 13(value) {
306
- this.columns[3].y = value;
307
- }
308
- set 14(value) {
309
- this.columns[3].z = value;
310
- }
311
- set 15(value) {
312
- this.columns[3].w = value;
313
- }
314
- *[Symbol.iterator]() {
315
- for (let i = 0; i < 16; i++) yield this[i];
316
- }
317
- [$resolve](ctx) {
318
- return ctx.gen.typeInstantiation(mat4x4f, VALID_MAT4x4_ELEMENTS.map((i) => numericLiteralToSnippet(this[i])));
319
- }
320
- toString() {
321
- return `${this.kind}(${VALID_MAT4x4_ELEMENTS.map((i) => this[i]).join(", ")})`;
322
- }
323
- };
324
- var mat4x4fImpl = class extends mat4x4Impl {
325
- kind = "mat4x4f";
326
- makeColumn(x, y, z, w) {
327
- return vec4f(x, y, z, w);
328
- }
329
- };
214
+ class mat4x4Impl extends MatBase {
215
+ [$internal] = true;
216
+ columns;
217
+ constructor(...elements) {
218
+ super();
219
+ this.columns = [
220
+ this.makeColumn(elements[0], elements[1], elements[2], elements[3]),
221
+ this.makeColumn(elements[4], elements[5], elements[6], elements[7]),
222
+ this.makeColumn(elements[8], elements[9], elements[10], elements[11]),
223
+ this.makeColumn(elements[12], elements[13], elements[14], elements[15]),
224
+ ];
225
+ }
226
+ length = 16;
227
+ get 0() {
228
+ return this.columns[0].x;
229
+ }
230
+ get 1() {
231
+ return this.columns[0].y;
232
+ }
233
+ get 2() {
234
+ return this.columns[0].z;
235
+ }
236
+ get 3() {
237
+ return this.columns[0].w;
238
+ }
239
+ get 4() {
240
+ return this.columns[1].x;
241
+ }
242
+ get 5() {
243
+ return this.columns[1].y;
244
+ }
245
+ get 6() {
246
+ return this.columns[1].z;
247
+ }
248
+ get 7() {
249
+ return this.columns[1].w;
250
+ }
251
+ get 8() {
252
+ return this.columns[2].x;
253
+ }
254
+ get 9() {
255
+ return this.columns[2].y;
256
+ }
257
+ get 10() {
258
+ return this.columns[2].z;
259
+ }
260
+ get 11() {
261
+ return this.columns[2].w;
262
+ }
263
+ get 12() {
264
+ return this.columns[3].x;
265
+ }
266
+ get 13() {
267
+ return this.columns[3].y;
268
+ }
269
+ get 14() {
270
+ return this.columns[3].z;
271
+ }
272
+ get 15() {
273
+ return this.columns[3].w;
274
+ }
275
+ set 0(value) {
276
+ this.columns[0].x = value;
277
+ }
278
+ set 1(value) {
279
+ this.columns[0].y = value;
280
+ }
281
+ set 2(value) {
282
+ this.columns[0].z = value;
283
+ }
284
+ set 3(value) {
285
+ this.columns[0].w = value;
286
+ }
287
+ set 4(value) {
288
+ this.columns[1].x = value;
289
+ }
290
+ set 5(value) {
291
+ this.columns[1].y = value;
292
+ }
293
+ set 6(value) {
294
+ this.columns[1].z = value;
295
+ }
296
+ set 7(value) {
297
+ this.columns[1].w = value;
298
+ }
299
+ set 8(value) {
300
+ this.columns[2].x = value;
301
+ }
302
+ set 9(value) {
303
+ this.columns[2].y = value;
304
+ }
305
+ set 10(value) {
306
+ this.columns[2].z = value;
307
+ }
308
+ set 11(value) {
309
+ this.columns[2].w = value;
310
+ }
311
+ set 12(value) {
312
+ this.columns[3].x = value;
313
+ }
314
+ set 13(value) {
315
+ this.columns[3].y = value;
316
+ }
317
+ set 14(value) {
318
+ this.columns[3].z = value;
319
+ }
320
+ set 15(value) {
321
+ this.columns[3].w = value;
322
+ }
323
+ *[Symbol.iterator]() {
324
+ for (let i = 0; i < 16; i++) {
325
+ yield this[i];
326
+ }
327
+ }
328
+ [$resolve](ctx) {
329
+ return ctx.gen.typeInstantiation(mat4x4f,
330
+ // oxlint-disable-next-line typescript-eslint(no-non-null-assertion)
331
+ VALID_MAT4x4_ELEMENTS.map((i) => numericLiteralToSnippet(this[i])));
332
+ }
333
+ toString() {
334
+ return `${this.kind}(${VALID_MAT4x4_ELEMENTS.map((i) => this[i]).join(', ')})`;
335
+ }
336
+ }
337
+ class mat4x4fImpl extends mat4x4Impl {
338
+ kind = 'mat4x4f';
339
+ makeColumn(x, y, z, w) {
340
+ return vec4f(x, y, z, w);
341
+ }
342
+ }
343
+ // ----------
344
+ // Matrix ops
345
+ // ----------
330
346
  /**
331
- * Returns a 2-by-2 identity matrix.
332
- * @returns {m2x2f} The result matrix.
333
- */
334
- const identity2 = comptime(() => mat2x2f(1, 0, 0, 1)).$name("identity2");
347
+ * Returns a 2-by-2 identity matrix.
348
+ * @returns {m2x2f} The result matrix.
349
+ */
350
+ export const identity2 = comptime(() => mat2x2f(1, 0, 0, 1)).$name('identity2');
335
351
  /**
336
- * Returns a 3-by-3 identity matrix.
337
- * @returns {m3x3f} The result matrix.
338
- */
339
- const identity3 = comptime(() => mat3x3f(1, 0, 0, 0, 1, 0, 0, 0, 1)).$name("identity3");
352
+ * Returns a 3-by-3 identity matrix.
353
+ * @returns {m3x3f} The result matrix.
354
+ */
355
+ export const identity3 = comptime(() => mat3x3f(1, 0, 0, 0, 1, 0, 0, 0, 1)).$name('identity3');
340
356
  /**
341
- * Returns a 4-by-4 identity matrix.
342
- * @returns {m4x4f} The result matrix.
343
- */
344
- const identity4 = comptime(() => mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)).$name("identity4");
357
+ * Returns a 4-by-4 identity matrix.
358
+ * @returns {m4x4f} The result matrix.
359
+ */
360
+ export const identity4 = comptime(() => mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)).$name('identity4');
345
361
  const identityFunctions = {
346
- 2: identity2,
347
- 3: identity3,
348
- 4: identity4
362
+ 2: identity2,
363
+ 3: identity3,
364
+ 4: identity4,
349
365
  };
350
366
  /**
351
- * Creates a 4-by-4 matrix which translates by the given vector v.
352
- * @param {v3f} vector - The vector by which to translate.
353
- * @returns {m4x4f} The translation matrix.
354
- */
355
- const translation4 = dualImpl({
356
- name: "translation4",
357
- normalImpl: (vector) => mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, vector.x, vector.y, vector.z, 1),
358
- get signature() {
359
- return {
360
- argTypes: [vec3f],
361
- returnType: mat4x4f
362
- };
363
- },
364
- codegenImpl: (_ctx, [v]) => stitch`mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, ${v}.x, ${v}.y, ${v}.z, 1)`
367
+ * Creates a 4-by-4 matrix which translates by the given vector v.
368
+ * @param {v3f} vector - The vector by which to translate.
369
+ * @returns {m4x4f} The translation matrix.
370
+ */
371
+ export const translation4 = dualImpl({
372
+ name: 'translation4',
373
+ normalImpl: (vector) =>
374
+ // oxfmt-ignore
375
+ mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, vector.x, vector.y, vector.z, 1),
376
+ get signature() {
377
+ return { argTypes: [vec3f], returnType: mat4x4f };
378
+ },
379
+ codegenImpl: (_ctx, [v]) => stitch `mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, ${v}.x, ${v}.y, ${v}.z, 1)`,
380
+ sideEffects: false,
365
381
  });
366
382
  /**
367
- * Creates a 4-by-4 matrix which scales in each dimension by an amount given by the corresponding entry in the given vector.
368
- * @param {v3f} vector - A vector of three entries specifying the factor by which to scale in each dimension.
369
- * @returns {m4x4f} The scaling matrix.
370
- */
371
- const scaling4 = dualImpl({
372
- name: "scaling4",
373
- normalImpl: (vector) => mat4x4f(vector.x, 0, 0, 0, 0, vector.y, 0, 0, 0, 0, vector.z, 0, 0, 0, 0, 1),
374
- get signature() {
375
- return {
376
- argTypes: [vec3f],
377
- returnType: mat4x4f
378
- };
379
- },
380
- codegenImpl: (_ctx, [v]) => stitch`mat4x4f(${v}.x, 0, 0, 0, 0, ${v}.y, 0, 0, 0, 0, ${v}.z, 0, 0, 0, 0, 1)`
383
+ * Creates a 4-by-4 matrix which scales in each dimension by an amount given by the corresponding entry in the given vector.
384
+ * @param {v3f} vector - A vector of three entries specifying the factor by which to scale in each dimension.
385
+ * @returns {m4x4f} The scaling matrix.
386
+ */
387
+ export const scaling4 = dualImpl({
388
+ name: 'scaling4',
389
+ normalImpl: (vector) =>
390
+ // oxfmt-ignore
391
+ mat4x4f(vector.x, 0, 0, 0, 0, vector.y, 0, 0, 0, 0, vector.z, 0, 0, 0, 0, 1),
392
+ get signature() {
393
+ return { argTypes: [vec3f], returnType: mat4x4f };
394
+ },
395
+ codegenImpl: (_ctx, [v]) => stitch `mat4x4f(${v}.x, 0, 0, 0, 0, ${v}.y, 0, 0, 0, 0, ${v}.z, 0, 0, 0, 0, 1)`,
396
+ sideEffects: false,
381
397
  });
382
398
  /**
383
- * Creates a 4-by-4 matrix which rotates around the x-axis by the given angle.
384
- * @param {number} angle - The angle by which to rotate (in radians).
385
- * @returns {m4x4f} The rotation matrix.
386
- */
387
- const rotationX4 = dualImpl({
388
- name: "rotationX4",
389
- normalImpl: (a) => mat4x4f(1, 0, 0, 0, 0, Math.cos(a), Math.sin(a), 0, 0, -Math.sin(a), Math.cos(a), 0, 0, 0, 0, 1),
390
- get signature() {
391
- return {
392
- argTypes: [f32],
393
- returnType: mat4x4f
394
- };
395
- },
396
- codegenImpl: (_ctx, [a]) => stitch`mat4x4f(1, 0, 0, 0, 0, cos(${a}), sin(${a}), 0, 0, -sin(${a}), cos(${a}), 0, 0, 0, 0, 1)`
399
+ * Creates a 4-by-4 matrix which rotates around the x-axis by the given angle.
400
+ * @param {number} angle - The angle by which to rotate (in radians).
401
+ * @returns {m4x4f} The rotation matrix.
402
+ */
403
+ export const rotationX4 = dualImpl({
404
+ name: 'rotationX4',
405
+ normalImpl: (a) =>
406
+ // oxfmt-ignore
407
+ mat4x4f(1, 0, 0, 0, 0, Math.cos(a), Math.sin(a), 0, 0, -Math.sin(a), Math.cos(a), 0, 0, 0, 0, 1),
408
+ get signature() {
409
+ return { argTypes: [f32], returnType: mat4x4f };
410
+ },
411
+ codegenImpl: (_ctx, [a]) => stitch `mat4x4f(1, 0, 0, 0, 0, cos(${a}), sin(${a}), 0, 0, -sin(${a}), cos(${a}), 0, 0, 0, 0, 1)`,
412
+ sideEffects: false,
397
413
  });
398
414
  /**
399
- * Creates a 4-by-4 matrix which rotates around the y-axis by the given angle.
400
- * @param {number} angle - The angle by which to rotate (in radians).
401
- * @returns {m4x4f} The rotation matrix.
402
- */
403
- const rotationY4 = dualImpl({
404
- name: "rotationY4",
405
- normalImpl: (a) => mat4x4f(Math.cos(a), 0, -Math.sin(a), 0, 0, 1, 0, 0, Math.sin(a), 0, Math.cos(a), 0, 0, 0, 0, 1),
406
- get signature() {
407
- return {
408
- argTypes: [f32],
409
- returnType: mat4x4f
410
- };
411
- },
412
- codegenImpl: (_ctx, [a]) => stitch`mat4x4f(cos(${a}), 0, -sin(${a}), 0, 0, 1, 0, 0, sin(${a}), 0, cos(${a}), 0, 0, 0, 0, 1)`
415
+ * Creates a 4-by-4 matrix which rotates around the y-axis by the given angle.
416
+ * @param {number} angle - The angle by which to rotate (in radians).
417
+ * @returns {m4x4f} The rotation matrix.
418
+ */
419
+ export const rotationY4 = dualImpl({
420
+ name: 'rotationY4',
421
+ normalImpl: (a) =>
422
+ // oxfmt-ignore
423
+ mat4x4f(Math.cos(a), 0, -Math.sin(a), 0, 0, 1, 0, 0, Math.sin(a), 0, Math.cos(a), 0, 0, 0, 0, 1),
424
+ get signature() {
425
+ return { argTypes: [f32], returnType: mat4x4f };
426
+ },
427
+ codegenImpl: (_ctx, [a]) => stitch `mat4x4f(cos(${a}), 0, -sin(${a}), 0, 0, 1, 0, 0, sin(${a}), 0, cos(${a}), 0, 0, 0, 0, 1)`,
428
+ sideEffects: false,
413
429
  });
414
430
  /**
415
- * Creates a 4-by-4 matrix which rotates around the z-axis by the given angle.
416
- * @param {number} angle - The angle by which to rotate (in radians).
417
- * @returns {m4x4f} The rotation matrix.
418
- */
419
- const rotationZ4 = dualImpl({
420
- name: "rotationZ4",
421
- normalImpl: (a) => mat4x4f(Math.cos(a), Math.sin(a), 0, 0, -Math.sin(a), Math.cos(a), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1),
422
- get signature() {
423
- return {
424
- argTypes: [f32],
425
- returnType: mat4x4f
426
- };
427
- },
428
- codegenImpl: (_ctx, [a]) => stitch`mat4x4f(cos(${a}), sin(${a}), 0, 0, -sin(${a}), cos(${a}), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)`
431
+ * Creates a 4-by-4 matrix which rotates around the z-axis by the given angle.
432
+ * @param {number} angle - The angle by which to rotate (in radians).
433
+ * @returns {m4x4f} The rotation matrix.
434
+ */
435
+ export const rotationZ4 = dualImpl({
436
+ name: 'rotationZ4',
437
+ normalImpl: (a) =>
438
+ // oxfmt-ignore
439
+ mat4x4f(Math.cos(a), Math.sin(a), 0, 0, -Math.sin(a), Math.cos(a), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1),
440
+ get signature() {
441
+ return { argTypes: [f32], returnType: mat4x4f };
442
+ },
443
+ codegenImpl: (_ctx, [a]) => stitch `mat4x4f(cos(${a}), sin(${a}), 0, 0, -sin(${a}), cos(${a}), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)`,
444
+ sideEffects: false,
429
445
  });
446
+ // ----------
447
+ // Public API
448
+ // ----------
430
449
  /**
431
- * Schema representing mat2x2f - a matrix with 2 rows and 2 columns, with elements of type f32.
432
- * Also a constructor function for this matrix type.
433
- *
434
- * @example
435
- * const zero2x2 = mat2x2f(); // filled with zeros
436
- *
437
- * @example
438
- * const mat = mat2x2f(0, 1, 2, 3);
439
- * mat.columns[0] // vec2f(0, 1)
440
- * mat.columns[1] // vec2f(2, 3)
441
- *
442
- * @example
443
- * const mat = mat2x2f(
444
- * vec2f(0, 1), // column 0
445
- * vec2f(1, 2), // column 1
446
- * );
447
- *
448
- * @example
449
- * const buffer = root.createBuffer(d.mat2x2f, d.mat2x2f(0, 1, 2, 3)); // buffer holding a d.mat2x2f value, with an initial value of ((0, 1), (2, 3))
450
- */
451
- const mat2x2f = createMatSchema({
452
- type: "mat2x2f",
453
- rows: 2,
454
- columns: 2,
455
- MatImpl: mat2x2fImpl
450
+ * Schema representing mat2x2f - a matrix with 2 rows and 2 columns, with elements of type f32.
451
+ * Also a constructor function for this matrix type.
452
+ *
453
+ * @example
454
+ * const zero2x2 = mat2x2f(); // filled with zeros
455
+ *
456
+ * @example
457
+ * const mat = mat2x2f(0, 1, 2, 3);
458
+ * mat.columns[0] // vec2f(0, 1)
459
+ * mat.columns[1] // vec2f(2, 3)
460
+ *
461
+ * @example
462
+ * const mat = mat2x2f(
463
+ * vec2f(0, 1), // column 0
464
+ * vec2f(1, 2), // column 1
465
+ * );
466
+ *
467
+ * @example
468
+ * const buffer = root.createBuffer(d.mat2x2f, d.mat2x2f(0, 1, 2, 3)); // buffer holding a d.mat2x2f value, with an initial value of ((0, 1), (2, 3))
469
+ */
470
+ export const mat2x2f = createMatSchema({
471
+ type: 'mat2x2f',
472
+ rows: 2,
473
+ columns: 2,
474
+ MatImpl: mat2x2fImpl,
456
475
  });
457
476
  /**
458
- * Schema representing mat3x3f - a matrix with 3 rows and 3 columns, with elements of type f32.
459
- * Also a constructor function for this matrix type.
460
- *
461
- * @example
462
- * const zero3x3 = mat3x3f(); // filled with zeros
463
- *
464
- * @example
465
- * const mat = mat3x3f(0, 1, 2, 3, 4, 5, 6, 7, 8);
466
- * mat.columns[0] // vec3f(0, 1, 2)
467
- * mat.columns[1] // vec3f(3, 4, 5)
468
- * mat.columns[2] // vec3f(6, 7, 8)
469
- *
470
- * @example
471
- * const mat = mat3x3f(
472
- * vec3f(0, 1, 2), // column 0
473
- * vec3f(2, 3, 4), // column 1
474
- * vec3f(5, 6, 7), // column 2
475
- * );
476
- *
477
- * @example
478
- * const buffer = root.createBuffer(d.mat3x3f, d.mat3x3f()); // buffer holding a d.mat3x3f value, with an initial value of mat3x3f filled with zeros
479
- */
480
- const mat3x3f = createMatSchema({
481
- type: "mat3x3f",
482
- rows: 3,
483
- columns: 3,
484
- MatImpl: mat3x3fImpl
477
+ * Schema representing mat3x3f - a matrix with 3 rows and 3 columns, with elements of type f32.
478
+ * Also a constructor function for this matrix type.
479
+ *
480
+ * @example
481
+ * const zero3x3 = mat3x3f(); // filled with zeros
482
+ *
483
+ * @example
484
+ * const mat = mat3x3f(0, 1, 2, 3, 4, 5, 6, 7, 8);
485
+ * mat.columns[0] // vec3f(0, 1, 2)
486
+ * mat.columns[1] // vec3f(3, 4, 5)
487
+ * mat.columns[2] // vec3f(6, 7, 8)
488
+ *
489
+ * @example
490
+ * const mat = mat3x3f(
491
+ * vec3f(0, 1, 2), // column 0
492
+ * vec3f(2, 3, 4), // column 1
493
+ * vec3f(5, 6, 7), // column 2
494
+ * );
495
+ *
496
+ * @example
497
+ * const buffer = root.createBuffer(d.mat3x3f, d.mat3x3f()); // buffer holding a d.mat3x3f value, with an initial value of mat3x3f filled with zeros
498
+ */
499
+ export const mat3x3f = createMatSchema({
500
+ type: 'mat3x3f',
501
+ rows: 3,
502
+ columns: 3,
503
+ MatImpl: mat3x3fImpl,
485
504
  });
486
505
  /**
487
- * Schema representing mat4x4f - a matrix with 4 rows and 4 columns, with elements of type f32.
488
- * Also a constructor function for this matrix type.
489
- *
490
- * @example
491
- * const zero4x4 = mat4x4f(); // filled with zeros
492
- *
493
- * @example
494
- * const mat = mat4x4f(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
495
- * mat.columns[0] // vec4f(0, 1, 2, 3)
496
- * mat.columns[1] // vec4f(4, 5, 6, 7)
497
- * mat.columns[2] // vec4f(8, 9, 10, 11)
498
- * mat.columns[3] // vec4f(12, 13, 14, 15)
499
- *
500
- * @example
501
- * const mat = mat4x4f(
502
- * vec4f(0, 1, 2, 3), // column 0
503
- * vec4f(4, 5, 6, 7), // column 1
504
- * vec4f(8, 9, 10, 11), // column 2
505
- * vec4f(12, 13, 14, 15), // column 3
506
- * );
507
- *
508
- * @example
509
- * const buffer = root.createBuffer(d.mat4x4f, d.mat4x4f()); // buffer holding a d.mat4x4f value, with an initial value of mat4x4f filled with zeros
510
- */
511
- const mat4x4f = createMatSchema({
512
- type: "mat4x4f",
513
- rows: 4,
514
- columns: 4,
515
- MatImpl: mat4x4fImpl
506
+ * Schema representing mat4x4f - a matrix with 4 rows and 4 columns, with elements of type f32.
507
+ * Also a constructor function for this matrix type.
508
+ *
509
+ * @example
510
+ * const zero4x4 = mat4x4f(); // filled with zeros
511
+ *
512
+ * @example
513
+ * const mat = mat4x4f(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
514
+ * mat.columns[0] // vec4f(0, 1, 2, 3)
515
+ * mat.columns[1] // vec4f(4, 5, 6, 7)
516
+ * mat.columns[2] // vec4f(8, 9, 10, 11)
517
+ * mat.columns[3] // vec4f(12, 13, 14, 15)
518
+ *
519
+ * @example
520
+ * const mat = mat4x4f(
521
+ * vec4f(0, 1, 2, 3), // column 0
522
+ * vec4f(4, 5, 6, 7), // column 1
523
+ * vec4f(8, 9, 10, 11), // column 2
524
+ * vec4f(12, 13, 14, 15), // column 3
525
+ * );
526
+ *
527
+ * @example
528
+ * const buffer = root.createBuffer(d.mat4x4f, d.mat4x4f()); // buffer holding a d.mat4x4f value, with an initial value of mat4x4f filled with zeros
529
+ */
530
+ export const mat4x4f = createMatSchema({
531
+ type: 'mat4x4f',
532
+ rows: 4,
533
+ columns: 4,
534
+ MatImpl: mat4x4fImpl,
516
535
  });
517
- function matToArray(mat) {
518
- if (mat.kind === "mat3x3f") return [
519
- mat[0],
520
- mat[1],
521
- mat[2],
522
- mat[4],
523
- mat[5],
524
- mat[6],
525
- mat[8],
526
- mat[9],
527
- mat[10]
528
- ];
529
- return Array.from({ length: mat.length }).map((_, idx) => mat[idx]);
536
+ export function matToArray(mat) {
537
+ if (mat.kind === 'mat3x3f') {
538
+ return [mat[0], mat[1], mat[2], mat[4], mat[5], mat[6], mat[8], mat[9], mat[10]];
539
+ }
540
+ return Array.from({ length: mat.length }).map((_, idx) => mat[idx]);
530
541
  }
531
-
532
- //#endregion
533
- export { MatBase, identity2, identity3, identity4, mat2x2f, mat3x3f, mat4x4f, matToArray, rotationX4, rotationY4, rotationZ4, scaling4, translation4 };