C3D Toolkit  Kernel - 117982, Vision - 2.9.2.2
VSN::RectI Class Reference

RectI class defines rectangle in the plane using integer precision. More...

#include <vsn_rect.h>

+ Collaboration diagram for VSN::RectI:

Public Member Functions

 RectI ()
 Default constructor for creating empty rectangle.
 
 RectI (const PointI &topleft, const PointI &bottomright)
 Special rectangle constructor with setting the top-left and bottom-right angle.
 
 RectI (const PointI &topleft, const SizeI &size)
 Special rectangle constructor with setting top-left angle coordinates and rectangle size.
 
 RectI (int left, int top, int width, int height)
 Special rectangle constructor with setting top-left angle coordinates and rectangle size.
 
void Init (int x, int y, int w, int h)
 Initializes the rectangle with setting top-left angle coordinates and rectangle size.
 
void InitCoords (int x1, int y1, int x2, int y2)
 Initializes the rectangle with setting top-left angle coordinates and rectangle size.
 
bool IsNull () const
 True if rectangle is empty. More...
 
bool IsEmpty () const
 True if rectangle is empty. More...
 
bool IsValid () const
 True if rectangle is valid. More...
 
int GetLeft () const
 Returns X-coordinate of the left rectangle edge. It is the equivalent of GetX() function. More...
 
int GetTop () const
 Returns Y-coordinate of the left rectangle edge. It is the equivalent of GetY() function. More...
 
int GetRight () const
 Returns X-coordinate of the right rectangle edge. More...
 
int GetBottom () const
 Returns Y-coordinate of the bottom rectangle edge. More...
 
RectI Normalized () const
 Returns normalized rectangle, i.e. the rectangle has no negative width and height. More...
 
int GetX () const
 Returns X-coordinate of the left rectangle edge. It is the equivalent of GetLeft() function. More...
 
int GetY () const
 Returns Y-coordinate of the top rectangle edge. It is the equivalent of GetTop() function. More...
 
void SetLeft (int left)
 Sets the left rectangle edge to the given X-coordinate. Changes width, but it does not change coordinate of the right rectangle edge. It is the equivalent of SetX() function.
 
void SetTop (int top)
 Sets the top rectangle edge to the given Y-coordinate. Changes height, but it does not change coordinate of the bottom rectangle edge. It is the equivalent of SetY() function.
 
void SetRight (int right)
 Sets the right rectangle edge to the given X-coordinate. Changes width, but it does not change coordinate of the left rectangle edge.
 
void SetBottom (int bottom)
 Sets the bottom rectangle edge to the given Y-coordinate. Changes height, but it does not change coordinate of the top rectangle edge.
 
void SetX (int x)
 Sets the left rectangle edge to the given X-coordinate. Changes width, but it does not change coordinate of the right rectangle edge. It is the equivalent of SetLeft() function.
 
void SetY (int y)
 Sets the top rectangle edge to the given Y-coordinate. Changes height, but it does not change coordinate of the bottom rectangle edge. It is the equivalent of SetTop() function.
 
void SetTopLeft (const PointI &p)
 Sets the top-left rectangle angle to the given position. Changes size, but it does not change the bottom-right rectangle angle.
 
void SetBottomRight (const PointI &p)
 Sets the bottom-right rectangle angle to the given position. Changes size, but it does not change the top-left rectangle angle.
 
void SetTopRight (const PointI &p)
 Sets the top-right rectangle angle to the given position. Changes size, but it does not change the bottom-left rectangle angle.
 
void SetBottomLeft (const PointI &p)
 Sets the bottom-left rectangle angle to the given position. Changes size, but it does not change the top-right rectangle angle.
 
PointI GetTopLeft () const
 Returns position of the top-left rectangle angle. More...
 
PointI GetBottomRight () const
 Returns position of the bottom-right rectangle angle. More...
 
PointI GetTopRight () const
 Returns position of the top-right rectangle angle. More...
 
