Skip to content

Commit

Permalink
Merge pull request #2632 from JakubEleniuk/fix/2503-locked-collision-fix
Browse files Browse the repository at this point in the history
fix/2503: break on locked node collision
  • Loading branch information
adumesny authored Mar 29, 2024
2 parents 74b1bbc + 859d277 commit ed1e9f0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/gridstack-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,28 +160,30 @@ export class GridStackEngine {

let collide: GridStackNode;
let overMax = 0.5; // need >50%
collides.forEach(n => {
if (n.locked || !n._rect) return;
for (let n of collides) {
if (n.locked || !n._rect) {
break;
}
let r2 = n._rect; // overlapping target
let yOver = Number.MAX_VALUE, xOver = Number.MAX_VALUE;
// depending on which side we started from, compute the overlap % of coverage
// (ex: from above/below we only compute the max horizontal line coverage)
if (r0.y < r2.y) { // from above
yOver = ((r.y + r.h) - r2.y) / r2.h;
} else if (r0.y+r0.h > r2.y+r2.h) { // from below
} else if (r0.y + r0.h > r2.y + r2.h) { // from below
yOver = ((r2.y + r2.h) - r.y) / r2.h;
}
if (r0.x < r2.x) { // from the left
xOver = ((r.x + r.w) - r2.x) / r2.w;
} else if (r0.x+r0.w > r2.x+r2.w) { // from the right
} else if (r0.x + r0.w > r2.x + r2.w) { // from the right
xOver = ((r2.x + r2.w) - r.x) / r2.w;
}
let over = Math.min(xOver, yOver);
if (over > overMax) {
overMax = over;
collide = n;
}
});
}
o.collide = collide; // save it so we don't have to find it again
return collide;
}
Expand Down

0 comments on commit ed1e9f0

Please sign in to comment.