From 1d8e6f1493175327cdb8fed9a824324b1005b1cb Mon Sep 17 00:00:00 2001 From: "nathan@daedalus" Date: Fri, 23 Mar 2012 23:21:26 -0500 Subject: [PATCH] Adding support for intersecting a floating point rectangle --- axios/Axios_WP7.csproj | 1 + axios/Axios_Windows.csproj | 1 + axios/Axios_Xbox_360.csproj | 1 + axios/Engine/Structures/AxiosPoint.cs | 21 +++++++++- axios/Engine/Structures/AxiosRectangle.cs | 50 ++++++++++++++--------- 5 files changed, 53 insertions(+), 21 deletions(-) diff --git a/axios/Axios_WP7.csproj b/axios/Axios_WP7.csproj index 7ef7738..45f9c86 100644 --- a/axios/Axios_WP7.csproj +++ b/axios/Axios_WP7.csproj @@ -179,6 +179,7 @@ + diff --git a/axios/Axios_Windows.csproj b/axios/Axios_Windows.csproj index e401259..1b76ffe 100644 --- a/axios/Axios_Windows.csproj +++ b/axios/Axios_Windows.csproj @@ -219,6 +219,7 @@ + diff --git a/axios/Axios_Xbox_360.csproj b/axios/Axios_Xbox_360.csproj index f66b644..f15b1d4 100644 --- a/axios/Axios_Xbox_360.csproj +++ b/axios/Axios_Xbox_360.csproj @@ -172,6 +172,7 @@ + diff --git a/axios/Engine/Structures/AxiosPoint.cs b/axios/Engine/Structures/AxiosPoint.cs index 9d40e39..60aeefc 100644 --- a/axios/Engine/Structures/AxiosPoint.cs +++ b/axios/Engine/Structures/AxiosPoint.cs @@ -7,6 +7,25 @@ namespace Axios.Engine.Structures { class AxiosPoint { - + private float _x; + private float _y; + + public float X + { + get { return _x; } + set { _x = value; } + } + + public float Y + { + get { return _y; } + set { _y = value; } + } + + public AxiosPoint(float X, float Y) + { + _x = X; + _y = Y; + } } } diff --git a/axios/Engine/Structures/AxiosRectangle.cs b/axios/Engine/Structures/AxiosRectangle.cs index c5fa2c7..2a07fa3 100644 --- a/axios/Engine/Structures/AxiosRectangle.cs +++ b/axios/Engine/Structures/AxiosRectangle.cs @@ -7,10 +7,11 @@ namespace Axios.Engine.Structures { class AxiosRectangle { + + private AxiosPoint _point; private float _width; private float _height; - private float _x; - private float _y; + public float Width { @@ -24,43 +25,52 @@ namespace Axios.Engine.Structures set { _height = value; } } - public float X - { - get { return _x; } - set { _x = value; } - } - - public float Y - { - get { return _y; } - set { _y = value; } - } - public float Top { + get { return _point.Y; } + } + public float Right + { + get { return _point.X + _width; } + } + + public float Left + { + get { return _point.X; } } public float Bottom { - get { return _y + _height; } + get { return _point.Y + _height; } } + /*public AxiosPoint Center + { + get { return new AxiosPoint(Top + (Width / 2), Bottom - (Width / 2)); } + }*/ + public bool Intersect(AxiosRectangle rect) { - bool intersects = false; + //bool intersects = true; + if (Bottom < rect.Top) + return false; + if (Top > rect.Bottom) + return false; + if (Right < rect.Left) + return false; + if (Left > rect.Right) + return false; - - return intersects; + return true; } public AxiosRectangle(float X, float Y, float width, float height) { _width = width; _height = height; - _x = X; - _y = Y; + _point = new AxiosPoint(X, Y); }