Last active
July 31, 2019 17:21
-
-
Save AlexKardone/abcfea25be6029945d8f3c7d3b3feddb to your computer and use it in GitHub Desktop.
Check overlap between two rectangles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var checkCollisions = function(rect1, rect2) { | |
var xOverlap = Math.abs(rect1.x - rect2.x) <= Math.max(rect1.width, rect2.width); | |
var yOverlap = Math.abs(rect1.y - rect2.y) <= Math.max(rect1.height, rect2.height); | |
return xOverlap && yOverlap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment