Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

otk::Rect Class Reference

#include <rect.hh>

List of all members.


Detailed Description

The Rect class defines a rectangle in the plane.

Definition at line 15 of file rect.hh.

Public Methods

 Rect (void)
 Constructs an invalid Rect.

 Rect (int x, int y, int w, int h)
 Constructs a Rect.

 Rect (const Point &location, const Point &size)
 Constructs a Rect from 2 Point objects.

 Rect (const Rect &rect)
 Constructs a Rect from another Rect.

 Rect (const XRectangle &xrect)
 Constructs a Rect from an XRectangle.

int left (void) const
 Returns the left coordinate of the Rect. Identical to Rect::x.

int top (void) const
 Returns the top coordinate of the Rect. Identical to Rect::y.

int right (void) const
 Returns the right coordinate of the Rect.

int bottom (void) const
 Returns the bottom coordinate of the Rect.

int x (void) const
 The x component of the point defining the top left corner of the Rect.

int y (void) const
 The y component of the point defining the top left corner of the Rect.

Point location () const
 Returns the Point that defines the top left corner of the rectangle.

void setX (int x)
 Sets the x coordinate of the Rect.

void setY (int y)
 Sets the y coordinate of the Rect.

void setPos (int x, int y)
 Sets the x and y coordinates of the Rect.

void setPos (const Point &location)
 Sets the x and y coordinates of the Rect.

int width (void) const
 The width of the Rect.

int height (void) const
 The height of the Rect.

Point size () const
 Returns the size of the Rect.

void setWidth (int w)
 Sets the width of the Rect.

void setHeight (int h)
 Sets the height of the Rect.

void setSize (int w, int h)
 Sets the size of the Rect.

void setSize (const Point &size)
 Sets the size of the Rect.

void setRect (int x, int y, int w, int h)
 Sets the position and size of the Rect.

void setRect (const Point &location, const Point &size)
 Sets the position and size of the Rect.

void setCoords (int l, int t, int r, int b)
 Sets the position of all 4 sides of the Rect.

void setCoords (const Point &tl, const Point &br)
 Sets the position of all 4 sides of the Rect.

bool operator== (const Rect &a)
 Determines if two Rect objects are equal.

bool operator!= (const Rect &a)
 Determines if two Rect objects are inequal.

Rect operator| (const Rect &a) const
 Returns the union of two Rect objects.

Rect operator & (const Rect &a) const
 Returns the intersection of two Rect objects.

Rect & operator|= (const Rect &a)
 Sets the Rect to the union of itself with another Rect object.

Rect & operator &= (const Rect &a)
 Sets the Rect to the intersection of itself with another Rect object.

bool valid (void) const
 Returns if the Rect is valid.

bool intersects (const Rect &a) const
 Determines if this Rect intersects another Rect.

bool contains (int x, int y) const
 Determines if this Rect contains a point.

bool contains (const Point &p) const
 Determines if this Rect contains a point.

bool contains (const Rect &a) const
 Determines if this Rect contains another Rect entirely.


Private Attributes

int _x1
 The left coordinate of the Rect.

int _y1
 The top coordinate of the Rect.

int _x2
 The right coordinate of the Rect.

int _y2
 The bottom coordinate of the Rect.


Constructor & Destructor Documentation

otk::Rect::Rect void    [inline]
 

Constructs an invalid Rect.

Definition at line 18 of file rect.hh.

References _x1, _x2, _y1, and _y2.

Referenced by setRect().

00018 : _x1(0), _y1(0), _x2(0), _y2(0) { }

otk::Rect::Rect int    x,
int    y,
int    w,
int    h
[inline]
 

Constructs a Rect.

Parameters:
x The x component of the point defining the top left corner of the rectangle
y The y component of the point defining the top left corner of the rectangle
w The width of the rectangle
h The height of the rectangle

Definition at line 28 of file rect.hh.

References _x1, _x2, _y1, and _y2.

00029     : _x1(x), _y1(y), _x2(w + x - 1), _y2(h + y - 1) { }

otk::Rect::Rect const Point   location,
const Point   size
[inline]
 

Constructs a Rect from 2 Point objects.

Parameters:
location The point defining the top left corner of the rectangle
size The width and height of the rectangle

Definition at line 35 of file rect.hh.