PointI GetBottomLeft () const
 Returns position of the bottom-left rectangle angle. More...
 
PointI GetCenter () const
 Returns the rectangle center point. More...
 
void Offset (int dx, int dy)
 Moves the rectangle on "dx" value along X-axis and "dy" value along Y-axis. It is all about the current position.
 
void Offset (const PointI &p)
 Overloaded function. It moves the rectangle p.GetX() along X-axis and p.GetY() along Y-axis, all about the current position.
 
RectI Offseted (int dx, int dy) const
 Returns copy of the rectangle that is moved on "dx" value along X-axis and "dy" value along Y-axis, all about the current position. All positive values move the rectangle to right and down. More...
 
RectI Offseted (const PointI &p) const
 Overloaded function. It returns copy of the rectangle that is moved p.GetX() along X-axis and p.GetY() along Y-axis, all about the current position. Positive values move the rectangle to right and down. More...
 
void MoveToXY (int x, int t)
 Moves the rectangle by shifting the top-left angle at the defined position (х, у). Rectangle size is not changed.
 
void MoveToXY (const PointI &p)
 Moves the rectangle by shifting the top-left angle at the defined position.
 
void Inflate (int x1, int y1, int x2, int y2)
 Adds x1, y1, x2, and y2 values to existing rectangle coordinates.
 
RectI Inflated (int x1, int y1, int x2, int y2) const
 Returns new rectangle with x1, y1, x2, and y2 values, added to existing rectangle coordinates. More...
 
SizeI GetSize () const
 Returns rectangle size. More...
 
int GetWidth () const
 Returns rectangle width. More...
 
int GetHeight () const
 Returns rectangle height. More...
 
void SetWidth (int w)
 Sets the defined width for the rectangle by changing its right edge. The left rectangle edge is not changed.
 
void SetHeight (int h)
 Sets the defined height for the rectangle by changing its bottom edge. Top edge is not changed.
 
void SetSize (const SizeI &s)
 Sets the new size for the rectangle. Top-left angle is not moved.
 
RectI operator| (const RectI &other) const
 Returns bounding rectangle of the given rectangle and the defined rectangle. More...
 
RectI operator& (const RectI &other) const
 Returns intersection of the given rectangle and the defined rectangle. It returns empty rectangle if no intersection. More...
 
RectIoperator|= (const RectI &other)
 Union of the given rectangle with the defined rectangle.
 
RectIoperator&= (const RectI &other)
 Intersection of the given rectangle with the defined rectangle.
 
bool RectInRect (const RectI &other, bool proper=false) const
 Overloaded function. True if the defined rectangle is inside the given rectangle. True if the defined rectangle is wholly inside the given rectangle, not on the edge. More...
 
bool PntInRect (const PointI &p, bool proper=false) const
 True if the given point is inside the rectangle or on the edge. True if the given point is inside the rectangle, i.e. not on the edge. More...
 
bool PntInRect (int x, int y) const
 Overloaded function. True if point (х, у) is inside the rectangle. More...
 
bool PntInRect (int x, int y, bool proper) const
 Overloaded function. True if the given point (x, y) is inside the rectangle or on the edge. True if the given point (x, y) is inside the rectangle, i.e. not on the edge. More...
 
RectI United (const RectI &other) const
 Returns bounding rectangle of the given rectangle and the defined rectangle. More...
 
RectI Intersected (const RectI &other) const
 Returns intersection of the given rectangle and the defined rectangle. More...
 
bool Intersects (const RectI &r) const
 True if the given rectangle intersects with the defined rectangle. It means that at least one pixel, inside both rectangles, exists. More...
 
bool operator== (const RectI &)
 True if the given rectangle is equal to the specified rectangle. More...
 
bool operator!= (const RectI &)
 True if the given rectangle is different from the specified rectangle. More...
 

Static Public Attributes

static const RectI ZERO
 Zero rect.
 

Detailed Description

RectI class defines rectangle in the plane using integer precision.

