Переглянути джерело

Merge branch 'master' of github.com:notanumber/GamePlay

David Sauve 13 роки тому
батько
коміт
92e93d487b

+ 1 - 1
gameplay-template/src/TemplateGame.h

@@ -13,7 +13,7 @@ class TemplateGame: public Game
 public:
 
     /**
-     * Constructror.
+     * Constructor.
      */
     TemplateGame();
 

+ 6 - 6
gameplay/src/Rectangle.cpp

@@ -95,12 +95,12 @@ bool Rectangle::contains(const Rectangle& r) const
 
 bool Rectangle::intersects(float x, float y, float width, float height) const
 {
-    const float left   = max(this->x, x);
-    const float top    = max(this->y, y);
-    const float right  = min(x + width, x + width);
-    const float bottom = min(y + height, y + height);
-
-    return (right > left && bottom > top);
+    float t;
+    if ((t = x - this->x) > this->width || -t > width)
+        return false;
+    if ((t = y - this->y) > this->height || -t > height)
+        return false;
+    return true;
 }
 
 bool Rectangle::intersects(const Rectangle& r) const

+ 1 - 0
gameplay/src/Rectangle.h

@@ -169,6 +169,7 @@ public:
 
     /**
      * Determines whether a specified rectangle intersects with this rectangle.
+     * Rectangles intersect if there is a common point that is contained in both rectangles.
      *
      * @param x The x-coordinate of the rectangle.
      * @param y The y-coordinate of the rectangle.