A rectangle class with 2D coordinates. More...
#include "murl_math_rectangle.h"
Public Types | |
using | ValueType = DataType |
The template parameter value type. | |
Public Member Functions | |
Rectangle () | |
The default constructor. More... | |
Rectangle (DataType x1, DataType y1, DataType x2, DataType y2) | |
Constructor to initialize a rectangle with given coordinates. More... | |
template<class DataType2 > | |
Rectangle (const Rectangle< DataType2 > &r) | |
The copy constructor using a rectangle of different type. More... | |
void | Set (const Rectangle &other) |
Copy the content of a source rectangle to the rectangle instance. More... | |
void | Set (DataType x1, DataType y1, DataType x2, DataType y2) |
Set all coordinates of the rectangle instance to a set of given coordinates. More... | |
void | SetX1 (DataType x1) |
Set the horizontal start coordinate. More... | |
void | SetY1 (DataType y1) |
Set the vertical start coordinate. More... | |
void | SetX2 (DataType x2) |
Set the horizontal end coordinate. More... | |
void | SetY2 (DataType y2) |
Set the vertical end coordinate. More... | |
void | SetPositionAndSize (DataType x, DataType y, DataType sizeX, DataType sizeY) |
Set the x / y coordinate and the horizontal / vertical size of the rectangle. More... | |
void | SetSize (DataType sizeX, DataType sizeY) |
Set the horizontal and vertical size of the rectangle. More... | |
void | SetSizeX (DataType size) |
Set the horizontal size of the rectangle. More... | |
void | SetSizeY (DataType size) |
Set the vertical size of the rectangle. More... | |
DataType | GetX1 () const |
Get the lower X coordinate. More... | |
DataType | GetY1 () const |
Get the lower Y coordinate. More... | |
DataType | GetX2 () const |
Get the higher X coordinate. More... | |
DataType | GetY2 () const |
Get the higher Y coordinate. More... | |
DataType | GetSizeX () const |
Get the horizontal size of the rectangle. More... | |
DataType | GetSizeY () const |
Get the vertical size of the rectangle. More... | |
DataType | GetArea () const |
Get the area occupied by the rectangle. More... | |
void | Unite (const Rectangle &other) |
Unite this rectangle with another rectangle. More... | |
void | Intersect (const Rectangle &other) |
Intersect this rectangle with another rectangle. More... | |
void | Include (DataType x, DataType y) |
Include a point in this rectangle. More... | |
Bool | IsIntersecting (const Rectangle &other) const |
Check if a given rectangle is intersecting this rectangle. More... | |
Bool | IsEmpty () const |
Check if a given rectangle is empty, i.e. More... | |
Bool | IsEqual (const Rectangle &r) const |
Check if the rectangle instance is equal to a given second rectangle. More... | |
Bool | IsEqual (const Rectangle &r, DataType epsilon) const |
Check if the rectangle instance is equal to a given second rectangle. More... | |
String | ToString () const |
Get the string representation of the object. More... | |
Protected Attributes | |
DataType | mX1 |
The lower X coordinate. | |
DataType | mY1 |
The lower Y coordinate. | |
DataType | mX2 |
The higher X coordinate. | |
DataType | mY2 |
The higher Y coordinate. | |
Friends | |
bool | operator== (const Rectangle< DataType > &lhs, const Rectangle< DataType > &rhs) |
Equal to comparison operator. More... | |
bool | operator!= (const Rectangle< DataType > &lhs, const Rectangle< DataType > &rhs) |
Not equal to comparison operator. More... | |
Detailed Description
template<class DataType>
class Murl::Math::Rectangle< DataType >
A rectangle class with 2D coordinates.
Constructor & Destructor Documentation
◆ Rectangle() [1/3]
|
inline |
The default constructor.
Create an empty rectangle with the following properties:
- The lower coordinates GetX1() and GetY1() contains the DataType's maximum value.
- The higher coordinates GetX2() and GetY2() contains the DataType's minimum value.
- In this case the dimension GetSizeX() and GetSizeY() returns zero.
This allowes to Include() a point in an empty rectangle which sets the lower and higher coordinates to the included point.
◆ Rectangle() [2/3]
|
inline |
Constructor to initialize a rectangle with given coordinates.
Takes care of setting the lower and higher coordinates correctly.
- Parameters
-
x1 The X coordinate of the first point. y1 The Y coordinate of the first point. x2 The X coordinate of the second point. y2 The Y coordinate of the second point.
References Murl::Math::Rectangle< DataType >::Set().
◆ Rectangle() [3/3]
|
inline |
The copy constructor using a rectangle of different type.
- Parameters
-
r The rectangle to copy.
Member Function Documentation
◆ Set() [1/2]
|
inline |
Copy the content of a source rectangle to the rectangle instance.
- Parameters
-
other The rectangle to copy from.
References Murl::Math::Rectangle< DataType >::mX1, Murl::Math::Rectangle< DataType >::mX2, Murl::Math::Rectangle< DataType >::mY1, and Murl::Math::Rectangle< DataType >::mY2.
Referenced by Murl::Math::Rectangle< DataType >::Rectangle().
◆ Set() [2/2]
|
inline |
Set all coordinates of the rectangle instance to a set of given coordinates.
Takes care of setting the lower and higher coordinates correctly.
- Parameters
-
x1 The X coordinate of the first point. y1 The Y coordinate of the first point. x2 The X coordinate of the second point. y2 The Y coordinate of the second point.
References Murl::Math::Rectangle< DataType >::mX1, Murl::Math::Rectangle< DataType >::mX2, Murl::Math::Rectangle< DataType >::mY1, and Murl::Math::Rectangle< DataType >::mY2.
◆ SetX1()
|
inline |
Set the horizontal start coordinate.
This sets the coordinate without taking care about lower and higher coordinates.
- Parameters
-
x1 The X coordinate of the first point.
References Murl::Math::Rectangle< DataType >::mX1.
◆ SetY1()
|
inline |
Set the vertical start coordinate.
This sets the coordinate without taking care about lower and higher coordinates.
- Parameters
-
y1 The Y coordinate of the first point.
References Murl::Math::Rectangle< DataType >::mY1.
◆ SetX2()
|
inline |
Set the horizontal end coordinate.
This sets the coordinate without taking care about lower and higher coordinates.
- Parameters
-
x2 The X coordinate of the second point.
References Murl::Math::Rectangle< DataType >::mX2.
◆ SetY2()
|
inline |
Set the vertical end coordinate.
This sets the coordinate without taking care about lower and higher coordinates.
- Parameters
-
y2 The Y coordinate of the second point.
References Murl::Math::Rectangle< DataType >::mY2.
◆ SetPositionAndSize()
|
inline |
Set the x / y coordinate and the horizontal / vertical size of the rectangle.
- Parameters
-
x The X coordinate of the first point. y The Y coordinate of the first point. sizeX The horizontal size of the rectangle. sizeY The vertical size of the rectangle.
References Murl::Math::Rectangle< DataType >::mX1, Murl::Math::Rectangle< DataType >::mX2, Murl::Math::Rectangle< DataType >::mY1, and Murl::Math::Rectangle< DataType >::mY2.
◆ SetSize()
|
inline |
Set the horizontal and vertical size of the rectangle.
- Parameters
-
sizeX The horizontal size of the rectangle. sizeY The vertical size of the rectangle.
References Murl::Math::Rectangle< DataType >::mX1, Murl::Math::Rectangle< DataType >::mX2, Murl::Math::Rectangle< DataType >::mY1, and Murl::Math::Rectangle< DataType >::mY2.
◆ SetSizeX()
|
inline |
Set the horizontal size of the rectangle.
- Parameters
-
size The horizontal size of the rectangle.
References Murl::Math::Rectangle< DataType >::mX1, and Murl::Math::Rectangle< DataType >::mX2.
◆ SetSizeY()
|
inline |
Set the vertical size of the rectangle.
- Parameters
-
size The vertical size of the rectangle.
References Murl::Math::Rectangle< DataType >::mY1, and Murl::Math::Rectangle< DataType >::mY2.
◆ GetX1()
|
inline |
Get the lower X coordinate.
- Returns
- The lower X coordinate.
References Murl::Math::Rectangle< DataType >::mX1.
◆ GetY1()
|
inline |
Get the lower Y coordinate.
- Returns
- The lower Y coordinate.
References Murl::Math::Rectangle< DataType >::mY1.
◆ GetX2()
|
inline |
Get the higher X coordinate.
- Returns
- The higher X coordinate.
References Murl::Math::Rectangle< DataType >::mX2.
◆ GetY2()
|
inline |
Get the higher Y coordinate.
- Returns
- The higher Y coordinate.
References Murl::Math::Rectangle< DataType >::mY2.
◆ GetSizeX()
|
inline |
Get the horizontal size of the rectangle.
- Returns
- The horizontal size of the rectangle or zero if the lower coordinate is greater than the higher coordinated.
References Murl::Math::Max(), Murl::Math::Rectangle< DataType >::mX1, and Murl::Math::Rectangle< DataType >::mX2.
Referenced by Murl::Math::Rectangle< DataType >::GetArea().
◆ GetSizeY()
|
inline |
Get the vertical size of the rectangle.
- Returns
- The vertical size of the rectangle or zero if the lower coordinate is greater than the higher coordinated.
References Murl::Math::Max(), Murl::Math::Rectangle< DataType >::mY1, and Murl::Math::Rectangle< DataType >::mY2.
Referenced by Murl::Math::Rectangle< DataType >::GetArea().
◆ GetArea()
|
inline |
Get the area occupied by the rectangle.
- Returns
- The area, i.e. GetSizeX() * GetSizeY();
References Murl::Math::Rectangle< DataType >::GetSizeX(), and Murl::Math::Rectangle< DataType >::GetSizeY().
Referenced by Murl::Math::Rectangle< DataType >::IsEmpty().
◆ Unite()
|
inline |
Unite this rectangle with another rectangle.
- Parameters
-
other The other rectangle to unite.
References Murl::Math::Max(), Murl::Math::Min(), Murl::Math::Rectangle< DataType >::mX1, Murl::Math::Rectangle< DataType >::mX2, Murl::Math::Rectangle< DataType >::mY1, and Murl::Math::Rectangle< DataType >::mY2.
◆ Intersect()
|
inline |
Intersect this rectangle with another rectangle.
- Parameters
-
other The other rectangle to intersect.
References Murl::Math::Max(), Murl::Math::Min(), Murl::Math::Rectangle< DataType >::mX1, Murl::Math::Rectangle< DataType >::mX2, Murl::Math::Rectangle< DataType >::mY1, and Murl::Math::Rectangle< DataType >::mY2.
◆ Include()
|
inline |
Include a point in this rectangle.
Sets the lower and higher coordinates to the included point if the rectangle is empty, see default constructor Rectangle().
- Parameters
-
x The x-position of the point to include. y The y-position of the point to include.
References Murl::Math::Max(), Murl::Math::Min(), Murl::Math::Rectangle< DataType >::mX1, Murl::Math::Rectangle< DataType >::mX2, Murl::Math::Rectangle< DataType >::mY1, and Murl::Math::Rectangle< DataType >::mY2.
◆ IsIntersecting()
|
inline |
Check if a given rectangle is intersecting this rectangle.
- Parameters
-
other The other rectangle to check.
- Returns
- true if the other rectangle is intersecting this rectangle.
References Murl::Math::Rectangle< DataType >::mX1, Murl::Math::Rectangle< DataType >::mX2, Murl::Math::Rectangle< DataType >::mY1, and Murl::Math::Rectangle< DataType >::mY2.
◆ IsEmpty()
|
inline |
Check if a given rectangle is empty, i.e.
its area is zero.
- Returns
- true if the rectangle is empty.
References Murl::Math::Rectangle< DataType >::GetArea().
◆ IsEqual() [1/2]
|
inline |
Check if the rectangle instance is equal to a given second rectangle.
Compares all values within the default epsilon range Limits::Epsilon().
- Parameters
-
r The rectangle to compare.
- Returns
- true if equal to the compared rectangle.
◆ IsEqual() [2/2]
|
inline |
Check if the rectangle instance is equal to a given second rectangle.
Compares all values within a given epsilon range.
- Parameters
-
r The rectangle to compare. epsilon The epsilon to compare.
- Returns
- true if equal to the compared rectangle.
References Murl::Math::Abs(), Murl::Math::Rectangle< DataType >::mX1, Murl::Math::Rectangle< DataType >::mX2, Murl::Math::Rectangle< DataType >::mY1, and Murl::Math::Rectangle< DataType >::mY2.
◆ ToString()
|
inline |
Get the string representation of the object.
- Returns
- The string representation of the object.
References Murl::Math::Rectangle< DataType >::mX1, Murl::Math::Rectangle< DataType >::mX2, Murl::Math::Rectangle< DataType >::mY1, Murl::Math::Rectangle< DataType >::mY2, and Murl::Util::PrintToString().
Friends And Related Function Documentation
◆ operator==
|
friend |
Equal to comparison operator.
Performs a test without an epsilon range, which can be used for detecting changes i.e. DoubleBuffer<Rectangle> class. To compare within an epsilon range use Rectangle::IsEqual().
- Parameters
-
lhs The left hand side rectangle to compare. rhs The right hand side rectangle to compare.
- Returns
- true if all components are exactly the same.
◆ operator!=
|
friend |
Not equal to comparison operator.
Performs a test without an epsilon range, which can be used for detecting changes i.e. DoubleBuffer<Rectangle> class. To compare within an epsilon range use Rectangle::IsEqual().
- Parameters
-
lhs The left hand side rectangle to compare. rhs The right hand side rectangle to compare.
- Returns
- true if all components are not exactly the same.
The documentation for this class was generated from the following files:
- murl_graph_types.h
- murl_math_rectangle.h