PRectanglef Class Reference

Detailed Description

The PRectanglef class represents an axis-aligned rectangle with float coordinates; PRectanglef instances are immutable (thread-safe).

A rectangle is defined from one corner (minX, minY) and two lengths: width and height.

Definition at line 34 of file PRectanglef.h.

#include <PRectanglef.h>

Constructor & Destructor Documentation

◆ PRectanglef() [1/2]

PRectanglef::PRectanglef ( float  x = PMath::NaNf(),
float  y = PMath::NaNf(),
float  w = PMath::NaNf(),
float  h = PMath::NaNf() 
)
explicit

Constructs a rectangle from its (minX, minY) corner, its width and its height.

By default NaN values are used.

◆ PRectanglef() [2/2]

PRectanglef::PRectanglef ( const PRectanglef other)

Constructs a shared copy of other.

◆ ~PRectanglef()

virtual PRectanglef::~PRectanglef ( )
virtual

Destroys this object.

Member Function Documentation

◆ Bad()

static const PRectanglef& PRectanglef::Bad ( )
inlinestatic

Returns an invalid (bad) instance of PRectanglef, made of NaN values.

Definition at line 41 of file PRectanglef.h.

◆ Contains()

bool PRectanglef::Contains ( const PPoint2Df p) const

Returns true if the specified point belongs to this rectangle, false otherwise.

◆ Expand()

PRectanglef PRectanglef::Expand ( float  expandBy) const

DEPRECATED, use Expanded() instead.

Returns a new rectangle expanded on all four sides.

◆ Expanded()

PRectanglef PRectanglef::Expanded ( float  expandBy) const

Returns a new rectangle expanded on all four sides.

◆ GetArea()

float PRectanglef::GetArea ( ) const

Gets the area of this rectangle.

◆ GetCentre()

PPoint2Df PRectanglef::GetCentre ( ) const

Returns the centre point of this rectangle.

◆ GetDiceCoefficient()

float PRectanglef::GetDiceCoefficient ( const PRectanglef i_rectangle) const

Gets the diceCoefficient with another rectangle.

The dice coefficient between 2 rectangles A and B is given by:

Dice(A,B) = 2 x overlapArea(A,B) / (Area(A) + Area(B))

the returned value range is [0, 1].

◆ GetHeight()

float PRectanglef::GetHeight ( ) const

Returns the height of this rectangle.

Note: the result is always >= 0.

◆ GetOrigin()

PPoint2Df PRectanglef::GetOrigin ( ) const

Returns the origin point (x,y) of this rectangle.

◆ GetOverlapArea()

float PRectanglef::GetOverlapArea ( const PRectanglef i_rectangle) const

Gets the overlap area with another rectangle.

◆ GetSize()

PSizef PRectanglef::GetSize ( ) const

Returns the size this rectangle.

◆ GetWidth()

float PRectanglef::GetWidth ( ) const

Returns the width of this rectangle.

Note: the result is always >= 0.

◆ GetX()

float PRectanglef::GetX ( ) const

Returns the x-coordinate (column) of the top left corner of this rectangle.

◆ GetY()

float PRectanglef::GetY ( ) const

Returns the y-coordinate (row) of the top left corner of this rectangle.

◆ Intersected()

PRectanglef PRectanglef::Intersected ( const PRectanglef other) const

Returns the rectangle corresponding to the intersection of this rectangle and other.

◆ IsValid()

bool PRectanglef::IsValid ( ) const

Returns true if this rectangle is valid (no NaN) and with>0 and height>0, false otherwise.

◆ Normalized() [1/3]

PRectanglef PRectanglef::Normalized ( float  sx,
float  sy 
) const

Returns a new normalized rectangle from the specified size.

Minimum coordinates, width and height of the returned rectangle are in the range 0..1.

See also
Scaled(float,float).

◆ Normalized() [2/3]

PRectanglef PRectanglef::Normalized ( const PSizef size) const

Returns a new normalized rectangle from the specified size.

Minimum coordinates, width and height of the returned rectangle are in the range 0..1.

See also
Scaled(float,float).

◆ Normalized() [3/3]

PRectanglef PRectanglef::Normalized ( const PSizei size) const

Returns a new normalized rectangle from the specified size.

Minimum coordinates, width and height of the returned rectangle are in the range 0..1.

See also
Scaled(float,float).

◆ operator!=()

bool PRectanglef::operator!= ( const PRectanglef other) const

Returns true if this rectangle is different of other, false otherwise.

WARNING: if A = Bad() and B = Bad(), then A != B will return true, because of NaN.

◆ operator=()

PRectanglef& PRectanglef::operator= ( const PRectanglef other)

Performs a shared copy of other to this object.

◆ operator==()

bool PRectanglef::operator== ( const PRectanglef other) const

Returns true if this rectangle is the same than other, false otherwise.

WARNING: if A = Bad() and B = Bad(), then A == B will return false, because of NaN.

◆ Scaled() [1/4]

PRectanglef PRectanglef::Scaled ( float  scaleBy) const

Returns a new rectangle uniformly scaled by the given scale factor.

Both position and size are scaled. This can be useful if you have a feature rectangle in an image and then scale the image by a factor.

◆ Scaled() [2/4]

PRectanglef PRectanglef::Scaled ( float  sx,
float  sy 
) const

Returns a new rectangle scaled (can be non-uniform) by the given scale factor.

Both position and size are scaled. This can be useful if you have a rectangle in relative coordinates (values in 0..1) and you want to scale it to draw it on top of an image.

See also
Normalized(float,float)

◆ Scaled() [3/4]

PRectanglef PRectanglef::Scaled ( const PSizef size) const

Returns a new rectangle scaled (can be non-uniform) by the given scale factor.

Both position and size are scaled. This can be useful if you have a rectangle in relative coordinates (values in 0..1) and you want to scale it to draw it on top of an image.

See also
Normalized(float,float)

◆ Scaled() [4/4]

PRectanglef PRectanglef::Scaled ( const PSizei size) const

Returns a new rectangle scaled (can be non-uniform) by the given scale factor.

Both position and size are scaled. This can be useful if you have a rectangle in relative coordinates (values in 0..1) and you want to scale it to draw it on top of an image.

See also
Normalized(float,float)

◆ ToPRectanglei()

PRectanglei PRectanglef::ToPRectanglei ( ) const

Returns a PRectanglei from this rectangle.

◆ Translated() [1/2]

PRectanglef PRectanglef::Translated ( float  xTranslateBy,
float  yTranslateBy 
) const

Returns a new rectangle translated by the given vector.

The size remains unchanged. This can be useful if you have a feature rectangle in an image and then crop the image by a rectangle (x,y,w,h). Then you should translate the feature rectangle by (-x, -y).

◆ Translated() [2/2]

PRectanglef PRectanglef::Translated ( const PPoint2Df v) const

Returns a new rectangle translated by the given vector.

The size remains unchanged. This can be useful if you have a feature rectangle in an image and then crop the image by a rectangle (x,y,w,h). Then you should translate the feature rectangle by (-x, -y).