References _x1, _x2, _y1, _y2, size(), x(), and y().

00036     : _x1(location.x()), _y1(location.y()),
00037       _x2(size.x() + location.x() - 1), _y2(size.y() + location.y() - 1) { }

otk::Rect::Rect const Rect &    rect [inline]
 

Constructs a Rect from another Rect.

Parameters:
rect The rectangle from which to construct this new one

Definition at line 42 of file rect.hh.

References _x1, _x2, _y1, and _y2.

00043     : _x1(rect._x1), _y1(rect._y1), _x2(rect._x2), _y2(rect._y2) { }

otk::Rect::Rect const XRectangle &    xrect [inline, explicit]
 

Constructs a Rect from an XRectangle.

Definition at line 45 of file rect.hh.

References _x1, _x2, _y1, _y2, height(), width(), x(), and y().

00046     : _x1(xrect.x), _y1(xrect.y), _x2(xrect.width + xrect.x - 1),
00047       _y2(xrect.height + xrect.y - 1) { }


Member Function Documentation

int otk::Rect::bottom void    const [inline]
 

Returns the bottom coordinate of the Rect.

Definition at line 56 of file rect.hh.

References _y2.

00056 { return _y2; }

bool otk::Rect::contains const Rect &    a const
 

Determines if this Rect contains another Rect entirely.

This rectangle contains the second rectangle if it is entirely within this rectangle's boundaries.

Parameters:
a The Rect to test for containment inside of this Rect
Returns:
true if the second Rect is contained within this Rect; otherwise, false

Definition at line 145 of file rect.cc.

References _x1, _x2, _y1, and _y2.

00146 {
00147   return a._x1 >= _x1 && a._x2 <= _x2 &&
00148          a._y1 >= _y1 && a._y2 <= _y2;
00149 }

bool otk::Rect::contains const Point   p const
 

Determines if this Rect contains a point.

The rectangle contains the point if it falls within the rectangle's boundaries.

Parameters:
p The point to operate on
Returns:
true if the point is contained within this Rect; otherwise, false

Definition at line 139 of file rect.cc.

References contains(), otk::Point::x(), and otk::Point::y().

00140 {
00141   return contains(p.x(), p.y());
00142 }

bool otk::Rect::contains int    x,
int    y
const
 

Determines if this Rect contains a point.

The rectangle contains the point if it falls within the rectangle's boundaries.

Parameters:
x The x coordinate of the point to operate on
y The y coordinate of the point to operate on
Returns:
true if the point is contained within this Rect; otherwise, false

Definition at line 132 of file rect.cc.

References _x1, _x2, _y1, and _y2.

Referenced by contains().

00133 {
00134   return x >= _x1 && x <= _x2 &&
00135          y >= _y1 && y <= _y2;
00136 }

int otk::Rect::height void    const [inline]
 

The height of the Rect.

Definition at line 94 of file rect.hh.

References _y1, and _y2.

Referenced by otk::Widget::adjustHorz(), ob::Frame::adjustSize(), otk::Widget::adjustVert(), ob::Screen::changeWorkArea(), otk::Widget::configureHandler(), ob::Client::configureRequestHandler(), otk::Widget::create(), ob::Client::fullscreen(), otk::Widget::height(), otk::ScreenInfo::height(), ob::Client::internal_move(), ob::Client::internal_resize(), otk::Widget::internalResize(), ob::Client::maximize(), ob::MouseData::MouseData(), Rect(), otk::Widget::setGeometry(), otk::Widget::setWidth(), otk::Label::update(), and otk::FocusLabel::update().

00094 { return _y2 - _y1 + 1; }

bool otk::Rect::intersects const Rect &    a const
 

Determines if this Rect intersects another Rect.

The rectangles intersect if any part of them overlaps.

Parameters:
a Another Rect object to compare this Rect with
Returns:
true if the Rect objects overlap; otherwise, false

Definition at line 125 of file rect.cc.

References _x1, _x2, _y1, and _y2.

00126 {
00127   return std::max(_x1, a._x1) <= std::min(_x2, a._x2) &&
00128          std::max(_y1, a._y1) <= std::min(_y2, a._y2);
00129 }

int otk::Rect::left void    const [inline]
 

