libpgf 7.26.45
PGF - Progressive Graphics File
Loading...
Searching...
No Matches
pgf::PGFRect Struct Reference

Rectangle. More...

#include <PGFtypes.h>

Public Member Functions

 PGFRect ()
 Standard constructor.
 PGFRect (uint32_t x, uint32_t y, uint32_t width, uint32_t height)
uint32_t Width () const
uint32_t Height () const
bool IsInside (uint32_t x, uint32_t y) const
void Offset (int32_t shiftH, int32_t shiftV)
bool operator== (const PGFRect &rect2) const
bool operator!= (const PGFRect &rect2) const

Public Attributes

uint32_t left
uint32_t top
uint32_t right
uint32_t bottom

Friends

bool Intersect (const PGFRect &rect1, const PGFRect &rect2, PGFRect &resultRect)

Detailed Description

Rectangle.

Rectangle

Author
C. Stamm

Definition at line 258 of file PGFtypes.h.

Constructor & Destructor Documentation

◆ PGFRect() [1/2]

pgf::PGFRect::PGFRect ( )
inline

Standard constructor.

Definition at line 262 of file PGFtypes.h.

263 : left(0)
264 , top(0)
265 , right(0)
266 , bottom(0)
267 {}
uint32_t top
Definition PGFtypes.h:259
uint32_t bottom
Definition PGFtypes.h:259
uint32_t right
Definition PGFtypes.h:259
uint32_t left
Definition PGFtypes.h:259

◆ PGFRect() [2/2]

pgf::PGFRect::PGFRect ( uint32_t x,
uint32_t y,
uint32_t width,
uint32_t height )
inline

Constructor

Parameters
xLeft offset
yTop offset
widthRectangle width
heightRectangle height

Definition at line 274 of file PGFtypes.h.

275 : left(x)
276 , top(y)
277 , right(x + width)
278 , bottom(y + height)
279 {}

Member Function Documentation

◆ Height()

uint32_t pgf::PGFRect::Height ( ) const
inline
Returns
Rectangle height

Definition at line 307 of file PGFtypes.h.

307{ return bottom - top; }

◆ IsInside()

bool pgf::PGFRect::IsInside ( uint32_t x,
uint32_t y ) const
inline

Test if point (x,y) is inside this rectangle (inclusive top-left edges, exclusive bottom-right edges)

Parameters
xPoint coordinate x
yPoint coordinate y
Returns
True if point (x,y) is inside this rectangle (inclusive top-left edges, exclusive bottom-right edges)

Definition at line 313 of file PGFtypes.h.

313{ return (x >= left && x < right && y >= top && y < bottom); }

◆ Offset()

void pgf::PGFRect::Offset ( int32_t shiftH,
int32_t shiftV )
inline

Moves a rect.

Parameters
rectThe rectangle.
shiftHHorizontal shift.
shiftVVertical shift.

Definition at line 321 of file PGFtypes.h.

321 {
322 left += shiftH;
323 top += shiftV;
324 right += shiftH;
325 bottom += shiftV;
326 }

◆ operator!=()

bool pgf::PGFRect::operator!= ( const PGFRect & rect2) const
inline

Definition at line 360 of file PGFtypes.h.

360 {
361 return !(*this == rect2);
362 }

◆ operator==()

bool pgf::PGFRect::operator== ( const PGFRect & rect2) const
inline

Returns true if both rectangles are equal.

Parameters
rect1A source rectangle.
rect2Another source rectangle.
Returns
A boolean, indicating whether the two rectangles are equal.

Definition at line 356 of file PGFtypes.h.

356 {
357 return (bottom == rect2.bottom && left == rect2.left && right == rect2.right && top == rect2.top);
358 }

◆ Width()

uint32_t pgf::PGFRect::Width ( ) const
inline
Returns
Rectangle width

Definition at line 304 of file PGFtypes.h.

304{ return right - left; }

◆ Intersect

bool Intersect ( const PGFRect & rect1,
const PGFRect & rect2,
PGFRect & resultRect )
friend

Calculates the intersection of two rectangles.

Parameters
rect1A source rectangle.
rect2Another source rectangle.
resultRectThe intersection rectangle.
Returns
A boolean, indicating whether the intersection was successful (shared region).

Definition at line 335 of file PGFtypes.h.

335 {
336 if ((rect1.right > rect2.left) && (rect2.right > rect1.left) &&
337 (rect1.bottom > rect2.top) && (rect2.bottom > rect1.top)) {
338
339 resultRect.left = __max(rect1.left, rect2.left);
340 resultRect.top = __max(rect1.top, rect2.top);
341 resultRect.right = __min(rect1.right, rect2.right);
342 resultRect.bottom = __min(rect1.bottom, rect2.bottom);
343 return true;
344 } else { // no intersection
345 resultRect.left = resultRect.top = resultRect.right = resultRect.bottom = 0;
346 return false;
347 }
348 }
#define __min(x, y)
#define __max(x, y)

Member Data Documentation

◆ bottom

uint32_t pgf::PGFRect::bottom

Definition at line 259 of file PGFtypes.h.

◆ left

uint32_t pgf::PGFRect::left

Definition at line 259 of file PGFtypes.h.

◆ right

uint32_t pgf::PGFRect::right

Definition at line 259 of file PGFtypes.h.

◆ top

uint32_t pgf::PGFRect::top

Definition at line 259 of file PGFtypes.h.


The documentation for this struct was generated from the following file: