fix snapping for negative i values

Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
Victor Seiji Hariki 2022-12-17 01:20:51 -03:00
parent 9a8b064ab2
commit fc7302f8fa

View file

@ -244,7 +244,12 @@ function makeWriteOnce(obj, name = "write-once object", exceptions = []) {
* @returns an offset, in which [i + offset = (a location snapped to the grid)]
*/
function snap(i, offset = 0, gridSize = 64) {
const modulus = (i - offset) % gridSize;
let diff = i - offset;
if (diff < 0) {
diff += gridSize * Math.ceil(Math.abs(diff / gridSize));
}
const modulus = diff % gridSize;
var snapOffset = modulus;
if (modulus > gridSize / 2) snapOffset = modulus - gridSize;