Returns the left coordinate of the Rect. Identical to Rect::x.

Definition at line 50 of file rect.hh.

References _x1.

00050 { return _x1; }

Point otk::Rect::location   const [inline]
 

Returns the Point that defines the top left corner of the rectangle.

Definition at line 63 of file rect.hh.

00063 { return Point(_x1, _y1); }

Rect otk::Rect::operator & const Rect &    a const
 

Returns the intersection of two Rect objects.

The intersection of the rectangles will consist of just the area where the two rectangles overlap.

Parameters:
a A second Rect object to form an intersection with.
Returns:
The intersection between this Rect and the one passed to the function

Definition at line 112 of file rect.cc.

References _x1, _x2, _y1, and _y2.

00113 {
00114   Rect b;
00115 
00116   b._x1 = std::max(_x1, a._x1);
00117   b._y1 = std::max(_y1, a._y1);
00118   b._x2 = std::min(_x2, a._x2);
00119   b._y2 = std::min(_y2, a._y2);
00120 
00121   return b;
00122 }

Rect& otk::Rect::operator &= const Rect &    a [inline]
 

Sets the Rect to the intersection of itself with another Rect object.

The intersection of the rectangles will consist of just the area where the two rectangles overlap.

Parameters:
a A second Rect object to form an intersection with.

Definition at line 195 of file rect.hh.

00195 { *this = *this & a; return *this; }

bool otk::Rect::operator!= const Rect &    a [inline]
 

Determines if two Rect objects are inequal.

See also:
operator==

Definition at line 163 of file rect.hh.

References operator==().

00163 { return ! operator==(a); }

bool otk::Rect::operator== const Rect &    a [inline]
 

Determines if two Rect objects are equal.

The rectangles are considered equal if they are in the same position and are the same size.

Definition at line 157 of file rect.hh.

References _x1, _x2, _y1, and _y2.

Referenced by operator!=().

00158   { return _x1 == a._x1 && _y1 == a._y1 && _x2 == a._x2 && _y2 == a._y2; }

Rect otk::Rect::operator| const Rect &    a const
 

Returns the union of two Rect objects.

The union of the rectangles will consist of the maximimum area that the two rectangles can make up.

Parameters:
a A second Rect object to form a union with.

Definition at line 99 of file rect.cc.

References _x1, _x2, _y1, and _y2.

00100 {
00101   Rect b;
00102 
00103   b._x1 = std::min(_x1, a._x1);
00104   b._y1 = std::min(_y1, a._y1);
00105   b._x2 = std::max(_x2, a._x2);
00106   b._y2 = std::max(_y2, a._y2);
00107 
00108   return b;
00109 }

Rect& otk::Rect::operator|= const Rect &    a [inline]
 

Sets the Rect to the union of itself with another Rect object.

The union of the rectangles will consist of the maximimum area that the two rectangles can make up.

Parameters:
a A second Rect object to form a union with.
Returns:
The union between this Rect and the one passed to the function

Definition at line 188 of file rect.hh.

00188 { *this = *this | a; return *this; }

int otk::Rect::right void    const [inline]
 

Returns the right coordinate of the Rect.

Definition at line 54 of file rect.hh.

References _x2.

00054 { return _x2; }

void otk::Rect::setCoords const Point   tl,
const Point   br
 

Sets the position of all 4 sides of the Rect.

Parameters:
tl The new point at the top left of the rectangle
br The new point at the bottom right of the rectangle

Definition at line 90 of file rect.cc.

References _x1, _x2, _y1, _y2, otk::Point::x(), and otk::Point::y().

00091 {
00092   _x1 = tl.x();
00093   _y1 = tl.y();
00094   _x2 = br.x();
00095   _y2 = br.y();
00096 }

void otk::Rect::setCoords int    l,
int    t,
int    r,
int    b
 

Sets the position of all 4 sides of the Rect.

Parameters:
l The new left coordinate of the rectangle
t The new top coordinate of the rectangle
r The new right coordinate of the rectangle
b The new bottom coordinate of the rectangle

Definition at line 81 of file rect.cc.

References _x1, _x2, _y1, and _y2.

00082 {
00083   _x1 = l;
00084   _y1 = t;
00085   _x2 = r;
00086   _y2 = b;
00087 }

void otk::Rect::setHeight int    h
 

