NNRect
class NNRect
{
public:
NNRect();
NNRect(float x, float y, float width, float height);
public:
void setX(float x);
float getX();
void setY(float y);
float getY();
void setWidth(float width);
float getWidth();
void setHeight(float height);
float getHeight();
public:
virtual std::string getType();
virtual std::string toString();
virtual std::shared_ptr<NNRect> clone(bool deep);
};
Introduction to the class
Represents a rectangular area defined by its position (x, y) and dimensions (width, height).
The `NNRect` class provides methods to set and get the position and dimensions of the rectangle, as well as methods to retrieve the type of the rectangle and to generate a string representation of it. Additionally, it includes a method to clone the rectangle object, optionally performing a deep copy.
Introduction to the Class's Methods
NNRect()
brief: Default constructor. Initializes the rectangle with default values (typically zero).
NNRect(float x, float y, float width, float height)
brief: Parameterized constructor. Initializes the rectangle with the specified position and dimensions.
param
x: The x-coordinate of the top-left corner of the rectangle.
y: The y-coordinate of the top-left corner of the rectangle.
width: The width of the rectangle.
height: The height of the rectangle.
void setX(uint32_t x)
brief: Sets the x-coordinate of the top-left corner of the rectangle.
param
x: The new x-coordinate.
uint32_t getX()
brief: Gets the x-coordinate of the top-left corner of the rectangle.
return uint32_t: The x-coordinate of the top-left corner.
void setY(uint32_t y)
brief: Sets the y-coordinate of the top-left corner of the rectangle.
param
y: The new y-coordinate.
uint32_t getY()
brief: Gets the y-coordinate of the top-left corner of the rectangle.
return uint32_t: The y-coordinate of the top-left corner.
void setWidth(uint32_t width)
brief: Sets the width of the rectangle.
param
width: The new width.
uint32_t getWidth()
brief: Gets the width of the rectangle.
return uint32_t: The width of the rectangle.
void setHeight(uint32_t height)
brief: Sets the height of the rectangle.
param
height: The new height.
uint32_t getHeight()
brief: Gets the height of the rectangle.
return uint32_t: The height of the rectangle.
std::string getType()
brief: Gets the type of the rectangle.
return string: A string representing the type of the rectangle.
std::string toString()
brief: Generates a string representation of the rectangle. This method returns a string containing the position and dimensions of the rectangle.
return string: A string representation of the rectangle.
std::shared_ptr<NNRect> clone(bool deep)
brief: Clones the rectangle object. This method creates a new `NNRect` object that is a copy of the current object. If `deep` is true, a deep copy is performed (although for this simple class, a shallow copy is sufficient since there are no pointers to dynamic memory).
param
deep: If true, perform a deep copy; otherwise, perform a shallow copy.
return shared_ptr<NNRect>: A shared pointer to the cloned rectangle object.