Pepper_47_C++_interfaces
Public Member Functions | List of all members
pp::Rect Class Reference

#include <rect.h>

Collaboration diagram for pp::Rect:
Collaboration graph

Public Member Functions

 Rect ()
 
 Rect (const PP_Rect &rect)
 
 Rect (int32_t w, int32_t h)
 
 Rect (int32_t x, int32_t y, int32_t w, int32_t h)
 
 Rect (const Size &s)
 
 Rect (const Point &origin, const Size &size)
 
 ~Rect ()
 Destructor. More...
 
 operator PP_Rect () const
 
const PP_Rect & pp_rect () const
 
PP_Rect & pp_rect ()
 
int32_t x () const
 
void set_x (int32_t in_x)
 
int32_t y () const
 
void set_y (int32_t in_y)
 
int32_t width () const
 
void set_width (int32_t w)
 
int32_t height () const
 
void set_height (int32_t h)
 
Point point () const
 
void set_point (const Point &origin)
 
Size size () const
 
void set_size (const Size &s)
 
int32_t right () const
 
int32_t bottom () const
 
void SetRect (int32_t x, int32_t y, int32_t w, int32_t h)
 
void SetRect (const PP_Rect &rect)
 
void Inset (int32_t horizontal, int32_t vertical)
 
void Inset (int32_t left, int32_t top, int32_t right, int32_t bottom)
 
void Offset (int32_t horizontal, int32_t vertical)
 
void Offset (const Point &point)
 
bool IsEmpty () const
 
bool Contains (int32_t point_x, int32_t point_y) const
 
bool Contains (const Point &point) const
 
bool Contains (const Rect &rect) const
 
bool Intersects (const Rect &rect) const
 
Rect Intersect (const Rect &rect) const
 
Rect Union (const Rect &rect) const
 
Rect Subtract (const Rect &rect) const
 
Rect AdjustToFit (const Rect &rect) const
 
Point CenterPoint () const
 
bool SharesEdgeWith (const Rect &rect) const
 

Detailed Description

A 2 dimensional rectangle. A rectangle is represented by x and y (which identifies the upper-left corner of the rectangle), width, and height.

Definition at line 19 of file rect.h.

Constructor & Destructor Documentation

pp::Rect::Rect ( )
inline

The default constructor. Creates a Rect in the upper-left at 0,0 with height and width of 0.

Definition at line 24 of file rect.h.

Referenced by AdjustToFit(), Intersect(), Subtract(), and Union().

pp::Rect::Rect ( const PP_Rect &  rect)
inline

A constructor accepting a reference to a PP_Rect and converting the PP_Rect to a Rect. This is an implicit conversion constructor.

Parameters
[in]rectA PP_Rect.

Definition at line 36 of file rect.h.

References set_height(), set_width(), set_x(), and set_y().

pp::Rect::Rect ( int32_t  w,
int32_t  h 
)
inline

A constructor accepting two int32_t values for width and height and converting them to a Rect in the upper-left starting coordinate of 0,0.

Parameters
[in]wAn int32_t value representing a width.
[in]hAn int32_t value representing a height.

Definition at line 49 of file rect.h.

References set_height(), set_width(), set_x(), and set_y().

pp::Rect::Rect ( int32_t  x,
int32_t  y,
int32_t  w,
int32_t  h 
)
inline

A constructor accepting four int32_t values for width, height, x, and y.

Parameters
[in]xAn int32_t value representing a horizontal coordinate of a point, starting with 0 as the left-most coordinate.
[in]yAn int32_t value representing a vertical coordinate of a point, starting with 0 as the top-most coordinate.
[in]wAn int32_t value representing a width.
[in]hAn int32_t value representing a height.

Definition at line 64 of file rect.h.

References set_height(), set_width(), set_x(), and set_y().

pp::Rect::Rect ( const Size s)
inlineexplicit

A constructor accepting a pointer to a Size and converting the Size to a Rect in the upper-left starting coordinate of 0,0.