Sets the height of the Rect.

Parameters:
h The new height of the rectangle

Definition at line 49 of file rect.cc.

References _y1, and _y2.

00050 {
00051   _y2 = h + _y1 - 1;
00052 }

void otk::Rect::setPos const Point   location
 

Sets the x and y coordinates of the Rect.

Parameters:
location The point defining the top left corner of the rectangle.

Definition at line 25 of file rect.cc.

References _x1, _x2, _y1, _y2, otk::Point::x(), and otk::Point::y().

00026 {
00027   _x2 += location.x() - _x1;
00028   _x1 = location.x();
00029   _y2 += location.y() - _y1;
00030   _y1 = location.y();
00031 }

void otk::Rect::setPos int    x,
int    y
 

Sets the x and y coordinates of the Rect.

Parameters:
x The new x component of the point defining the top left corner of the rectangle
y The new y component of the point defining the top left corner of the rectangle

Definition at line 34 of file rect.cc.

References _x1, _x2, _y1, and _y2.

Referenced by ob::Client::internal_move(), otk::Widget::move(), ob::Client::toggleClientBorder(), and ob::Client::updateNormalHints().

00035 {
00036   _x2 += x - _x1;
00037   _x1 = x;
00038   _y2 += y - _y1;
00039   _y1 = y;
00040 }

void otk::Rect::setRect const Point   location,
const Point   size
 

Sets the position and size of the Rect.

Parameters:
location The new point defining the top left corner of the rectangle
size The new size of the rectangle

Definition at line 75 of file rect.cc.

References Rect().

00076 {
00077   *this = Rect(location, size);
00078 }

void otk::Rect::setRect int    x,
int    y,
int    w,
int    h
 

Sets the position and size of the Rect.

Parameters:
x The new x component of the point defining the top left corner of the rectangle
y The new y component of the point defining the top left corner of the rectangle
w The new width of the rectangle
h The new height of the rectangle

Definition at line 69 of file rect.cc.

References Rect().

Referenced by ob::Screen::calcArea(), otk::Widget::create(), and ob::Client::getArea().

00070 {
00071   *this = Rect(x, y, w, h);
00072 }

void otk::Rect::setSize const Point   size
 

Sets the size of the Rect.

Parameters:
size The new size of the rectangle

Definition at line 62 of file rect.cc.

References _x1, _x2, _y1, _y2, otk::Point::x(), and otk::Point::y().

00063 {
00064   _x2 = size.x() + _x1 - 1;
00065   _y2 = size.y() + _y1 - 1;
00066 }

void otk::Rect::setSize int    w,
int    h
 

Sets the size of the Rect.

Parameters:
w The new width of the rectangle
h The new height of the rectangle

Definition at line 55 of file rect.cc.

References _x1, _x2, _y1, and _y2.

Referenced by otk::Widget::configureHandler(), ob::Client::internal_resize(), and otk::ScreenInfo::ScreenInfo().

00056 {
00057   _x2 = w + _x1 - 1;
00058   _y2 = h + _y1 - 1;
00059 }

void otk::Rect::setWidth int    w
 

Sets the width of the Rect.

Parameters:
w The new width of the rectangle

Definition at line 43 of file rect.cc.

References _x1, and _x2.

00044 {
00045   _x2 = w + _x1 - 1;
00046 }

void otk::Rect::setX int    x
 

Sets the x coordinate of the Rect.

Parameters:
x The new x component of the point defining the top left corner of the rectangle

Definition at line 11 of file rect.cc.

References _x1, and _x2.

00012 {
00013   _x2 += x - _x1;
00014   _x1 = x;
00015 }

void otk::Rect::setY int    y
 

Sets the y coordinate of the Rect.

Parameters:
y The new y component of the point defining the top left corner of the rectangle

Definition at line 18 of file rect.cc.

References _y1, and _y2.

00019 {
00020   _y2 += y - _y1;
00021   _y1 = y;
00022 }

Point otk::Rect::size   const [inline]
 

Returns the size of the Rect.

Definition at line 96 of file rect.hh.

Referenced by Rect(), and otk::Widget::render().

00096 { return Point(_x2 - _x1 + 1, _y2 - _y1 + 1); }

int otk::Rect::top void    const [inline]
 

