Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions app/client/src/utils/boxHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@ export interface Rect {
}

export const areIntersecting = (r1: Rect, r2: Rect) => {
return !(
r2.left >= r1.right ||
r2.right <= r1.left ||
r2.top >= r1.bottom ||
r2.bottom <= r1.top
);
// Check left/right overlap first, with short-circuits to avoid unnecessary property reads.
const l2 = r2.left;
const r1r = r1.right;
if (!(l2 < r1r)) return false;

const r2r = r2.right;
const l1 = r1.left;
if (!(r2r > l1)) return false;

// Check top/bottom overlap next.
const t2 = r2.top;
const b1 = r1.bottom;
if (!(t2 < b1)) return false;

const b2 = r2.bottom;
const t1 = r1.top;
return b2 > t1;
};