Applied the sf::Rect modifications in CSFML and SFML.Net

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1504 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2010-04-09 17:05:21 +00:00
parent 082a928555
commit fb91bf4c6d
12 changed files with 99 additions and 193 deletions

View File

@ -39,30 +39,18 @@ typedef struct
{ {
float Left; float Left;
float Top; float Top;
float Right; float Width;
float Bottom; float Height;
} sfFloatRect; } sfFloatRect;
typedef struct typedef struct
{ {
int Left; int Left;
int Top; int Top;
int Right; int Width;
int Bottom; int Height;
} sfIntRect; } sfIntRect;
////////////////////////////////////////////////////////////
/// Move a rectangle by the given offset
///
/// \param rect : Rectangle to move
/// \param offsetX : Horizontal offset
/// \param offsetY : Vertical offset
///
////////////////////////////////////////////////////////////
CSFML_API void sfFloatRect_Offset(sfFloatRect* rect, float offsetX, float offsetY);
CSFML_API void sfIntRect_Offset(sfIntRect* rect, int offsetX, int offsetY);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Check if a point is inside a rectangle's area /// Check if a point is inside a rectangle's area
/// ///

View File

@ -95,12 +95,12 @@ sfGlyph sfFont_GetGlyph(sfFont* font, sfUint32 codePoint, unsigned int character
glyph.Advance = SFMLGlyph.Advance; glyph.Advance = SFMLGlyph.Advance;
glyph.Bounds.Left = SFMLGlyph.Bounds.Left; glyph.Bounds.Left = SFMLGlyph.Bounds.Left;
glyph.Bounds.Top = SFMLGlyph.Bounds.Top; glyph.Bounds.Top = SFMLGlyph.Bounds.Top;
glyph.Bounds.Right = SFMLGlyph.Bounds.Right; glyph.Bounds.Width = SFMLGlyph.Bounds.Width;
glyph.Bounds.Bottom = SFMLGlyph.Bounds.Bottom; glyph.Bounds.Height = SFMLGlyph.Bounds.Height;
glyph.SubRect.Left = SFMLGlyph.SubRect.Left; glyph.SubRect.Left = SFMLGlyph.SubRect.Left;
glyph.SubRect.Top = SFMLGlyph.SubRect.Top; glyph.SubRect.Top = SFMLGlyph.SubRect.Top;
glyph.SubRect.Right = SFMLGlyph.SubRect.Right; glyph.SubRect.Width = SFMLGlyph.SubRect.Width;
glyph.SubRect.Bottom = SFMLGlyph.SubRect.Bottom; glyph.SubRect.Height = SFMLGlyph.SubRect.Height;
return glyph; return glyph;
} }

View File

