Struct Rect

Struct Documentation

struct Rect

Rect structure

x,y coordinates together with width and height that define a rectangle. Can be either normalized [0,1] or absolute representation.

Public Functions

Rect() = default
inline Rect(float x, float y, float width, float height)

Construct Rectangle from (x, y) coordinates of the top-left corner, width and height.

inline Rect(float x, float y, float width, float height, bool normalized)

Construct Rectangle from (x, y) coordinates of the top-left corner, width, height and normalization flag.

Parameters:
  • x – Top-left x coordinate

  • y – Top-left y coordinate

  • width – Width of the rectangle

  • height – Height of the rectangle

  • normalized – Whether the rectangle is normalized (coordinates in [0,1] range) or not

inline Rect(const Rect &r)

Copy constructor

inline Rect(const Point2f &org, const Size2f &sz)

Construct Rectangle from top left point and size

inline Rect(const Point2f &org, const Size2f &sz, bool normalized)

Construct Rectangle from top left point, size and normalization flag.

Note

: if normalized is true, the coordinates are in [0,1] range

inline Rect(const Point2f &pt1, const Point2f &pt2)

Construct Rectangle between any two given points. Constructor will determine top-left and bottom-right points.

Parameters:
  • pt1 – First point

  • pt2 – Second point

inline Rect(const Point2f &pt1, const Point2f &pt2, bool normalized)

Construct Rectangle between any two given points with normalization flag. Constructor will determine top-left and bottom-right points.

Parameters:
  • pt1 – First point

  • pt2 – Second point

  • normalized – Whether the rectangle is normalized (coordinates in [0,1] range) or not

Rect &operator=(const Rect &r) = default
Rect &operator=(Rect &&r) = default
inline Point2f topLeft() const

The top-left corner.

inline Point2f bottomRight() const

The bottom-right corner

inline Size2f size() const

Size (width, height) of the rectangle

inline float area() const

Area (width*height) of the rectangle

inline bool empty() const

True if rectangle is empty.

inline bool contains(const Point2f &pt) const

Checks whether the rectangle contains the point.

inline bool isNormalized() const

Whether rectangle is normalized (coordinates in [0,1] range) or not.

inline Rect denormalize(int destWidth, int destHeight) const

Denormalize rectangle.

Parameters:
  • destWidth – Destination frame width.

  • destHeight – Destination frame height.

inline Rect normalize(int srcWidth, int srcHeight) const

Normalize rectangle.

Parameters:
  • srcWidth – Source frame width.

  • srcHeight – Source frame height.

Public Members

float x = 0.0f
float y = 0.0f
float width = 0.0f
float height = 0.0f
bool normalized = false
bool hasNormalized = false