aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2018-08-14 09:55:53 +0200
committerGitHub <noreply@github.com>2018-08-14 09:55:53 +0200
commit20ff9dc66331ad490795371a49000b3000b248be (patch)
tree80b555a68348dd1665a7bbdca2dc72d2c84af67d /src
parent477928dd0fc6c1a8e4abff9becfb584759297b1a (diff)
parent1cef8ea1bf814d9268f7769edfdcd5d7abda3ff8 (diff)
downloadraylib-20ff9dc66331ad490795371a49000b3000b248be.tar.gz
raylib-20ff9dc66331ad490795371a49000b3000b248be.zip
Merge pull request #622 from Joefish/rectcollision-optim
Shapes: Simplifies CheckCollisionRecs
Diffstat (limited to 'src')
-rw-r--r--src/shapes.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/shapes.c b/src/shapes.c
index 833f1613..acc0dc06 100644
--- a/src/shapes.c
+++ b/src/shapes.c
@@ -646,14 +646,11 @@ bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2
// Check collision between two rectangles
bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2)
{
- bool collision = false;
-
- float dx = (float)fabs((rec1.x + rec1.width/2) - (rec2.x + rec2.width/2));
- float dy = (float)fabs((rec1.y + rec1.height/2) - (rec2.y + rec2.height/2));
-
- if ((dx <= (rec1.width/2 + rec2.width/2)) && ((dy <= (rec1.height/2 + rec2.height/2)))) collision = true;
-
- return collision;
+ if ((rec1.x <= (rec2.x + rec2.width) && (rec1.x + rec1.width) >= rec2.x) &&
+ (rec1.y <= (rec2.y + rec2.height) && (rec1.y + rec1.height) >= rec2.y))
+ return true;
+ else
+ return false;
}
// Check collision between two circles