@ -155,7 +155,7 @@ void sfImage_CreateMaskFromColor(sfImage* image, sfColor colorKey, sfUint8 alpha
void sfImage_CopyImage(sfImage* image, const sfImage* source, unsigned int destX, unsigned int destY, sfIntRect sourceRect) void sfImage_CopyImage(sfImage* image, const sfImage* source, unsigned int destX, unsigned int destY, sfIntRect sourceRect)
{ {
CSFML_CHECK(source); CSFML_CHECK(source);
sf::IntRect SFMLRect(sourceRect.Left, sourceRect.Top, sourceRect.Right, sourceRect.Bottom); sf::IntRect SFMLRect(sourceRect.Left, sourceRect.Top, sourceRect.Width, sourceRect.Height);
CSFML_CALL_PTR(image, Copy(*source->This, destX, destY, SFMLRect)); CSFML_CALL_PTR(image, Copy(*source->This, destX, destY, SFMLRect));
} }
@ -167,7 +167,7 @@ void sfImage_CopyImage(sfImage* image, const sfImage* source, unsigned int destX
CSFML_API sfBool sfImage_CopyScreen(sfImage* image, sfRenderWindow* window, sfIntRect sourceRect) CSFML_API sfBool sfImage_CopyScreen(sfImage* image, sfRenderWindow* window, sfIntRect sourceRect)
{ {
CSFML_CHECK_RETURN(window, sfFalse); CSFML_CHECK_RETURN(window, sfFalse);
sf::IntRect SFMLRect(sourceRect.Left, sourceRect.Top, sourceRect.Right, sourceRect.Bottom); sf::IntRect SFMLRect(sourceRect.Left, sourceRect.Top, sourceRect.Width, sourceRect.Height);
CSFML_CALL_PTR_RETURN(image, CopyScreen(window->This, SFMLRect), sfFalse); CSFML_CALL_PTR_RETURN(image, CopyScreen(window->This, SFMLRect), sfFalse);
} }
@ -213,7 +213,7 @@ const sfUint8* sfImage_GetPixelsPtr(const sfImage* image)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfImage_UpdatePixels(const sfImage* image, const sfUint8* pixels, sfIntRect rectangle) void sfImage_UpdatePixels(const sfImage* image, const sfUint8* pixels, sfIntRect rectangle)
{ {
sf::IntRect rect(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom); sf::IntRect rect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height);
CSFML_CALL_PTR(image, UpdatePixels(pixels, rect)); CSFML_CALL_PTR(image, UpdatePixels(pixels, rect));
} }

View File

@ -30,39 +30,18 @@
#include <SFML/Internal.h> #include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Move a rectangle by the given offset
////////////////////////////////////////////////////////////
void sfFloatRect_Offset(sfFloatRect* rect, float offsetX, float offsetY)
{
CSFML_CHECK(rect)
rect->Left += offsetX;
rect->Right += offsetX;
rect->Top += offsetY;
rect->Bottom += offsetY;
}
void sfIntRect_Offset(sfIntRect* rect, int offsetX, int offsetY)
{
CSFML_CHECK(rect)
rect->Left += offsetX;
rect->Right += offsetX;
rect->Top += offsetY;
rect->Bottom += offsetY;
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Check if a point is inside a rectangle's area /// Check if a point is inside a rectangle's area
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfBool sfFloatRect_Contains(const sfFloatRect* rect, float x, float y) sfBool sfFloatRect_Contains(const sfFloatRect* rect, float x, float y)
{ {
CSFML_CHECK_RETURN(rect, sfFalse) CSFML_CHECK_RETURN(rect, sfFalse)
return sf::FloatRect(rect->Left, rect->Top, rect->Right, rect->Bottom).Contains(x, y); return sf::FloatRect(rect->Left, rect->Top, rect->Width, rect->Height).Contains(x, y);
} }
sfBool sfIntRect_Contains(const sfIntRect* rect, int x, int y) sfBool sfIntRect_Contains(const sfIntRect* rect, int x, int y)
{ {
CSFML_CHECK_RETURN(rect, sfFalse) CSFML_CHECK_RETURN(rect, sfFalse)
return sf::IntRect(rect->Left, rect->Top, rect->Right, rect->Bottom).Contains(x, y); return sf::IntRect(rect->Left, rect->Top, rect->Width, rect->Height).Contains(x, y);
} }
@ -74,8 +53,8 @@ sfBool sfFloatRect_Intersects(const sfFloatRect* rect1, const sfFloatRect* rect2
CSFML_CHECK_RETURN(rect1, sfFalse) CSFML_CHECK_RETURN(rect1, sfFalse)
CSFML_CHECK_RETURN(rect2, sfFalse) CSFML_CHECK_RETURN(rect2, sfFalse)
sf::FloatRect SFMLRect1(rect1->Left, rect1->Top, rect1->Right, rect1->Bottom); sf::FloatRect SFMLRect1(rect1->Left, rect1->Top, rect1->Width, rect1->Height);
sf::FloatRect SFMLRect2(rect2->Left, rect2->Top, rect2->Right, rect2->Bottom); sf::FloatRect SFMLRect2(rect2->Left, rect2->Top, rect2->Width, rect2->Height);
if (intersection) if (intersection)
{ {
@ -84,8 +63,8 @@ sfBool sfFloatRect_Intersects(const sfFloatRect* rect1, const sfFloatRect* rect2
intersection->Left = overlap.Left; intersection->Left = overlap.Left;
intersection->Top = overlap.Top; intersection->Top = overlap.Top;
intersection->Right = overlap.Right; intersection->Width = overlap.Width;
intersection->Bottom = overlap.Bottom; intersection->Height = overlap.Height;
return intersects; return intersects;
} }
@ -99,8 +78,8 @@ sfBool sfIntRect_Intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIn
CSFML_CHECK_RETURN(rect1, sfFalse) CSFML_CHECK_RETURN(rect1, sfFalse)
CSFML_CHECK_RETURN(rect2, sfFalse) CSFML_CHECK_RETURN(rect2, sfFalse)
sf::IntRect SFMLRect1(rect1->Left, rect1->Top, rect1->Right, rect1->Bottom); sf::IntRect SFMLRect1(rect1->Left, rect1->Top, rect1->Width, rect1->Height);
sf::IntRect SFMLRect2(rect2->Left, rect2->Top, rect2->Right, rect2->Bottom); sf::IntRect SFMLRect2(rect2->Left, rect2->Top, rect2->Width, rect2->Height);
if (intersection) if (intersection)
{ {
@ -109,8 +88,8 @@ sfBool sfIntRect_Intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIn
intersection->Left = overlap.Left; intersection->Left = overlap.Left;
intersection->Top = overlap.Top; intersection->Top = overlap.Top;
intersection->Right = overlap.Right; intersection->Width = overlap.Width;
intersection->Bottom = overlap.Bottom; intersection->Height = overlap.Height;
return intersects; return intersects;
} }

View File

@ -212,8 +212,8 @@ sfIntRect sfRenderImage_GetViewport(const sfRenderImage* renderImage, const sfVi
sf::IntRect SFMLrect = renderImage->This.GetViewport(view->This); sf::IntRect SFMLrect = renderImage->This.GetViewport(view->This);
rect.Left = SFMLrect.Left; rect.Left = SFMLrect.Left;
rect.Top = SFMLrect.Top; rect.Top = SFMLrect.Top;
rect.Right = SFMLrect.Right; rect.Width = SFMLrect.Width;
rect.Bottom = SFMLrect.Bottom; rect.Height = SFMLrect.Height;
return rect; return rect;
} }

View File

@ -449,8 +449,8 @@ sfIntRect sfRenderWindow_GetViewport(const sfRenderWindow* renderWindow, const s
sf::IntRect SFMLrect = renderWindow->This.GetViewport(view->This); sf::IntRect SFMLrect = renderWindow->This.GetViewport(view->This);
rect.Left = SFMLrect.Left; rect.Left = SFMLrect.Left;
rect.Top = SFMLrect.Top; rect.Top = SFMLrect.Top;
rect.Right = SFMLrect.Right; rect.Width = SFMLrect.Width;
rect.Bottom = SFMLrect.Bottom; rect.Height = SFMLrect.Height;
return rect; return rect;
} }

View File

@ -41,8 +41,8 @@ sfSprite* sfSprite_Create()
sprite->Image = NULL; sprite->Image = NULL;
sprite->SubRect.Left = sprite->This.GetSubRect().Left; sprite->SubRect.Left = sprite->This.GetSubRect().Left;
sprite->SubRect.Top = sprite->This.GetSubRect().Top; sprite->SubRect.Top = sprite->This.GetSubRect().Top;
sprite->SubRect.Right = sprite->This.GetSubRect().Right; sprite->SubRect.Width = sprite->This.GetSubRect().Width;
sprite->SubRect.Bottom = sprite->This.GetSubRect().Bottom; sprite->SubRect.Height = sprite->This.GetSubRect().Height;
return sprite; return sprite;
} }
@ -319,7 +319,7 @@ void sfSprite_SetImage(sfSprite* sprite, const sfImage* image, sfBool adjustToNe
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfSprite_SetSubRect(sfSprite* sprite, sfIntRect rectangle) void sfSprite_SetSubRect(sfSprite* sprite, sfIntRect rectangle)
{ {
CSFML_CALL(sprite, SetSubRect(sf::IntRect(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom))) CSFML_CALL(sprite, SetSubRect(sf::IntRect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height)))
sprite->SubRect = rectangle; sprite->SubRect = rectangle;
} }

