Murl::Math::Rectangle< DataType > Class Template Reference

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]

template<class DataType >
Murl::Math::Rectangle< DataType >::Rectangle ( )
inline

The default constructor.

Create an empty rectangle with the following properties:

This allowes to Include() a point in an empty rectangle which sets the lower and higher coordinates to the included point.

◆ Rectangle() [2/3]

template<class DataType >
Murl::Math::Rectangle< DataType >::Rectangle ( DataType  x1,
DataType  y1,
DataType  x2,
DataType  y2 
)
inline

Constructor to initialize a rectangle with given coordinates.

Takes care of setting the lower and higher coordinates correctly.

Parameters
x1The X coordinate of the first point.
y1The Y coordinate of the first point.
x2The X coordinate of the second point.
y2The Y coordinate of the second point.

References Murl::Math::Rectangle< DataType >::Set().

◆ Rectangle() [3/3]

template<class DataType >
template<class DataType2 >
Murl::Math::Rectangle< DataType >::Rectangle ( const Rectangle< DataType2 > &  r)
inline

The copy constructor using a rectangle of different type.

Parameters
rThe rectangle to copy.

Member Function Documentation

◆ Set() [1/2]

template<class DataType >
void Murl::Math::Rectangle< DataType >::Set ( const Rectangle< DataType > &  other)
inline

Copy the content of a source rectangle to the rectangle instance.

Parameters
otherThe 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]

template<class DataType >
void Murl::Math::Rectangle< DataType >::Set ( DataType  x1,
DataType  y1,
DataType  x2,
DataType  y2 
)
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
x1The X coordinate of the first point.
y1The Y coordinate of the first point.
x2The X coordinate of the second point.
y2The 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()

template<class DataType >
void Murl::Math::Rectangle< DataType >::SetX1 ( DataType  x1)
inline

Set the horizontal start coordinate.

This sets the coordinate without taking care about lower and higher coordinates.

Parameters
x1The X coordinate of the first point.

References Murl::Math::Rectangle< DataType >::mX1.

◆ SetY1()

template<class DataType >
void Murl::Math::Rectangle< DataType >::SetY1 ( DataType  y1)
inline

Set the vertical start coordinate.

This sets the coordinate without taking care about lower and higher coordinates.

Parameters
y1The Y coordinate of the first point.

References Murl::Math::Rectangle< DataType >::mY1.

◆ SetX2()

template<class DataType >
void Murl::Math::Rectangle< DataType >::SetX2 ( DataType  x2)
inline

Set the horizontal end coordinate.

This sets the coordinate without taking care about lower and higher coordinates.

Parameters
x2The X coordinate of the second point.

References Murl::Math::Rectangle< DataType >::mX2.

◆ SetY2()

template<class DataType >
void Murl::Math::Rectangle< DataType >::SetY2 ( DataType  y2)
inline

Set the vertical end coordinate.

This sets the coordinate without taking care about lower and higher coordinates.

Parameters
y2The Y coordinate of the second point.

References Murl::Math::Rectangle< DataType >::mY2.

◆ SetPositionAndSize()

template<class DataType >
void Murl::Math::Rectangle< DataType >::SetPositionAndSize ( DataType  x,
DataType  y,
DataType  sizeX,
DataType  sizeY 
)
inline

Set the x / y coordinate and the horizontal / vertical size of the rectangle.

Parameters
xThe X coordinate of the first point.
yThe Y coordinate of the first point.
sizeXThe horizontal size of the rectangle.
sizeYThe 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()

template<class DataType >
void Murl::Math::Rectangle< DataType >::SetSize ( DataType  sizeX,
DataType  sizeY 
)
inline

Set the horizontal and vertical size of the rectangle.

Parameters
sizeXThe horizontal size of the rectangle.
sizeYThe 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()

template<class DataType >
void Murl::Math::Rectangle< DataType >::SetSizeX ( DataType  size)
inline

Set the horizontal size of the rectangle.

Parameters
sizeThe horizontal size of the rectangle.

References Murl::Math::Rectangle< DataType >::mX1, and Murl::Math::Rectangle< DataType >::mX2.

