Adding support for intersecting a floating point rectangle

This commit is contained in:
nathan@daedalus 2012-03-23 23:21:26 -05:00
parent f4b91c0fc3
commit 1d8e6f1493
5 changed files with 53 additions and 21 deletions

View File

@ -179,6 +179,7 @@
<Compile Include="Engine\SimpleAxiosGameObject.cs" /> <Compile Include="Engine\SimpleAxiosGameObject.cs" />
<Compile Include="Engine\SimpleDrawableAxiosGameObject.cs" /> <Compile Include="Engine\SimpleDrawableAxiosGameObject.cs" />
<Compile Include="Engine\Singleton.cs" /> <Compile Include="Engine\Singleton.cs" />
<Compile Include="Engine\Structures\AxiosPoint.cs" />
<Compile Include="Engine\Structures\AxiosRectangle.cs" /> <Compile Include="Engine\Structures\AxiosRectangle.cs" />
<Compile Include="Engine\UI\AxiosButton.cs" /> <Compile Include="Engine\UI\AxiosButton.cs" />
<Compile Include="Engine\UI\AxiosUIObject.cs" /> <Compile Include="Engine\UI\AxiosUIObject.cs" />

View File

@ -219,6 +219,7 @@
<Compile Include="Engine\Interfaces\IAxiosGameObject.cs" /> <Compile Include="Engine\Interfaces\IAxiosGameObject.cs" />
<Compile Include="Engine\Interfaces\IDrawableAxiosGameObject.cs" /> <Compile Include="Engine\Interfaces\IDrawableAxiosGameObject.cs" />
<Compile Include="Engine\Log\AxiosLog.cs" /> <Compile Include="Engine\Log\AxiosLog.cs" />
<Compile Include="Engine\Structures\AxiosPoint.cs" />
<Compile Include="Engine\Structures\AxiosRectangle.cs" /> <Compile Include="Engine\Structures\AxiosRectangle.cs" />
<Compile Include="Engine\SimpleAxiosGameObject.cs" /> <Compile Include="Engine\SimpleAxiosGameObject.cs" />
<Compile Include="Engine\SimpleDrawableAxiosGameObject.cs" /> <Compile Include="Engine\SimpleDrawableAxiosGameObject.cs" />

View File

@ -172,6 +172,7 @@
<Compile Include="Engine\SimpleAxiosGameObject.cs" /> <Compile Include="Engine\SimpleAxiosGameObject.cs" />
<Compile Include="Engine\SimpleDrawableAxiosGameObject.cs" /> <Compile Include="Engine\SimpleDrawableAxiosGameObject.cs" />
<Compile Include="Engine\Singleton.cs" /> <Compile Include="Engine\Singleton.cs" />
<Compile Include="Engine\Structures\AxiosPoint.cs" />
<Compile Include="Engine\Structures\AxiosRectangle.cs" /> <Compile Include="Engine\Structures\AxiosRectangle.cs" />
<Compile Include="Engine\UI\AxiosButton.cs" /> <Compile Include="Engine\UI\AxiosButton.cs" />
<Compile Include="Engine\UI\AxiosUIObject.cs" /> <Compile Include="Engine\UI\AxiosUIObject.cs" />

View File

@ -7,6 +7,25 @@ namespace Axios.Engine.Structures
{ {
class AxiosPoint 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;
}
} }
} }

View File

@ -7,10 +7,11 @@ namespace Axios.Engine.Structures
{ {
class AxiosRectangle class AxiosRectangle
{ {
private AxiosPoint _point;
private float _width; private float _width;
private float _height; private float _height;
private float _x;
private float _y;
public float Width public float Width
{ {
@ -24,43 +25,52 @@ namespace Axios.Engine.Structures
set { _height = value; } set { _height = value; }
} }
public float X
{
get { return _x; }
set { _x = value; }
}
public float Y
{
get { return _y; }
set { _y = value; }
}
public float Top 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 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) 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 true;
return intersects;
} }
public AxiosRectangle(float X, float Y, float width, float height) public AxiosRectangle(float X, float Y, float width, float height)
{ {
_width = width; _width = width;
_height = height; _height = height;
_x = X; _point = new AxiosPoint(X, Y);
_y = Y;
} }