View File

@ -425,8 +425,8 @@ sfFloatRect sfText_GetRect(const sfText* text)
sf::FloatRect SFMLRect = text->This.GetRect(); sf::FloatRect SFMLRect = text->This.GetRect();
text->Rect.Left = SFMLRect.Left; text->Rect.Left = SFMLRect.Left;
text->Rect.Top = SFMLRect.Top; text->Rect.Top = SFMLRect.Top;
text->Rect.Right = SFMLRect.Right; text->Rect.Width = SFMLRect.Width;
text->Rect.Bottom = SFMLRect.Bottom; text->Rect.Height = SFMLRect.Height;
return text->Rect; return text->Rect;
} }

View File

@ -103,7 +103,7 @@ void sfView_SetRotation(sfView* view, float angle)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfView_SetViewport(sfView* view, sfFloatRect viewport) void sfView_SetViewport(sfView* view, sfFloatRect viewport)
{ {
CSFML_CALL(view, SetViewport(sf::FloatRect(viewport.Left, viewport.Top, viewport.Right, viewport.Bottom))); CSFML_CALL(view, SetViewport(sf::FloatRect(viewport.Left, viewport.Top, viewport.Width, viewport.Height)));
} }
@ -113,7 +113,7 @@ void sfView_SetViewport(sfView* view, sfFloatRect viewport)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfView_Reset(sfView* view, sfFloatRect rectangle) void sfView_Reset(sfView* view, sfFloatRect rectangle)
{ {
CSFML_CALL(view, Reset(sf::FloatRect(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom))); CSFML_CALL(view, Reset(sf::FloatRect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height)));
} }
@ -181,8 +181,8 @@ sfFloatRect sfView_GetViewport(const sfView* view)
sf::FloatRect SFMLRect = view->This.GetViewport(); sf::FloatRect SFMLRect = view->This.GetViewport();
rect.Left = SFMLRect.Left; rect.Left = SFMLRect.Left;
rect.Top = SFMLRect.Top; rect.Top = SFMLRect.Top;
rect.Right = SFMLRect.Right; rect.Width = SFMLRect.Width;
rect.Bottom = SFMLRect.Bottom; rect.Height = SFMLRect.Height;
return rect; return rect;
} }

