Skip to content

Instantly share code, notes, and snippets.

@ashblue
Last active August 29, 2015 13:57
Show Gist options
  • Save ashblue/9887202 to your computer and use it in GitHub Desktop.
Save ashblue/9887202 to your computer and use it in GitHub Desktop.
/**
* Detect overlap between two square objects
* @param square1 {object} x, y, width, height
* @param square2 {object} x, y, width, height
* @returns {boolean}
*/
function getOverlap(square1, square2) {
return square1.x < square2.x + square2.width &&
square1.x + square1.width > square2.x &&
square1.y < square2.y + square2.height &&
square1.y + square1.height > square2.y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment