the 1st approach was to throw an error when outside the grid canvas but that caused multiple errors when using auto-scroll (which is normal to fall outside the canvas to let the auto-scroll do its job). So to avoid all these errors, I opted with -1 instead when outside the canvas.
So why not use return null? That would require too much refactoring and potentially bring a breaking change to the users who expect the getCellFromPoint() function to always return an object structured as { cell: a, row: b } (where a and b are numbers), so returning -1 has less impact and is still identifiable by being outside the canvas
the bulk of the unit tests I have in my lib for this change are the following tests, which are more realistic than before. So any values outside the grid canvas will return -1 regardless of its position outside the canvas
return null
? That would require too much refactoring and potentially bring a breaking change to the users who expect thegetCellFromPoint()
function to always return an object structured as{ cell: a, row: b }
(wherea
andb
are numbers), so returning -1 has less impact and is still identifiable by being outside the canvasthe bulk of the unit tests I have in my lib for this change are the following tests, which are more realistic than before. So any values outside the grid canvas will return
-1
regardless of its position outside the canvas