Skip to content

Instantly share code, notes, and snippets.

@gyakoo
Created June 28, 2016 00:25
Show Gist options
  • Save gyakoo/69f652c33aa06b5426b813bf4f745f56 to your computer and use it in GitHub Desktop.
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.
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