Skip to content

Instantly share code, notes, and snippets.

@DevEarley
Last active April 20, 2020 01:19
Show Gist options
  • Select an option

  • Save DevEarley/1438d16d1ea8c6c0798a2f4557586cf4 to your computer and use it in GitHub Desktop.

Select an option

Save DevEarley/1438d16d1ea8c6c0798a2f4557586cf4 to your computer and use it in GitHub Desktop.
"AB" collision of two rectangles
type Rectangle = {
x: number,
y: number,
h: number,
w: number
}
function areRectanglesColliding(a: Rectangle, b: Rectangle) {
const i = a.x < (b.x + b.w);
const ii = b.x < (a.x + a.w);
const iii = a.y < (b.y + b.h);
const iv = b.y < (a.y + a.h);
return i && ii && iii && iv;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment