add primitives for vertical- and horizontal-symmetry#1862
Conversation
…ibrary due to performance reasons). Claude Sonnet 4.6 and Gemini 3.1 Thinking did the heavy lifting.
|
Most of the delta here is gratuitous (and inconsistent) whitespace changes - could you revert those, so that we can focus on just the interesting part? Naming-wise, I think the names are inconsistent -- everything else has an Also, the names are inconsistent with the other horizontal and vertical names: if |
…in the library due to performance reasons). Claude Sonnet 4.6 and Gemini 3.1 Thinking did the heavy lifting." This reverts commit 9a467e4.
|
@blerner fixed the whitespace issue. Major disagreement with you about the naming, but that will be inefficient to do over text. Maybe we can chat? |
| for (var x = 0; x < halfW; x++) { | ||
| var i1 = (y * width + x) * 4; | ||
| var i2 = (y * width + (width - 1 - x)) * 4; | ||
| for (var ch = 0; ch < 4; ch++) { |
There was a problem hiding this comment.
What is the actual similarity formula being used in these two functions? I think, if I'm understanding correctly, that it's the root mean-squared error over every pixel and every color channel? Probably worth a clarifying comment somewhere...
| for (var y = 0; y < height; y++) { | ||
| for (var x = 0; x < halfW; x++) { | ||
| var i1 = (y * width + x) * 4; | ||
| var i2 = (y * width + (width - 1 - x)) * 4; |
There was a problem hiding this comment.
I hate magic formulas like these :( Though I do understand it, I kinda wish we had
const getPixel(data, x, y, channel) => data[((y * width) + x) * 4 + channel];
And then you'd have var d = getPixel(data, x, y, ch) - getPixel(data, width - 1 - x, y, ch), which to me reads a lot more cleanly. OTOH, you're writing this in raw JS because of performance, so you could do
const basePixelIndex(x, y) => ((y * width) + x) * 4;
and then have
var i1 = basePixelIndex(x, y);
var i2 = basePixelIndex(width - 1 - x, y);
which saves two whole multiplications per loop ;-)
|
Those changes look good; I'll double-check them with Joe the next time we meet, and we'll get this merged soon. |
|
Good discussion good feature. @blerner and I had some good experiments just now. I think we can use So you can do this with: The extra roughnum and the We should fix We can add |
…explicitly ask for 0-255 ranges for rgb and a Relevant for #1862
add primitives for vertical- and horizontal-symmetry (needed in the library due to performance reasons). Claude Sonnet 4.6 and Gemini 3.1 Thinking did the heavy lifting.