فهرست منبع

Merge branch 'next' of https://github.com/blackberry/GamePlay into next

Darryl Gough 13 سال پیش
والد
کامیت
47ced8a75a
2فایلهای تغییر یافته به همراه8 افزوده شده و 7 حذف شده
  1. 7 7
      gameplay/src/Rectangle.cpp
  2. 1 0
      gameplay/src/Rectangle.h

+ 7 - 7
gameplay/src/Rectangle.cpp

@@ -80,7 +80,7 @@ float Rectangle::bottom() const
 
 bool Rectangle::contains(float x, float y) const
 {
-    return (x >= x && x <= (x + width) && y >= y && y <= (y + height));
+    return (x >= this->x && x <= (this->x + width) && y >= this->y && y <= (this->y + height));
 }
 
 bool Rectangle::contains(float x, float y, float width, float height) const
@@ -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.