mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
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:
parent
082a928555
commit
fb91bf4c6d
@ -39,30 +39,18 @@ typedef struct
|
||||
{
|
||||
float Left;
|
||||
float Top;
|
||||
float Right;
|
||||
float Bottom;
|
||||
float Width;
|
||||
float Height;
|
||||
} sfFloatRect;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int Left;
|
||||
int Top;
|
||||
int Right;
|
||||
int Bottom;
|
||||
int Width;
|
||||
int Height;
|
||||
} 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
|
||||
///
|
||||
|
@ -95,12 +95,12 @@ sfGlyph sfFont_GetGlyph(sfFont* font, sfUint32 codePoint, unsigned int character
|
||||
glyph.Advance = SFMLGlyph.Advance;
|
||||
glyph.Bounds.Left = SFMLGlyph.Bounds.Left;
|
||||
glyph.Bounds.Top = SFMLGlyph.Bounds.Top;
|
||||
glyph.Bounds.Right = SFMLGlyph.Bounds.Right;
|
||||
glyph.Bounds.Bottom = SFMLGlyph.Bounds.Bottom;
|
||||
glyph.Bounds.Width = SFMLGlyph.Bounds.Width;
|
||||
glyph.Bounds.Height = SFMLGlyph.Bounds.Height;
|
||||
glyph.SubRect.Left = SFMLGlyph.SubRect.Left;
|
||||
glyph.SubRect.Top = SFMLGlyph.SubRect.Top;
|
||||
glyph.SubRect.Right = SFMLGlyph.SubRect.Right;
|
||||
glyph.SubRect.Bottom = SFMLGlyph.SubRect.Bottom;
|
||||
glyph.SubRect.Width = SFMLGlyph.SubRect.Width;
|
||||
glyph.SubRect.Height = SFMLGlyph.SubRect.Height;
|
||||
|
||||
return glyph;
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
@ -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_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);
|
||||
}
|
||||
|
||||
@ -213,7 +213,7 @@ const sfUint8* sfImage_GetPixelsPtr(const sfImage* image)
|
||||
////////////////////////////////////////////////////////////
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -30,39 +30,18 @@
|
||||
#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
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfFloatRect_Contains(const sfFloatRect* rect, float x, float y)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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(rect2, sfFalse)
|
||||
|
||||
sf::FloatRect SFMLRect1(rect1->Left, rect1->Top, rect1->Right, rect1->Bottom);
|
||||
sf::FloatRect SFMLRect2(rect2->Left, rect2->Top, rect2->Right, rect2->Bottom);
|
||||
sf::FloatRect SFMLRect1(rect1->Left, rect1->Top, rect1->Width, rect1->Height);
|
||||
sf::FloatRect SFMLRect2(rect2->Left, rect2->Top, rect2->Width, rect2->Height);
|
||||
|
||||
if (intersection)
|
||||
{
|
||||
@ -84,8 +63,8 @@ sfBool sfFloatRect_Intersects(const sfFloatRect* rect1, const sfFloatRect* rect2
|
||||
|
||||
intersection->Left = overlap.Left;
|
||||
intersection->Top = overlap.Top;
|
||||
intersection->Right = overlap.Right;
|
||||
intersection->Bottom = overlap.Bottom;
|
||||
intersection->Width = overlap.Width;
|
||||
intersection->Height = overlap.Height;
|
||||
|
||||
return intersects;
|
||||
}
|
||||
@ -99,8 +78,8 @@ sfBool sfIntRect_Intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIn
|
||||
CSFML_CHECK_RETURN(rect1, sfFalse)
|
||||
CSFML_CHECK_RETURN(rect2, sfFalse)
|
||||
|
||||
sf::IntRect SFMLRect1(rect1->Left, rect1->Top, rect1->Right, rect1->Bottom);
|
||||
sf::IntRect SFMLRect2(rect2->Left, rect2->Top, rect2->Right, rect2->Bottom);
|
||||
sf::IntRect SFMLRect1(rect1->Left, rect1->Top, rect1->Width, rect1->Height);
|
||||
sf::IntRect SFMLRect2(rect2->Left, rect2->Top, rect2->Width, rect2->Height);
|
||||
|
||||
if (intersection)
|
||||
{
|
||||
@ -109,8 +88,8 @@ sfBool sfIntRect_Intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIn
|
||||
|
||||
intersection->Left = overlap.Left;
|
||||
intersection->Top = overlap.Top;
|
||||
intersection->Right = overlap.Right;
|
||||
intersection->Bottom = overlap.Bottom;
|
||||
intersection->Width = overlap.Width;
|
||||
intersection->Height = overlap.Height;
|
||||
|
||||
return intersects;
|
||||
}
|
||||
|
@ -212,8 +212,8 @@ sfIntRect sfRenderImage_GetViewport(const sfRenderImage* renderImage, const sfVi
|
||||
sf::IntRect SFMLrect = renderImage->This.GetViewport(view->This);
|
||||
rect.Left = SFMLrect.Left;
|
||||
rect.Top = SFMLrect.Top;
|
||||
rect.Right = SFMLrect.Right;
|
||||
rect.Bottom = SFMLrect.Bottom;
|
||||
rect.Width = SFMLrect.Width;
|
||||
rect.Height = SFMLrect.Height;
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
@ -449,8 +449,8 @@ sfIntRect sfRenderWindow_GetViewport(const sfRenderWindow* renderWindow, const s
|
||||
sf::IntRect SFMLrect = renderWindow->This.GetViewport(view->This);
|
||||
rect.Left = SFMLrect.Left;
|
||||
rect.Top = SFMLrect.Top;
|
||||
rect.Right = SFMLrect.Right;
|
||||
rect.Bottom = SFMLrect.Bottom;
|
||||
rect.Width = SFMLrect.Width;
|
||||
rect.Height = SFMLrect.Height;
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ sfSprite* sfSprite_Create()
|
||||
sprite->Image = NULL;
|
||||
sprite->SubRect.Left = sprite->This.GetSubRect().Left;
|
||||
sprite->SubRect.Top = sprite->This.GetSubRect().Top;
|
||||
sprite->SubRect.Right = sprite->This.GetSubRect().Right;
|
||||
sprite->SubRect.Bottom = sprite->This.GetSubRect().Bottom;
|
||||
sprite->SubRect.Width = sprite->This.GetSubRect().Width;
|
||||
sprite->SubRect.Height = sprite->This.GetSubRect().Height;
|
||||
|
||||
return sprite;
|
||||
}
|
||||
@ -319,7 +319,7 @@ void sfSprite_SetImage(sfSprite* sprite, const sfImage* image, sfBool adjustToNe
|
||||
////////////////////////////////////////////////////////////
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -425,8 +425,8 @@ sfFloatRect sfText_GetRect(const sfText* text)
|
||||
sf::FloatRect SFMLRect = text->This.GetRect();
|
||||
text->Rect.Left = SFMLRect.Left;
|
||||
text->Rect.Top = SFMLRect.Top;
|
||||
text->Rect.Right = SFMLRect.Right;
|
||||
text->Rect.Bottom = SFMLRect.Bottom;
|
||||
text->Rect.Width = SFMLRect.Width;
|
||||
text->Rect.Height = SFMLRect.Height;
|
||||
|
||||
return text->Rect;
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ void sfView_SetRotation(sfView* view, float angle)
|
||||
////////////////////////////////////////////////////////////
|
||||
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)
|
||||
{
|
||||
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();
|
||||
rect.Left = SFMLRect.Left;
|
||||
rect.Top = SFMLRect.Top;
|
||||
rect.Right = SFMLRect.Right;
|
||||
rect.Bottom = SFMLRect.Bottom;
|
||||
rect.Width = SFMLRect.Width;
|
||||
rect.Height = SFMLRect.Height;
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
@ -32,10 +32,8 @@ EXPORTS
|
||||
sfImage_GetWidth
|
||||
sfImage_GetHeight
|
||||
sfImage_IsSmooth
|
||||
sfFloatRect_Offset
|
||||
sfFloatRect_Contains
|
||||
sfFloatRect_Intersects
|
||||
sfIntRect_Offset
|
||||
sfIntRect_Contains
|
||||
sfIntRect_Intersects
|
||||
sfShader_CreateFromFile
|
||||
|
@ -32,10 +32,8 @@ EXPORTS
|
||||
sfImage_GetWidth
|
||||
sfImage_GetHeight
|
||||
sfImage_IsSmooth
|
||||
sfFloatRect_Offset
|
||||
sfFloatRect_Contains
|
||||
sfFloatRect_Intersects
|
||||
sfIntRect_Offset
|
||||
sfIntRect_Contains
|
||||
sfIntRect_Intersects
|
||||
sfShader_CreateFromFile
|
||||
|
@ -20,50 +20,15 @@ namespace SFML
|
||||
/// </summary>
|
||||
/// <param name="left">Left 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="bottom">Bottom coordinate of the rectangle</param>
|
||||
/// <param name="width">Width 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;
|
||||
Top = top;
|
||||
Right = right;
|
||||
Bottom = bottom;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <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;
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -76,7 +41,7 @@ namespace SFML
|
||||
////////////////////////////////////////////////////////////
|
||||
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)
|
||||
{
|
||||
return ((Math.Max(Left, rect.Left) < Math.Min(Right, rect.Right)) &&
|
||||
(Math.Max(Top, rect.Top) < Math.Min(Bottom, rect.Bottom)));
|
||||
// Compute the intersection boundaries
|
||||
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)
|
||||
{
|
||||
IntRect Overlapping = new IntRect(Math.Max(Left, rect.Left),
|
||||
Math.Max(Top, rect.Top),
|
||||
Math.Min(Right, rect.Right),
|
||||
Math.Min(Bottom, rect.Bottom));
|
||||
// Compute the intersection boundaries
|
||||
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);
|
||||
|
||||
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.Top = Overlapping.Top;
|
||||
overlap.Right = Overlapping.Right;
|
||||
overlap.Bottom = Overlapping.Bottom;
|
||||
overlap.Left = left;
|
||||
overlap.Top = top;
|
||||
overlap.Width = right - left;
|
||||
overlap.Height = bottom - top;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
overlap.Left = 0;
|
||||
overlap.Top = 0;
|
||||
overlap.Right = 0;
|
||||
overlap.Bottom = 0;
|
||||
overlap.Width = 0;
|
||||
overlap.Height = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -136,8 +108,8 @@ namespace SFML
|
||||
return "[IntRect]" +
|
||||
" Left(" + Left + ")" +
|
||||
" Top(" + Top + ")" +
|
||||
" Right(" + Right + ")" +
|
||||
" Bottom(" + Bottom + ")";
|
||||
" Width(" + Width + ")" +
|
||||
" Height(" + Height + ")";
|
||||
}
|
||||
|
||||
/// <summary>Left coordinate of the rectangle</summary>
|
||||
@ -146,16 +118,15 @@ namespace SFML
|
||||
/// <summary>Top coordinate of the rectangle</summary>
|
||||
public int Top;
|
||||
|
||||
/// <summary>Right coordinate of the rectangle</summary>
|
||||
public int Right;
|
||||
/// <summary>Width of the rectangle</summary>
|
||||
public int Width;
|
||||
|
||||
/// <summary>Bottom coordinate of the rectangle</summary>
|
||||
public int Bottom;
|
||||
/// <summary>Height of the rectangle</summary>
|
||||
public int Height;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// FloatRect is an utility class for manipulating 2D rectangles
|
||||
/// IntRect is an utility class for manipulating 2D rectangles
|
||||
/// with float coordinates
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -168,50 +139,15 @@ namespace SFML
|
||||
/// </summary>
|
||||
/// <param name="left">Left 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="bottom">Bottom coordinate of the rectangle</param>
|
||||
/// <param name="width">Width 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;
|
||||
Top = top;
|
||||
Right = right;
|
||||
Bottom = bottom;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <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;
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -224,7 +160,7 @@ namespace SFML
|
||||
////////////////////////////////////////////////////////////
|
||||
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)
|
||||
{
|
||||
return ((Math.Max(Left, rect.Left) < Math.Min(Right, rect.Right)) &&
|
||||
(Math.Max(Top, rect.Top) < Math.Min(Bottom, rect.Bottom)));
|
||||
// Compute the intersection boundaries
|
||||
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)
|
||||
{
|
||||
FloatRect Overlapping = new FloatRect(Math.Max(Left, rect.Left),
|
||||
Math.Max(Top, rect.Top),
|
||||
Math.Min(Right, rect.Right),
|
||||
Math.Min(Bottom, rect.Bottom));
|
||||
// Compute the intersection boundaries
|
||||
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);
|
||||
|
||||
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.Top = Overlapping.Top;
|
||||
overlap.Right = Overlapping.Right;
|
||||
overlap.Bottom = Overlapping.Bottom;
|
||||
overlap.Left = left;
|
||||
overlap.Top = top;
|
||||
overlap.Width = right - left;
|
||||
overlap.Height = bottom - top;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
overlap.Left = 0;
|
||||
overlap.Top = 0;
|
||||
overlap.Right = 0;
|
||||
overlap.Bottom = 0;
|
||||
overlap.Width = 0;
|
||||
overlap.Height = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -284,8 +227,8 @@ namespace SFML
|
||||
return "[FloatRect]" +
|
||||
" Left(" + Left + ")" +
|
||||
" Top(" + Top + ")" +
|
||||
" Right(" + Right + ")" +
|
||||
" Bottom(" + Bottom + ")";
|
||||
" Width(" + Width + ")" +
|
||||
" Height(" + Height + ")";
|
||||
}
|
||||
|
||||
/// <summary>Left coordinate of the rectangle</summary>
|
||||
@ -294,11 +237,11 @@ namespace SFML
|
||||
/// <summary>Top coordinate of the rectangle</summary>
|
||||
public float Top;
|
||||
|
||||
/// <summary>Right coordinate of the rectangle</summary>
|
||||
public float Right;
|
||||
/// <summary>Width of the rectangle</summary>
|
||||
public float Width;
|
||||
|
||||
/// <summary>Bottom coordinate of the rectangle</summary>
|
||||
public float Bottom;
|
||||
/// <summary>Height of the rectangle</summary>
|
||||
public float Height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user