Repository navigation
Support ** in p5.strands and error on unsupported operators - #9375
davepagurek merged 4 commits into
Conversation
| }).not.toThrow(); | ||
| }); | ||
|
|
||
| suite('exponentiation operator (#9252)', () => { |
There was a problem hiding this comment.
It's probably not super important to put the PR number here; the idea is to have the code be understandable to other contributors without extra context from github.
There was a problem hiding this comment.
Makes sense, I'll drop it.
| myp5.background(0); | ||
| myp5.filter(testShader); | ||
| const c = myp5.get(25, 25); | ||
| assert.approximately(c[0], 64, 5); // 0.5 ** 2 = 0.25 -> ~64 |
There was a problem hiding this comment.
For completeness, can we add similar tests to the webgpu module too?
There was a problem hiding this comment.
Sure, adding them now.
There was a problem hiding this comment.
Added in a29df88, same three cases using the material shader pattern, since filter shader tests are still todo on WebGPU.
| }); | ||
|
|
||
|
|
||
| suite('exponentiation operator', () => { |
There was a problem hiding this comment.
minor, but it looks like indentation is off here
davepagurek
left a comment
There was a problem hiding this comment.
Cool, looks good to go!
Resolves #9252
Changes:
replaceBinaryOperator(src/strands/strands_transpiler.js) now maps**topow, soa ** bbecomesa.pow(b). This also covers**=, since compound assignments go through the same function.StrandsNode.prototype.pow(src/strands/strands_api.js), which builds apow()function call node rather than a binary operator, since GLSL and WGSL have no**operator. This resolves the TODO.defaultcase that throws a strands error naming the operator (e.g.&,<<), instead of crashing with.undefined is not a function/reading 'startsWith'inside the transpiler. This was the second option in the issue; happy to drop it into a separate PR if you'd rather keep this one to**only.Tests (new
exponentiation operator (#9252)suite intest/unit/webgl/p5.Shader.js):v ** 2renders the same aspow(v, 2)v **= 2worksunsupported operatorAll three failed before the source change and pass after. The change is in the backend-independent transpiler, so I only added WebGL tests; happy to add WebGPU ones too.
npx vitest run: everything passes excepttest/unit/webgpu/p5.Shader.js→ "handle passing a value from a vertex hook to a fragment hook with swizzle assignment", which also fails on a cleanmain.PR Checklist
npm run lintpasses