This thread has been moved from the thread RECT (rectangle) class additions. Are they are useful?
I made the mistake of mixing 2 threads.
So I'm splitting them and moving both.
I am working on making a game engine. 2D Raster type graphics to start with. In doing so, I am taking my time and immersing myself in each aspect of the engine development rather than just getting sprites drawing and moving, then trying to make a game.
RECT class Patch
Straight away I needed some extra functions in the RECT class. I didn't see them in the code.
I know this is simple, but I wanted to know if it's useful for everyone in general. I found them necessary, or at least practical.
Here's the rect code
Code: Select all
//! (Re)Sets the rectangle to the parameters
void set(T x, T y, T x2, T y2)
{//! Modified by Ulf
UpperLeftCorner.X = x;
UpperLeftCorner.Y = y;
LowerRightCorner.X = x2;
LowerRightCorner.Y = y2;
}
//! (Re)Sets the rectangle to the parameters
void set(const position2d<T>& upperLeft, const position2d<T>& lowerRight)
{//! Modified by Ulf
UpperLeftCorner.X = upperLeft.X;
UpperLeftCorner.Y = upperLeft.Y;
LowerRightCorner.X = lowerRight.X;
LowerRightCorner.Y = lowerRight.Y;
}
//! (Re)Sets the rectangle so that it keeps the same dimensions, but anchors its Upper left corner at the position given.
void setUpperLeft(const position2d<T>& upperLeft)
{//! Modified by Ulf
T w = LowerRightCorner.X - UpperLeftCorner.X;
T h = LowerRightCorner.Y - UpperLeftCorner.Y;
UpperLeftCorner.X = upperLeft.X;
UpperLeftCorner.Y = upperLeft.Y;
LowerRightCorner.X = upperLeft.X + w;
LowerRightCorner.Y = upperLeft.Y + h;
}
//! (Re)Sets the rectangle so that it keeps the same dimensions, but anchors its left side at the position given.
void setLeft(T left)
{//! Modified by Ulf
T w = LowerRightCorner.X - UpperLeftCorner.X;
UpperLeftCorner.X = left;
LowerRightCorner.X = left + w;
}
//! (Re)Sets the rectangle so that it keeps the same dimensions, but anchors its top side at the position given.
void setTop(T top)
{//! Modified by Ulf
T h = LowerRightCorner.Y - UpperLeftCorner.Y;
UpperLeftCorner.Y = top;
LowerRightCorner.Y = top + h;
}
//! (Re)Sets the rectangle so that it keeps the same dimensions, but anchors its Lower right corner at the position given.
void setLowerRight(const position2d<T>& lowerRight)
{//! Modified by Ulf
T w = LowerRightCorner.X - UpperLeftCorner.X;
T h = LowerRightCorner.Y - UpperLeftCorner.Y;
LowerRightCorner.X = lowerRight.X;
LowerRightCorner.Y = lowerRight.Y;
UpperLeftCorner.X = lowerRight.X - w;
UpperLeftCorner.Y = lowerRight.Y - h;
}
//! (Re)Sets the rectangle so that it keeps the same dimensions, but anchors its right side at the position given.
void setRight(T right)
{//! Modified by Ulf
T w = LowerRightCorner.X - UpperLeftCorner.X;
LowerRightCorner.X = right;
UpperLeftCorner.X = right - w;
}
//! (Re)Sets the rectangle so that it keeps the same dimensions, but anchors its bottom side at the position given.
void setBottom(T bottom)
{//! Modified by Ulf
T h = LowerRightCorner.Y - UpperLeftCorner.Y;
LowerRightCorner.Y = bottom;
UpperLeftCorner.Y = bottom - h;
}
//! (Re)Sets the rectangle so that it keeps the same dimensions, but offsets its Upper left and Lower right X positions.
void offsetX(T x)
{//! Modified by Ulf
UpperLeftCorner.X += x;
LowerRightCorner.X += x;
}
//! (Re)Sets the rectangle so that it keeps the same dimensions, but offsets its Upper left and Lower right Y positions.
void offsetY(T y)
{//! Modified by Ulf
UpperLeftCorner.Y += y;
LowerRightCorner.Y += y;
}
//! (Re)Sets the rectangle so that it maintains its Upper left position, but changes its dimensions.
void setDimensions(const position2d<T>& size)
{//! Modified by Ulf
LowerRightCorner.X = UpperLeftCorner.X + size.X;
LowerRightCorner.Y = UpperLeftCorner.Y + size.Y;
}
//! (Re)Sets the rectangle so that it maintains its Upper left position, but changes its dimensions.
void setDimensions(const dimension2d<T>& size)
{//! Modified by Ulf
LowerRightCorner.X = UpperLeftCorner.X + size.Width;
LowerRightCorner.Y = UpperLeftCorner.Y + size.Height;
}
//! increases or decreases the width and height of the specified rectangle.
/** The InflateRect function adds xInflate units to the left and right ends of the rectangle and yInflate units to the top and bottom. */
void inflate(const T xInflate, const T yInflate)
{//! Modified by Ulf
UpperLeftCorner.X -= xInflate;
UpperLeftCorner.Y -= yInflate;
LowerRightCorner.X += iXShrink;
LowerRightCorner.Y += iYShrink;
}
void inflate(const position2d<T>& ptInflate)
{//! Modified by Ulf
UpperLeftCorner.X -= ptInflate.X;
UpperLeftCorner.Y -= ptInflate.Y;
LowerRightCorner.X += ptInflate.X;
LowerRightCorner.Y += ptInflate.Y;
}
//! Returns the Lower Left position.
position2d<T> getLowerLeft() const
{//! Modified by Ulf
return position2d<T>(UpperLeftCorner.X, LowerRightCorner.Y);
}
Code: Select all
//! Typedef for an f32 rect.
typedef rect<f32> rectf; //! Modified by Ulf
//! Typedef for an s32 rect.
typedef rect<s32> recti; //! Modified by Ulf