Closed Ignotus-mago closed 4 months ago
In fact, let's code all plant and pluck methods to use signalPos
as an argument instead of x
and y
. These methods all follow the signal path in reading or writing sample or pixel values.
Similarly, all peel and stamp methods should use x
and y
as arguments, rather than a position in the pixel array. These methods follow the image path in reading or writing sample or pixel values.
Pluck and plant methods have been refactored to use signalPos
exclusively. All stamp and peel methods already used x
and y
arguments.
We can close this issue, but should open another one about error handling when signalPos + length > img.length
in any method.
If "pluck" and "plant" methods only follow the signal array, then they don't need a version with "x" and "y", which are immediately used to calculate signal position and used in the rest of the method. Methods with "x" and "y" in the signature are redundant.
They are also more error prone: if
signalPos + length > img.length
in any method, we'll throw a gratuitous array out of bound error, all because we didn't calculate signal position and check it in the caller's code. The caller's code is probably where we should check this, though we could contemplate a fix in the library code.This will require several edits to example code, but it's early enough in development to do that.