support map() inside p5.strands shaders#8753
support map() inside p5.strands shaders#8753Nixxx19 wants to merge 2 commits intoprocessing:dev-2.0from
Conversation
davepagurek
left a comment
There was a problem hiding this comment.
Thanks, this is looking good! Do you think we could add some unit tests that map from one range to a different range to test the math? Possibly a visual test that maps the texture coordinate to something?
| const start1Node = p5.strandsNode(start1); | ||
| const stop1Node = p5.strandsNode(stop1); | ||
| const t = nNode.sub(start1Node).div(stop1Node.sub(start1Node)); | ||
| const result = fn.mix(start2, stop2, t); |
There was a problem hiding this comment.
I think this doesn't make a difference here since this part of the code happens just while the strands context isn't active, but maybe let's use this. instead of fn. to better match expected usage, since the intention is for these functions to not be called statically.
There was a problem hiding this comment.
thanks for the review @davepagurek!
swapped fn. to this. for mix/clamp/min/max in strands_api.js. you're right that it doesn't change behavior here but it's nicer to keep consistent with the rest of the file (like getTexture).
also added a few more tests in p5.Shader.js since the original two were both identity mappings (0..1 to 0..1), so they weren't really exercising the math:
- range shrink: map(5, 0, 10, 0, 1) -> 0.5
- offset output: map(0.5, 0, 1, 0.2, 0.8) -> 0.5 mapped to 128
- negative input range: map(0, -1, 1, 0, 1) -> 0.5
- a horizontal gradient test that pipes inputs.texCoord.x through map() and checks left/middle/right pixels (covers the visual side you mentioned)
all 6 pass locally with vitest. lmk if you want anything else changed!
Continuous ReleaseCDN linkPublished PackagesCommit hash: 2f7206c Previous deploymentsThis is an automated message. |
Resolves #8750
Summary
Tests
PR Checklist