View File

@ -32,10 +32,8 @@ EXPORTS
sfImage_GetWidth sfImage_GetWidth
sfImage_GetHeight sfImage_GetHeight
sfImage_IsSmooth sfImage_IsSmooth
sfFloatRect_Offset
sfFloatRect_Contains sfFloatRect_Contains
sfFloatRect_Intersects sfFloatRect_Intersects
sfIntRect_Offset
sfIntRect_Contains sfIntRect_Contains
sfIntRect_Intersects sfIntRect_Intersects
sfShader_CreateFromFile sfShader_CreateFromFile

View File

@ -32,10 +32,8 @@ EXPORTS
sfImage_GetWidth sfImage_GetWidth
sfImage_GetHeight sfImage_GetHeight
sfImage_IsSmooth sfImage_IsSmooth
sfFloatRect_Offset
sfFloatRect_Contains sfFloatRect_Contains
sfFloatRect_Intersects sfFloatRect_Intersects
sfIntRect_Offset
sfIntRect_Contains sfIntRect_Contains
sfIntRect_Intersects sfIntRect_Intersects
sfShader_CreateFromFile sfShader_CreateFromFile

View File

@ -20,50 +20,15 @@ namespace SFML
/// </summary> /// </summary>
/// <param name="left">Left coordinate of the rectangle</param> /// <param name="left">Left coordinate of the rectangle</param>
/// <param name="top">Top coordinate of the rectangle</param> /// <param name="top">Top coordinate of the rectangle</param>
/// <param name="right">Right coordinate of the rectangle</param> /// <param name="width">Width of the rectangle</param>
/// <param name="bottom">Bottom coordinate of the rectangle</param> /// <param name="height">Height of the rectangle</param>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public IntRect(int left, int top, int right, int bottom) public IntRect(int left, int top, int width, int height)
{ {
Left = left; Left = left;
Top = top; Top = top;
Right = right; Width = width;
Bottom = bottom; Height = height;
}
////////////////////////////////////////////////////////////
/// <summary>
/// Width of the rectangle
/// </summary>
////////////////////////////////////////////////////////////
public int Width
{
get {return Right - Left;}
}
////////////////////////////////////////////////////////////
/// <summary>
/// Height of the rectangle
/// </summary>
////////////////////////////////////////////////////////////
public int Height
{
get {return Bottom - Top;}
}
////////////////////////////////////////////////////////////
/// <summary>
/// Move the whole rectangle by the given offset
/// </summary>
/// <param name="offsetX">Horizontal offset</param>
/// <param name="offsetY">Vertical offset</param>
////////////////////////////////////////////////////////////
public void Offset(int offsetX, int offsetY)
{
Left += offsetX;
Top += offsetY;
Right += offsetX;
Bottom += offsetY;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -76,7 +41,7 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public bool Contains(int x, int y) public bool Contains(int x, int y)
{ {
return (x >= Left) && (x <= Right) && (y >= Top) && (y <= Bottom); return (x >= Left) && (x < Left + Width) && (y >= Top) && (y < Top + Height);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -88,8 +53,13 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public bool Intersects(IntRect rect) public bool Intersects(IntRect rect)
{ {
return ((Math.Max(Left, rect.Left) < Math.Min(Right, rect.Right)) && // Compute the intersection boundaries
(Math.Max(Top, rect.Top) < Math.Min(Bottom, rect.Bottom))); int left = Math.Max(Left, rect.Left);
int top = Math.Max(Top, rect.Top);
int right = Math.Min(Left + Width, rect.Left + rect.Width);
int bottom = Math.Min(Top + Height, rect.Top + rect.Height);
return (left < right) && (top < bottom);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -102,25 +72,27 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public bool Intersects(IntRect rect, out IntRect overlap) public bool Intersects(IntRect rect, out IntRect overlap)
{ {
IntRect Overlapping = new IntRect(Math.Max(Left, rect.Left), // Compute the intersection boundaries
Math.Max(Top, rect.Top), int left = Math.Max(Left, rect.Left);
Math.Min(Right, rect.Right), int top = Math.Max(Top, rect.Top);
Math.Min(Bottom, rect.Bottom)); int right = Math.Min(Left + Width, rect.Left + rect.Width);
int bottom = Math.Min(Top + Height, rect.Top + rect.Height);
if ((Overlapping.Left < Overlapping.Right) && (Overlapping.Top < Overlapping.Bottom)) // If the intersection is valid (positive non zero area), then there is an intersection
if ((left < right) && (top < bottom))
{ {
overlap.Left = Overlapping.Left; overlap.Left = left;
overlap.Top = Overlapping.Top; overlap.Top = top;
overlap.Right = Overlapping.Right; overlap.Width = right - left;
overlap.Bottom = Overlapping.Bottom; overlap.Height = bottom - top;
return true; return true;
} }
else else
{ {
overlap.Left = 0; overlap.Left = 0;
overlap.Top = 0; overlap.Top = 0;
overlap.Right = 0; overlap.Width = 0;
overlap.Bottom = 0; overlap.Height = 0;
return false; return false;
} }
} }
@ -136,8 +108,8 @@ namespace SFML
return "[IntRect]" + return "[IntRect]" +
" Left(" + Left + ")" + " Left(" + Left + ")" +
" Top(" + Top + ")" + " Top(" + Top + ")" +
" Right(" + Right + ")" + " Width(" + Width + ")" +
" Bottom(" + Bottom + ")"; " Height(" + Height + ")";
} }
/// <summary>Left coordinate of the rectangle</summary> /// <summary>Left coordinate of the rectangle</summary>
@ -146,16 +118,15 @@ namespace SFML
/// <summary>Top coordinate of the rectangle</summary> /// <summary>Top coordinate of the rectangle</summary>
public int Top; public int Top;
/// <summary>Right coordinate of the rectangle</summary> /// <summary>Width of the rectangle</summary>
public int Right; public int Width;
/// <summary>Bottom coordinate of the rectangle</summary> /// <summary>Height of the rectangle</summary>
public int Bottom; public int Height;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// <summary> /// <summary>
/// FloatRect is an utility class for manipulating 2D rectangles /// IntRect is an utility class for manipulating 2D rectangles
/// with float coordinates /// with float coordinates
/// </summary> /// </summary>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -168,50 +139,15 @@ namespace SFML
/// </summary> /// </summary>
/// <param name="left">Left coordinate of the rectangle</param> /// <param name="left">Left coordinate of the rectangle</param>
/// <param name="top">Top coordinate of the rectangle</param> /// <param name="top">Top coordinate of the rectangle</param>
/// <param name="right">Right coordinate of the rectangle</param> /// <param name="width">Width of the rectangle</param>
/// <param name="bottom">Bottom coordinate of the rectangle</param> /// <param name="height">Height of the rectangle</param>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public FloatRect(float left, float top, float right, float bottom) public FloatRect(float left, float top, float width, float height)
{ {
Left = left; Left = left;
Top = top; Top = top;
Right = right; Width = width;
Bottom = bottom; Height = height;
}
////////////////////////////////////////////////////////////
/// <summary>
/// Width of the rectangle
/// </summary>
////////////////////////////////////////////////////////////
public float Width
{
get {return Right - Left;}
}
////////////////////////////////////////////////////////////
/// <summary>
/// Height of the rectangle
/// </summary>
////////////////////////////////////////////////////////////
public float Height
{
get {return Bottom - Top;}
}
////////////////////////////////////////////////////////////
/// <summary>
/// Move the whole rectangle by the given offset
/// </summary>
/// <param name="offsetX">Horizontal offset</param>
/// <param name="offsetY">Vertical offset</param>
////////////////////////////////////////////////////////////
public void Offset(float offsetX, float offsetY)
{
Left += offsetX;
Top += offsetY;
Right += offsetX;
Bottom += offsetY;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -224,7 +160,7 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public bool Contains(float x, float y) public bool Contains(float x, float y)
{ {
return (x >= Left) && (x <= Right) && (y >= Top) && (y <= Bottom); return (x >= Left) && (x < Left + Width) && (y >= Top) && (y < Top + Height);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -236,8 +172,13 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public bool Intersects(FloatRect rect) public bool Intersects(FloatRect rect)
{ {
return ((Math.Max(Left, rect.Left) < Math.Min(Right, rect.Right)) && // Compute the intersection boundaries
(Math.Max(Top, rect.Top) < Math.Min(Bottom, rect.Bottom))); float left = Math.Max(Left, rect.Left);
float top = Math.Max(Top, rect.Top);
float right = Math.Min(Left + Width, rect.Left + rect.Width);
float bottom = Math.Min(Top + Height, rect.Top + rect.Height);
return (left < right) && (top < bottom);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -250,25 +191,27 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public bool Intersects(FloatRect rect, out FloatRect overlap) public bool Intersects(FloatRect rect, out FloatRect overlap)
{ {
FloatRect Overlapping = new FloatRect(Math.Max(Left, rect.Left), // Compute the intersection boundaries
Math.Max(Top, rect.Top), float left = Math.Max(Left, rect.Left);
Math.Min(Right, rect.Right), float top = Math.Max(Top, rect.Top);
Math.Min(Bottom, rect.Bottom)); float right = Math.Min(Left + Width, rect.Left + rect.Width);
float bottom = Math.Min(Top + Height, rect.Top + rect.Height);
if ((Overlapping.Left < Overlapping.Right) && (Overlapping.Top < Overlapping.Bottom)) // If the intersection is valid (positive non zero area), then there is an intersection
if ((left < right) && (top < bottom))
{ {
overlap.Left = Overlapping.Left; overlap.Left = left;
overlap.Top = Overlapping.Top; overlap.Top = top;
overlap.Right = Overlapping.Right; overlap.Width = right - left;
overlap.Bottom = Overlapping.Bottom; overlap.Height = bottom - top;
return true; return true;
} }
else else
{ {
overlap.Left = 0; overlap.Left = 0;
overlap.Top = 0; overlap.Top = 0;
overlap.Right = 0; overlap.Width = 0;
overlap.Bottom = 0; overlap.Height = 0;
return false; return false;
} }
} }
@ -284,8 +227,8 @@ namespace SFML
return "[FloatRect]" + return "[FloatRect]" +
" Left(" + Left + ")" + " Left(" + Left + ")" +
" Top(" + Top + ")" + " Top(" + Top + ")" +
" Right(" + Right + ")" + " Width(" + Width + ")" +
" Bottom(" + Bottom + ")"; " Height(" + Height + ")";
} }
/// <summary>Left coordinate of the rectangle</summary> /// <summary>Left coordinate of the rectangle</summary>
@ -294,11 +237,11 @@ namespace SFML
/// <summary>Top coordinate of the rectangle</summary> /// <summary>Top coordinate of the rectangle</summary>
public float Top; public float Top;
/// <summary>Right coordinate of the rectangle</summary> /// <summary>Width of the rectangle</summary>
public float Right; public float Width;
/// <summary>Bottom coordinate of the rectangle</summary> /// <summary>Height of the rectangle</summary>
public float Bottom; public float Height;
} }
} }
} }