Rectangle is typically expressed as top-left angle and size. Rectangle can be constructed with integer coordinates of left, top, width and height, or with PointI and SizeI classes. RectI class provides a set of functions that return necessary coordinates of the rectangle and allow initializing them. RectI class also provides functions for moving the rectangle about its coordinates, etc.

Member Function Documentation

◆ IsNull()

bool VSN::RectI::IsNull ( ) const
inline

True if rectangle is empty.

Null rectangle has width and height that equal 0, i.e. GetRight() == GetLeft() - 1 и GetBottom() == GetTop() - 1. Null rectangle is also empty and hence not valid.

Returns
True if rectangle is empty.

◆ IsEmpty()

bool VSN::RectI::IsEmpty ( ) const
inline

True if rectangle is empty.

Empty rectangle has GetLeft() > GetRight() or GetTop() > GetBottom(). Empty rectangle is not valid, i.e. IsEmpty() function value is not equal to IsValid() function value.

Note
Use Normalize() function to get regular rectangle.
Returns
True if rectangle is empty.

◆ IsValid()

bool VSN::RectI::IsValid ( ) const
inline

True if rectangle is valid.

Valid rectangle has GetLeft() < GetRight() and GetTop() < GetBottom(). Valid rectangle is not empty, i.e. IsValid() function value is not equal to IsEmpty() function value.

Note
Please note that operations like intersection are not performed if rectangle is invalid.
Returns
True if rectangle is valid.

◆ GetLeft()

int VSN::RectI::GetLeft ( ) const
inline

Returns X-coordinate of the left rectangle edge. It is the equivalent of GetX() function.

Returns
X-coordinate of the left rectangle edge.

◆ GetTop()

int VSN::RectI::GetTop ( ) const
inline

Returns Y-coordinate of the left rectangle edge. It is the equivalent of GetY() function.

Returns
Y-coordinate of the left rectangle edge.

◆ GetRight()

int VSN::RectI::GetRight ( ) const
inline

Returns X-coordinate of the right rectangle edge.

Returns
X-coordinate of the right rectangle edge.

◆ GetBottom()

int VSN::RectI::GetBottom ( ) const
inline

Returns Y-coordinate of the bottom rectangle edge.

Returns
Y-coordinate of the bottom rectangle edge.

◆ Normalized()

RectI VSN::RectI::Normalized ( ) const

Returns normalized rectangle, i.e. the rectangle has no negative width and height.

Note
If GetWidth() < 0, then function swaps the left and right angles. If GetHeight() < 0, then it swaps the top and bottom angles.
Returns
Normalized rectangle.

◆ GetX()

int VSN::RectI::GetX ( ) const
inline

Returns X-coordinate of the left rectangle edge. It is the equivalent of GetLeft() function.

Returns
X-coordinate of the left rectangle edge.

◆ GetY()

int VSN::RectI::GetY ( ) const
inline

Returns Y-coordinate of the top rectangle edge. It is the equivalent of GetTop() function.

Returns
Y-coordinate of the top rectangle edge.

◆ GetTopLeft()

PointI VSN::RectI::GetTopLeft ( ) const
inline

Returns position of the top-left rectangle angle.

Returns
Position of the top-left rectangle angle.

◆ GetBottomRight()

PointI VSN::RectI::GetBottomRight ( ) const
inline

Returns position of the bottom-right rectangle angle.

Returns
Position of the bottom-right rectangle angle.

◆ GetTopRight()

PointI VSN::RectI::GetTopRight ( ) const
inline

Returns position of the top-right rectangle angle.

Returns
Position of the top-right rectangle angle.

◆ GetBottomLeft()

PointI VSN::RectI::GetBottomLeft ( ) const
inline

Returns position of the bottom-left rectangle angle.

Returns
Position of the bottom-left rectangle angle.

◆ GetCenter()

PointI VSN::RectI::GetCenter ( ) const
inline

Returns the rectangle center point.

Returns
Rectangle center point.

◆ Offseted() [1/2]

RectI VSN::RectI::Offseted ( int  dx,
int  dy 
) const
inline