Parameters
[in]sA pointer to a Size.

Definition at line 76 of file rect.h.

References set_size(), set_x(), and set_y().

pp::Rect::Rect ( const Point origin,
const Size size 
)
inline

A constructor accepting a pointer to a Point representing the origin of the rectangle and a pointer to a Size representing the height and width.

Parameters
[in]originA pointer to a Point representing the upper-left starting coordinate.
[in]sizeA pointer to a Size representing the height and width.

Definition at line 90 of file rect.h.

References set_point(), and set_size().

pp::Rect::~Rect ( )
inline

Destructor.

Definition at line 96 of file rect.h.

Member Function Documentation

Rect pp::Rect::AdjustToFit ( const Rect rect) const

AdjustToFit() fits as much of the receiving rectangle within the supplied rectangle as possible, returning the result. For example, if the receiver had a x-location of 2 and a width of 4, and the supplied rectangle had an x-location of 0 with a width of 5, the returned rectangle would have an x-location of 1 with a width of 4.

Parameters
[in]rectA pointer to a Rect.
Returns
A Rect representing the difference between this rectangle and the receiving rectangle.

Definition at line 110 of file rect.cc.

References height(), Rect(), width(), x(), and y().

int32_t pp::Rect::bottom ( ) const
inline

Getter function to get the upper-bound for the y-coordinates of the rectangle. Note that this coordinate value is one past the highest xy value of pixels in the rectangle. This loop will access all the pixels in a horizontal line in the rectangle: for (int32_t y = rect.y(); y < rect.bottom(); ++y) {}

Returns
The value of y + height for this point.

Definition at line 235 of file rect.h.

References height(), and y().

Referenced by Contains(), Intersect(), Intersects(), SharesEdgeWith(), Subtract(), and Union().

Point pp::Rect::CenterPoint ( ) const

CenterPoint() determines the center of this rectangle.

Returns
A Point representing the center of this rectangle.

Definition at line 120 of file rect.cc.

References height(), width(), x(), and y().

bool pp::Rect::Contains ( int32_t  point_x,
int32_t  point_y 
) const

Contains() determines if the point identified by point_x and point_y falls inside this rectangle. The point (x, y) is inside the rectangle, but the point (x + width, y + height) is not.

Parameters
[in]point_xAn int32_t value representing a x value.
[in]point_yAn int32_t value representing a y value.
Returns
true if the point_x and point_y fall inside the rectangle.

Definition at line 38 of file rect.cc.

References bottom(), right(), x(), and y().

Referenced by Contains(), and Subtract().

bool pp::Rect::Contains ( const Point point) const
inline

Contains() determines if the specified point is contained by this rectangle.

Parameters
[in]pointA pointer to a Point representing a 2D coordinate.
Returns
true if the point_x and point_y fall inside the rectangle.

Definition at line 323 of file rect.h.

References Contains(), pp::Point::x(), and pp::Point::y().

bool pp::Rect::Contains ( const Rect rect) const

Contains() determines if this rectangle contains the specified rectangle.

Parameters
[in]rectA pointer to a Rect.
Returns
true if the rectangle fall inside this rectangle.

Definition at line 43 of file rect.cc.

References bottom(), right(), x(), and y().

int32_t pp::Rect::height ( ) const
inline

Getter function for returning the value of height.

Returns
The value of height for this Rect.

Definition at line 171 of file rect.h.

Referenced by AdjustToFit(), bottom(), CenterPoint(), Inset(), operator==(), and SharesEdgeWith().

void pp::Rect::Inset ( int32_t  horizontal,
int32_t  vertical 
)
inline

Inset() shrinks the rectangle by a horizontal and vertical distance on all sides.

Parameters
[in]horizontalAn int32_t value representing a horizontal shrinking distance.
[in]verticalAn int32_t value representing a vertical shrinking distance.

Definition at line 266 of file rect.h.

void pp::Rect::Inset ( int32_t  left,
int32_t  top,
int32_t  right,
int32_t  bottom 
)

