///////////////////////////////////////////////////////////////////////////////
//  SRect.cpp

#include "S2DI.h"
#include "SRect.h"

namespace math3d {

SRect::SRect(void) :
	x(0),
	y(0),
	width(0),
	height(0)
{
}

SRect::SRect(int nX_, int nY_, int nWidth_, int nHeight_) :
	x(nX_),
	y(nY_),
	width(nWidth_),
	height(nHeight_)
{
}

bool SRect::operator!=(const SRect& Obj) const
{
	if (x != Obj.x) return true;
	if (y != Obj.y) return true;
	if (width != Obj.width) return true;
	if (height != Obj.height) return true;

	return false;
}

void SRect::Set(int nX_, int nY_, int nWidth_, int nHeight_)
{
	x = nX_;
	y = nY_;
	width = nWidth_;
	height = nHeight_;
}

S2DI SRect::GetPos() const
{
	return S2DI(x, y);
}

S2DI SRect::GetSize() const
{
	return S2DI(width, height);
}

S2DI SRect::Limit(const S2DI& Pos) const
{
	S2DI NewPos = Pos;

	if (NewPos.x < x) NewPos.x = x;
	if (NewPos.x >= x + width) NewPos.x = x + width - 1;
	if (NewPos.y < y) NewPos.y = y;
	if (NewPos.y >= y + height) NewPos.y = y + height - 1;

	return NewPos;
}

}