Returns copy of the rectangle that is moved on "dx" value along X-axis and "dy" value along Y-axis, all about the current position. All positive values move the rectangle to right and down.

Returns
New rectangle.

◆ Offseted() [2/2]

RectI VSN::RectI::Offseted ( const PointI p) const
inline

Overloaded function. It returns copy of the rectangle that is moved p.GetX() along X-axis and p.GetY() along Y-axis, all about the current position. Positive values move the rectangle to right and down.

Returns
New rectangle.

◆ Inflated()

RectI VSN::RectI::Inflated ( int  x1,
int  y1,
int  x2,
int  y2 
) const
inline

Returns new rectangle with x1, y1, x2, and y2 values, added to existing rectangle coordinates.

Returns
New rectangle.

◆ GetSize()

SizeI VSN::RectI::GetSize ( ) const
inline

Returns rectangle size.

Returns
Rectangle size.

◆ GetWidth()

int VSN::RectI::GetWidth ( ) const
inline

Returns rectangle width.

Returns
Rectangle width.

◆ GetHeight()

int VSN::RectI::GetHeight ( ) const
inline

Returns rectangle height.

Returns
Rectangle height.

◆ operator|()

RectI VSN::RectI::operator| ( const RectI other) const

Returns bounding rectangle of the given rectangle and the defined rectangle.

Returns
Bounding rectangle of the given rectangle and the defined rectangle.

◆ operator&()

RectI VSN::RectI::operator& ( const RectI other) const

Returns intersection of the given rectangle and the defined rectangle. It returns empty rectangle if no intersection.

Returns
Intersection of the given rectangle and the defined rectangle.

◆ RectInRect()

bool VSN::RectI::RectInRect ( const RectI other,
bool  proper = false 
) const

Overloaded function. True if the defined rectangle is inside the given rectangle. True if the defined rectangle is wholly inside the given rectangle, not on the edge.

Returns
True if the defined rectangle is inside the given rectangle.

◆ PntInRect() [1/3]

bool VSN::RectI::PntInRect ( const PointI p,
bool  proper = false 
) const

True if the given point is inside the rectangle or on the edge. True if the given point is inside the rectangle, i.e. not on the edge.

Returns
True if the given point is inside the rectangle or on the edge.

◆ PntInRect() [2/3]

bool VSN::RectI::PntInRect ( int  x,
int  y 
) const
inline

Overloaded function. True if point (х, у) is inside the rectangle.

Returns
True if point (х, у) is inside the rectangle.

◆ PntInRect() [3/3]

bool VSN::RectI::PntInRect ( int  x,
int  y,
bool  proper 
) const
inline

Overloaded function. True if the given point (x, y) is inside the rectangle or on the edge. True if the given point (x, y) is inside the rectangle, i.e. not on the edge.

Returns
True if the given point (x, y) is inside the rectangle or on the edge.

◆ United()

RectI VSN::RectI::United ( const RectI other) const

Returns bounding rectangle of the given rectangle and the defined rectangle.

Returns
Bounding rectangle of the given rectangle and the defined rectangle.

◆ Intersected()

RectI VSN::RectI::Intersected ( const RectI other) const
inline

Returns intersection of the given rectangle and the defined rectangle.

Returns
Bounding rectangle of the given rectangle and the defined rectangle.

◆ Intersects()

bool VSN::RectI::Intersects ( const RectI r) const

True if the given rectangle intersects with the defined rectangle. It means that at least one pixel, inside both rectangles, exists.

Returns
True if the given rectangle intersects with the defined rectangle.

◆ operator==()

bool VSN::RectI::operator== ( const RectI other)
inline

True if the given rectangle is equal to the specified rectangle.

Returns
True if the given rectangle is equal to the specified rectangle.

◆ operator!=()

bool VSN::RectI::operator!= ( const RectI other)
inline

True if the given rectangle is different from the specified rectangle.

Returns
True if the given rectangle is different from the specified rectangle.

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