Inset() shrinks the rectangle by the specified amount on each side.

Parameters
[in]leftAn int32_t value representing a left shrinking distance.
[in]topAn int32_t value representing a top shrinking distance.
[in]rightAn int32_t value representing a right shrinking distance.
[in]bottomAn int32_t value representing a bottom shrinking distance.

Definition at line 27 of file rect.cc.

References height(), Offset(), set_height(), set_width(), and width().

Rect pp::Rect::Intersect ( const Rect rect) const

Intersect() computes the intersection of this rectangle with the given rectangle.

Parameters
[in]rectA pointer to a Rect.
Returns
A Rect representing the intersection.

Definition at line 53 of file rect.cc.

References bottom(), Rect(), right(), x(), and y().

bool pp::Rect::Intersects ( const Rect rect) const

Intersects() determines if this rectangle intersects the specified rectangle.

Parameters
[in]rectA pointer to a Rect.
Returns
true if the rectangle intersects this rectangle.

Definition at line 48 of file rect.cc.

References bottom(), right(), x(), and y().

Referenced by Subtract().

bool pp::Rect::IsEmpty ( ) const
inline

IsEmpty() determines if the area of a rectangle is zero. Returns true if the area of the rectangle is zero.

Returns
true if the area of the rectangle is zero.

Definition at line 303 of file rect.h.

Referenced by Union().

void pp::Rect::Offset ( int32_t  horizontal,
int32_t  vertical 
)

Offset() moves the rectangle by a horizontal and vertical distance.

Parameters
[in]horizontalAn int32_t value representing a horizontal move distance.
[in]verticalAn int32_t value representing a vertical move distance.

Definition at line 33 of file rect.cc.

Referenced by Inset(), and Offset().

void pp::Rect::Offset ( const Point point)
inline

Offset() moves the rectangle by a horizontal and vertical distance.

Parameters
[in]pointA pointer to a Point representing the horizontal and vertical move distances.

Definition at line 295 of file rect.h.

References Offset(), pp::Point::x(), and pp::Point::y().

pp::Rect::operator PP_Rect ( ) const
inline

PP_Rect() allows implicit conversion of a Rect to a PP_Rect.

Returns
A Point.

Definition at line 103 of file rect.h.

Point pp::Rect::point ( ) const
inline

Getter function for returning the Point.

Returns
A Point.

Definition at line 189 of file rect.h.

const PP_Rect& pp::Rect::pp_rect ( ) const
inline

Getter function for returning the internal PP_Rect struct.

Returns
A const reference to the internal PP_Rect struct.

Definition at line 110 of file rect.h.

Referenced by pp::Graphics2D::PaintImageData(), pp::Graphics2D::Scroll(), pp::CompositorLayer::SetClipRect(), and pp::TextInputController::UpdateCaretPosition().

PP_Rect& pp::Rect::pp_rect ( )
inline

Getter function for returning the internal PP_Rect struct.

Returns
A mutable reference to the PP_Rect struct.

Definition at line 117 of file rect.h.

int32_t pp::Rect::right ( ) const
inline

Getter function to get the upper-bound for the x-coordinates of the rectangle. Note that this coordinate value is one past the highest x value of pixels in the rectangle. This loop will access all the pixels in a horizontal line in the rectangle: for (int32_t x = rect.x(); x < rect.right(); ++x) {}

Returns
The value of x + width for this point.

Definition at line 224 of file rect.h.

References width(), and x().

Referenced by Contains(), Intersect(), Intersects(), SharesEdgeWith(), Subtract(), and Union().

void pp::Rect::set_height ( int32_t  h)
inline

Setter function for setting the value of height.

Parameters
[in]hA new width height.

Definition at line 178 of file rect.h.

References PP_DCHECK.

Referenced by Inset(), Rect(), and SetRect().

void pp::Rect::set_point ( const Point origin)
inline

Setter function for setting the value of the Point.

Parameters
[in]originA Point representing the upper-left starting coordinate.

Definition at line 197 of file rect.h.