Returns the top coordinate of the Rect. Identical to Rect::y.

Definition at line 52 of file rect.hh.

References _y1.

00052 { return _y1; }

bool otk::Rect::valid void    const [inline]
 

Returns if the Rect is valid.

A rectangle is valid only if its right and bottom coordinates are larger than its left and top coordinates (i.e. it does not have a negative width or height).

Returns:
true if the Rect is valid; otherwise, false

Definition at line 204 of file rect.hh.

References _x1, _x2, _y1, and _y2.

00204 { return _x2 > _x1 && _y2 > _y1; }

int otk::Rect::width void    const [inline]
 

The width of the Rect.

Definition at line 92 of file rect.hh.

References _x1, and _x2.

Referenced by otk::Widget::adjustHorz(), ob::Frame::adjustSize(), otk::Widget::adjustVert(), ob::Screen::changeWorkArea(), otk::Widget::configureHandler(), ob::Client::configureRequestHandler(), otk::Widget::create(), ob::Client::fullscreen(), ob::Client::internal_move(), ob::Client::internal_resize(), otk::Widget::internalResize(), ob::Client::maximize(), ob::MouseData::MouseData(), Rect(), otk::Widget::setGeometry(), otk::Widget::setHeight(), otk::Label::update(), otk::FocusLabel::update(), otk::Widget::width(), and otk::ScreenInfo::width().

00092 { return _x2 - _x1 + 1; }

int otk::Rect::x void    const [inline]
 

The x component of the point defining the top left corner of the Rect.

Definition at line 59 of file rect.hh.

References _x1.

Referenced by otk::Widget::adjustHorz(), ob::Frame::adjustPosition(), ob::Screen::changeWorkArea(), ob::Client::configureRequestHandler(), otk::Widget::create(), ob::Client::fullscreen(), ob::Client::internal_resize(), ob::Client::maximize(), ob::MouseData::MouseData(), Rect(), ob::Frame::releaseClient(), otk::Widget::resize(), otk::Widget::setGeometry(), otk::Widget::setHeight(), otk::Widget::setWidth(), and ob::Client::toggleClientBorder().

00059 { return _x1; }

int otk::Rect::y void    const [inline]
 

The y component of the point defining the top left corner of the Rect.

Definition at line 61 of file rect.hh.

References _y1.

Referenced by ob::Frame::adjustPosition(), otk::Widget::adjustVert(), ob::Screen::changeWorkArea(), ob::Client::configureRequestHandler(), otk::Widget::create(), ob::Client::fullscreen(), ob::Client::internal_resize(), ob::Client::maximize(), ob::MouseData::MouseData(), Rect(), ob::Frame::releaseClient(), otk::Widget::resize(), otk::Widget::setGeometry(), otk::Widget::setHeight(), otk::Widget::setWidth(), and ob::Client::toggleClientBorder().

00061 { return _y1; }


Member Data Documentation

int otk::Rect::_x1 [private]
 

The left coordinate of the Rect.

Definition at line 242 of file rect.hh.

Referenced by contains(), intersects(), left(), operator &(), operator==(), operator|(), Rect(), setCoords(), setPos(), setSize(), setWidth(), setX(), valid(), width(), and x().

int otk::Rect::_x2 [private]
 

The right coordinate of the Rect.

Definition at line 246 of file rect.hh.

Referenced by contains(), intersects(), operator &(), operator==(), operator|(), Rect(), right(), setCoords(), setPos(), setSize(), setWidth(), setX(), valid(), and width().

int otk::Rect::_y1 [private]
 

The top coordinate of the Rect.

Definition at line 244 of file rect.hh.

Referenced by contains(), height(), intersects(), operator &(), operator==(), operator|(), Rect(), setCoords(), setHeight(), setPos(), setSize(), setY(), top(), valid(), and y().

int otk::Rect::_y2 [private]
 

The bottom coordinate of the Rect.

Definition at line 248 of file rect.hh.

Referenced by bottom(), contains(), height(), intersects(), operator &(), operator==(), operator|(), Rect(), setCoords(), setHeight(), setPos(), setSize(), setY(), and valid().


The documentation for this class was generated from the following files:
Generated on Tue Feb 4 23:00:28 2003 for Openbox by doxygen1.3-rc2