Created
June 28, 2016 00:25
-
-
Save gyakoo/69f652c33aa06b5426b813bf4f745f56 to your computer and use it in GitHub Desktop.
Returns a tuple with 1st as axis with bigger distance (0=x,1=y) and 2nd as the bigger separating distance.
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
def rectSAT(r0,r1): | |
'''Returns a tuple with 1st as axis with bigger distance (0=x,1=y) | |
and 2nd as the bigger separating distance. | |
If tuple[1]<0 there's penetration. If tuple[1]>0 no penetration. | |
Assumes Y grows down the screen.''' | |
# vertical edges | |
if r0.left > r1.left: r0,r1 = r1,r0 # assume r0 is always on left | |
sepX = r1.left - r0.right | |
if r0.top > r1.top: r0,r1=r1,r0 # assume r0 is always on top | |
sepY = r1.top - r0.bottom | |
return (0,sepX) if sepX > sepY else (1,sepY) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment