From 7006fe3cc4580b2ece75681c0adc1ab6ab27891a Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Fri, 24 Apr 2015 16:08:05 -0300 Subject: [PATCH] Corrected rectangle intersection, fixes #1731 --- core/math/aabb.h | 12 ++++++------ core/math/math_2d.h | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/math/aabb.h b/core/math/aabb.h index 5ce39c34d74..4781e5c2638 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -110,17 +110,17 @@ public: inline bool AABB::intersects(const AABB& p_aabb) const { - if ( pos.x > (p_aabb.pos.x + p_aabb.size.x) ) + if ( pos.x >= (p_aabb.pos.x + p_aabb.size.x) ) return false; - if ( (pos.x+size.x) < p_aabb.pos.x ) + if ( (pos.x+size.x) <= p_aabb.pos.x ) return false; - if ( pos.y > (p_aabb.pos.y + p_aabb.size.y) ) + if ( pos.y >= (p_aabb.pos.y + p_aabb.size.y) ) return false; - if ( (pos.y+size.y) < p_aabb.pos.y ) + if ( (pos.y+size.y) <= p_aabb.pos.y ) return false; - if ( pos.z > (p_aabb.pos.z + p_aabb.size.z) ) + if ( pos.z >= (p_aabb.pos.z + p_aabb.size.z) ) return false; - if ( (pos.z+size.z) < p_aabb.pos.z ) + if ( (pos.z+size.z) <= p_aabb.pos.z ) return false; return true; diff --git a/core/math/math_2d.h b/core/math/math_2d.h index 3691ab75b9e..ac315fddb75 100644 --- a/core/math/math_2d.h +++ b/core/math/math_2d.h @@ -214,13 +214,13 @@ struct Rect2 { float get_area() const { return size.width*size.height; } inline bool intersects(const Rect2& p_rect) const { - if ( pos.x > (p_rect.pos.x + p_rect.size.width) ) + if ( pos.x >= (p_rect.pos.x + p_rect.size.width) ) return false; - if ( (pos.x+size.width) < p_rect.pos.x ) + if ( (pos.x+size.width) <= p_rect.pos.x ) return false; - if ( pos.y > (p_rect.pos.y + p_rect.size.height) ) + if ( pos.y >= (p_rect.pos.y + p_rect.size.height) ) return false; - if ( (pos.y+size.height) < p_rect.pos.y ) + if ( (pos.y+size.height) <= p_rect.pos.y ) return false; return true;