◆ SetSizeY()

template<class DataType >
void Murl::Math::Rectangle< DataType >::SetSizeY ( DataType  size)
inline

Set the vertical size of the rectangle.

Parameters
sizeThe vertical size of the rectangle.

References Murl::Math::Rectangle< DataType >::mY1, and Murl::Math::Rectangle< DataType >::mY2.

◆ GetX1()

template<class DataType >
DataType Murl::Math::Rectangle< DataType >::GetX1 ( ) const
inline

Get the lower X coordinate.

Returns
The lower X coordinate.

References Murl::Math::Rectangle< DataType >::mX1.

◆ GetY1()

template<class DataType >
DataType Murl::Math::Rectangle< DataType >::GetY1 ( ) const
inline

Get the lower Y coordinate.

Returns
The lower Y coordinate.

References Murl::Math::Rectangle< DataType >::mY1.

◆ GetX2()

template<class DataType >
DataType Murl::Math::Rectangle< DataType >::GetX2 ( ) const
inline

Get the higher X coordinate.

Returns
The higher X coordinate.

References Murl::Math::Rectangle< DataType >::mX2.

◆ GetY2()

template<class DataType >
DataType Murl::Math::Rectangle< DataType >::GetY2 ( ) const
inline

Get the higher Y coordinate.

Returns
The higher Y coordinate.

References Murl::Math::Rectangle< DataType >::mY2.

◆ GetSizeX()

template<class DataType >
DataType Murl::Math::Rectangle< DataType >::GetSizeX ( ) const
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()

template<class DataType >
DataType Murl::Math::Rectangle< DataType >::GetSizeY ( ) const
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()

template<class DataType >
DataType Murl::Math::Rectangle< DataType >::GetArea ( ) const
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()

template<class DataType >
void Murl::Math::Rectangle< DataType >::Unite ( const Rectangle< DataType > &  other)
inline

◆ Intersect()

template<class DataType >
void Murl::Math::Rectangle< DataType >::Intersect ( const Rectangle< DataType > &  other)
inline

Intersect this rectangle with another rectangle.

Parameters
otherThe 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()

template<class DataType >
void Murl::Math::Rectangle< DataType >::Include ( DataType  x,
DataType  y 
)
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
xThe x-position of the point to include.
yThe 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()

template<class DataType >
Bool Murl::Math::Rectangle< DataType >::IsIntersecting ( const Rectangle< DataType > &  other) const
inline

Check if a given rectangle is intersecting this rectangle.

Parameters
otherThe 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()

template<class DataType >
Bool Murl::Math::Rectangle< DataType >::IsEmpty ( ) const
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]

template<class DataType >
Bool Murl::Math::Rectangle< DataType >::IsEqual ( const Rectangle< DataType > &  r) const
inline

Check if the rectangle instance is equal to a given second rectangle.

Compares all values within the default epsilon range Limits::Epsilon().

Parameters
rThe rectangle to compare.
Returns
true if equal to the compared rectangle.

◆ IsEqual() [2/2]

template<class DataType >
Bool Murl::Math::Rectangle< DataType >::IsEqual ( const Rectangle< DataType > &  r,
DataType  epsilon 
) const
inline

Check if the rectangle instance is equal to a given second rectangle.

Compares all values within a given epsilon range.

Parameters
rThe rectangle to compare.
epsilonThe 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()

template<class DataType >
String Murl::Math::Rectangle< DataType >::ToString ( ) const
inline

Friends And Related Function Documentation

◆ operator==

template<class DataType >
bool operator== ( const Rectangle< DataType > &  lhs,
const Rectangle< DataType > &  rhs 
)
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
lhsThe left hand side rectangle to compare.
rhsThe right hand side rectangle to compare.
Returns
true if all components are exactly the same.

◆ operator!=

template<class DataType >
bool operator!= ( const Rectangle< DataType > &  lhs,
const Rectangle< DataType > &  rhs 
)
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
lhsThe left hand side rectangle to compare.
rhsThe 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


Copyright © 2011-2024 Spraylight GmbH.