From 5125f35e71f430e4483b3240086e93331b0ef3f6 Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Tue, 10 Jul 2012 16:18:20 +0200 Subject: [PATCH] Quick exit on shape:collidesWith(shape) --- shapes.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shapes.lua b/shapes.lua index bb5a265..d1a60c7 100644 --- a/shapes.lua +++ b/shapes.lua @@ -123,6 +123,7 @@ end -- collision dispatching: -- let circle shape or compund shape handle the collision function ConvexPolygonShape:collidesWith(other) + if self == other then return false end if other._type ~= Shape.POLYGON then local collide, sx,sy = other:collidesWith(self) return collide, sx and -sx, sy and -sy @@ -133,6 +134,7 @@ function ConvexPolygonShape:collidesWith(other) end function ConcavePolygonShape:collidesWith(other) + if self == other then return false end if other._type == Shape.POINT then return other:collidesWith(self) end @@ -151,6 +153,7 @@ function ConcavePolygonShape:collidesWith(other) end function CircleShape:collidesWith(other) + if self == other then return false end if other._type == Shape.CIRCLE then local px,py = self._center.x-other._center.x, self._center.y-other._center.y local d = vector.len2(px,py) @@ -174,6 +177,7 @@ function CircleShape:collidesWith(other) end function PointShape:collidesWith(other) + if self == other then return false end if other._type == Shape.POINT then return (self._pos == other._pos), 0,0 end