Last active
August 5, 2021 03:52
-
-
Save TrishZwei/82be6c70b2d87189e118 to your computer and use it in GitHub Desktop.
rectHit: A formulaic hit detect for squares and rectangles
This file contains 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
function rectHit(rectone, recttwo){ | |
//console.log('recthit called'); | |
var r1 = $(rectone); | |
var r2 = $(recttwo); | |
var r1x = r1.offset().left; | |
var r1w = r1.width(); | |
var r1y = r1.offset().top; | |
var r1h = r1.height(); | |
var r2x = r2.offset().left; | |
var r2w = r2.width(); | |
var r2y = r2.offset().top; | |
var r2h = r2.height(); | |
if( r1y+r1h < r2y || | |
r1y > r2y+r2h || | |
r1x > r2x+r2w || | |
r1x+r1w < r2x ){ | |
// console.log('recthit-false') | |
return false; | |
}else{ | |
//console.log('recthit-true') | |
return true; | |
} | |
}//end function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment