Skip to content

Commit

Permalink
fix snapping for negative i values
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Seiji Hariki <[email protected]>
  • Loading branch information
seijihariki committed Dec 17, 2022
1 parent 9a8b064 commit fc7302f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion js/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fc7302f

Please sign in to comment.