Referenced by Rect().

void pp::Rect::set_size ( const Size s)
inline

Setter function for setting the Size.

Parameters
[in]sA pointer to a Size representing the height and width.

Definition at line 212 of file rect.h.

References pp::Size::height(), and pp::Size::width().

Referenced by Rect().

void pp::Rect::set_width ( int32_t  w)
inline

Setter function for setting the value of width.

Parameters
[in]wA new width value.

Definition at line 160 of file rect.h.

References PP_DCHECK.

Referenced by Inset(), Rect(), and SetRect().

void pp::Rect::set_x ( int32_t  in_x)
inline

Setter function for setting the value of x.

Parameters
[in]in_xA new x value.

Definition at line 132 of file rect.h.

Referenced by Rect(), and SetRect().

void pp::Rect::set_y ( int32_t  in_y)
inline

Setter function for setting the value of y.

Parameters
[in]in_yA new y value.

Definition at line 146 of file rect.h.

Referenced by Rect(), and SetRect().

void pp::Rect::SetRect ( int32_t  x,
int32_t  y,
int32_t  w,
int32_t  h 
)
inline

Setter function for setting the value of the Rect.

Parameters
[in]xA new x value.
[in]yA new y value.
[in]wA new width value.
[in]hA new height value.

Definition at line 245 of file rect.h.

References set_height(), set_width(), set_x(), and set_y().

void pp::Rect::SetRect ( const PP_Rect &  rect)
inline

Setter function for setting the value of the Rect.

Parameters
[in]rectA pointer to a PP_Rect.

Definition at line 255 of file rect.h.

bool pp::Rect::SharesEdgeWith ( const Rect rect) const

SharesEdgeWith() determines if this rectangle shares an entire edge (same width or same height) with the given rectangle, and the rectangles do not overlap.

Parameters
[in]rectA pointer to a Rect.
Returns
true if this rectangle and supplied rectangle share an edge.

Definition at line 124 of file rect.cc.

References bottom(), height(), right(), width(), x(), and y().

Size pp::Rect::size ( ) const
inline

Getter function for returning the Size.

Returns
The size of the rectangle.

Definition at line 204 of file rect.h.

Rect pp::Rect::Subtract ( const Rect rect) const

Subtract() computes the rectangle resulting from subtracting rect from this Rect. If rectdoes not intersect completely in either the x or y direction, then *this is returned. If rect contains this, then an empty Rect is returned.

Parameters
[in]rectA pointer to a Rect.
Returns
A Rect representing the subtraction.

Definition at line 80 of file rect.cc.

References bottom(), Contains(), Intersects(), Rect(), right(), x(), and y().

Rect pp::Rect::Union ( const Rect rect) const

Union() computes the union of this rectangle with the given rectangle. The union is the smallest rectangle containing both rectangles.

Parameters
[in]rectA pointer to a Rect.
Returns
A Rect representing the union.

Definition at line 65 of file rect.cc.

References bottom(), IsEmpty(), Rect(), right(), x(), and y().

int32_t pp::Rect::width ( ) const
inline

Getter function for returning the value of width.

Returns
The value of width for this Rect.

Definition at line 153 of file rect.h.

Referenced by AdjustToFit(), CenterPoint(), Inset(), operator==(), right(), and SharesEdgeWith().

int32_t pp::Rect::x ( ) const
inline

Getter function for returning the value of x.

Returns
The value of x for this Point.

Definition at line 125 of file rect.h.

Referenced by AdjustToFit(), CenterPoint(), Contains(), Intersect(), Intersects(), operator==(), right(), SharesEdgeWith(), Subtract(), and Union().

int32_t pp::Rect::y ( ) const
inline

Getter function for returning the value of y.

Returns
The value of y for this Point.

Definition at line 139 of file rect.h.

Referenced by AdjustToFit(), bottom(), CenterPoint(), Contains(), Intersect(), Intersects(), operator==(), SharesEdgeWith(), Subtract(), and Union().


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