Public Member Functions

QwtDoubleRect Class Reference

#include <qwt_double_rect.h>

Inheritance diagram for QwtDoubleRect:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 QwtDoubleRect ()
 Constructs an rectangle with all components set to 0.0.
 QwtDoubleRect (double left, double top, double width, double height)
 QwtDoubleRect (const QwtDoublePoint &, const QwtDoubleSize &)
 QwtDoubleRect (const QRect &)
QRect toRect () const
bool isNull () const
bool isEmpty () const
bool isValid () const
QwtDoubleRect normalized () const
double x () const
 Returns x.
double y () const
 Returns y.
double left () const
 Returns left.
double right () const
 Returns right.
double top () const
 Returns top.
double bottom () const
 Returns bottom.
void setX (double)
 Set left.
void setY (double)
 Set left.
void setLeft (double)
 Set left.
void setRight (double)
 Set right.
void setTop (double)
 Set top.
void setBottom (double)
 Set bottom.
QwtDoublePoint center () const
 Returns the center point of the rectangle.
void moveLeft (double x)
 moves x1() to x, leaving the size unchanged
void moveRight (double x)
 moves x1() to x, leaving the size unchanged
void moveTop (double y)
 moves y1() to y, leaving the size unchanged
void moveBottom (double y)
 moves y1() to y, leaving the size unchanged
void moveTo (double x, double y)
 moves left() to x and top() to y, leaving the size unchanged
void moveTo (const QwtDoublePoint &)
void moveBy (double dx, double dy)
 moves x1() by dx and y1() by dy. leaving the size unchanged
void moveCenter (const QwtDoublePoint &)
 moves the center to pos, leaving the size unchanged
void moveCenter (double dx, double dy)
 moves the center to (x, y), leaving the size unchanged
void setRect (double x1, double x2, double width, double height)
double width () const
 Returns the width.
double height () const
 Returns the height.
QwtDoubleSize size () const
 Returns the size.
void setWidth (double w)
 Set the width, by right = left + w;.
void setHeight (double h)
 Set the height, by bottom = top + h;.
void setSize (const QwtDoubleSize &)
QwtDoubleRect operator| (const QwtDoubleRect &r) const
QwtDoubleRect operator& (const QwtDoubleRect &r) const
QwtDoubleRectoperator|= (const QwtDoubleRect &r)
 Unites this rectangle with rectangle other.
QwtDoubleRectoperator&= (const QwtDoubleRect &r)
 Intersects this rectangle with rectangle other.
bool operator== (const QwtDoubleRect &) const
 Returns true if this rect and other are equal; otherwise returns false.
bool operator!= (const QwtDoubleRect &) const
 Returns true if this rect and other are different; otherwise returns false.
bool contains (const QwtDoublePoint &p, bool proper=false) const
bool contains (double x, double y, bool proper=false) const
bool contains (const QwtDoubleRect &r, bool proper=false) const
QwtDoubleRect unite (const QwtDoubleRect &) const
QwtDoubleRect intersect (const QwtDoubleRect &) const
bool intersects (const QwtDoubleRect &) const
QwtDoublePoint bottomRight () const
QwtDoublePoint topRight () const
QwtDoublePoint topLeft () const
QwtDoublePoint bottomLeft () const

Detailed Description

The QwtDoubleRect class defines a size in double coordinates.

Definition at line 142 of file qwt_double_rect.h.


Constructor & Destructor Documentation

QwtDoubleRect::QwtDoubleRect (  )

Constructs an rectangle with all components set to 0.0.

Definition at line 301 of file qwt_double_rect.cpp.

Referenced by operator&(), and operator|().

                            :
    d_left(0.0),
    d_right(0.0),
    d_top(0.0),
    d_bottom(0.0)
{
}
QwtDoubleRect::QwtDoubleRect ( double  left,
double  top,
double  width,
double  height 
)

Constructs an rectangle with x1 to x2 as x-range and, y1 to y2 as y-range.

Definition at line 313 of file qwt_double_rect.cpp.

                                    :
    d_left(left),
    d_right(left + width),
    d_top(top),
    d_bottom(top + height)
{
}
QwtDoubleRect::QwtDoubleRect ( const QwtDoublePoint p,
const QwtDoubleSize size 
)

Constructs a rectangle with topLeft as the top-left corner and size as the rectangle size.

Definition at line 326 of file qwt_double_rect.cpp.

                                                           :
    d_left(p.x()),
    d_right(p.x() + size.width()),
    d_top(p.y()),
    d_bottom(p.y() + size.height())
{
}
QwtDoubleRect::QwtDoubleRect ( const QRect &  rect )

Definition at line 335 of file qwt_double_rect.cpp.

                                             :
    d_left(rect.left()),
    d_right(rect.right()),
    d_top(rect.top()),
    d_bottom(rect.bottom())
{
}

Member Function Documentation

double QwtDoubleRect::bottom (  ) const [inline]
QwtDoublePoint QwtDoubleRect::bottomLeft (  ) const [inline]

Definition at line 493 of file qwt_double_rect.h.

References bottom(), and left().

{
    return QwtDoublePoint(bottom(), left());
}
QwtDoublePoint QwtDoubleRect::bottomRight (  ) const [inline]

Definition at line 478 of file qwt_double_rect.h.

References bottom(), and right().

{
    return QwtDoublePoint(bottom(), right());
}
QwtDoublePoint QwtDoubleRect::center (  ) const

Returns the center point of the rectangle.

Definition at line 499 of file qwt_double_rect.cpp.

Referenced by QwtPlotZoomer::end().

{
    return QwtDoublePoint(d_left + (d_right - d_left) / 2.0, 
        d_top + (d_bottom - d_top) / 2.0);
}
bool QwtDoubleRect::contains ( double  x,
double  y,
bool  proper = false 
) const

Returns true if the point (x, y) is inside or on the edge of the rectangle; otherwise returns false.

If proper is true, this function returns true only if p is inside (not on the edge).

Definition at line 512 of file qwt_double_rect.cpp.

{
    if ( proper )
        return x > d_left && x < d_right && y > d_top && y < d_bottom;
    else
        return x >= d_left && x <= d_right && y >= d_top && y <= d_bottom;
}
bool QwtDoubleRect::contains ( const QwtDoubleRect other,
bool  proper = false 
) const

Returns true if the rectangle other is inside this rectangle; otherwise returns false.

If proper is true, this function returns true only if other is entirely inside (not on the edge).

Definition at line 539 of file qwt_double_rect.cpp.

References contains().

{
    return contains(other.d_left, other.d_top, proper) && 
        contains(other.d_right, other.d_bottom, proper);
}
bool QwtDoubleRect::contains ( const QwtDoublePoint p,
bool  proper = false 
) const

Returns true if the point p is inside or on the edge of the rectangle; otherwise returns false.

If proper is true, this function returns true only if p is inside (not on the edge).

Definition at line 527 of file qwt_double_rect.cpp.

References QwtDoublePoint::x(), and QwtDoublePoint::y().

Referenced by QwtPolygonClipperF::clipPolygon(), contains(), and QwtPlotSvgItem::draw().

{
    return contains(p.x(), p.y(), proper);
}
double QwtDoubleRect::height (  ) const [inline]

Returns the height.

Definition at line 446 of file qwt_double_rect.h.

Referenced by QwtPlotZoomer::move(), moveBottom(), moveCenter(), moveTop(), QwtPlotSvgItem::render(), QwtPlotSpectrogram::renderImage(), setRect(), size(), and toRect().

{ 
    return  d_bottom - d_top; 
}
QwtDoubleRect QwtDoubleRect::intersect ( const QwtDoubleRect other ) const

Returns the intersection of this rectangle and rectangle other. r.intersect(s) is equivalent to r&s.

Definition at line 415 of file qwt_double_rect.cpp.

{
    return *this & other;
}
bool QwtDoubleRect::intersects ( const QwtDoubleRect other ) const

Returns true if this rectangle intersects with rectangle other; otherwise returns false.

Definition at line 424 of file qwt_double_rect.cpp.

References qwtMax, and qwtMin.

{
    return ( qwtMax(d_left, other.d_left) <= qwtMin(d_right, other.d_right) ) &&
         ( qwtMax(d_top, other.d_top ) <= qwtMin(d_bottom, other.d_bottom) );
}
bool QwtDoubleRect::isEmpty (  ) const [inline]

Returns true if the rectangle is empty; otherwise returns false. An empty rectangle has a width() <= 0 or height() <= 0. An empty rectangle is not valid. isEmpty() == !isValid()

See also:
isNull(), isValid()

Definition at line 349 of file qwt_double_rect.h.

Referenced by operator|(), and QwtPlotSpectrogram::renderImage().

{ 
    return d_left >= d_right || d_top >= d_bottom; 
}
bool QwtDoubleRect::isNull (  ) const [inline]

Returns true if the rectangle is a null rectangle; otherwise returns false. A null rectangle has both the width and the height set to 0. A null rectangle is also empty and invalid.

See also:
isEmpty(), isValid()

Definition at line 337 of file qwt_double_rect.h.

Referenced by operator&().

{ 
    return d_right == d_left && d_bottom == d_top;
}
bool QwtDoubleRect::isValid (  ) const [inline]

Returns true if the rectangle is valid; otherwise returns false. A valid rectangle has a width() > 0 and height() > 0. Note that non-trivial operations like intersections are not defined for invalid rectangles. isValid() == !isEmpty()

See also:
isNull(), isEmpty(), and normalized().

Definition at line 362 of file qwt_double_rect.h.

Referenced by QmitkHistogram::boundingRect(), QwtPlotSvgItem::draw(), QwtPlotSpectrogram::draw(), QwtPlotSvgItem::render(), and QwtPlotSvgItem::viewBox().

{ 
    return d_left < d_right && d_top < d_bottom; 
}
double QwtDoubleRect::left (  ) const [inline]
void QwtDoubleRect::moveBottom ( double  y )

moves y1() to y, leaving the size unchanged

Definition at line 570 of file qwt_double_rect.cpp.

References height(), and y().

{
    const double h = height();
    d_bottom = y;
    d_top = d_bottom - h;
}
void QwtDoubleRect::moveBy ( double  dx,
double  dy 
)

moves x1() by dx and y1() by dy. leaving the size unchanged

Definition at line 585 of file qwt_double_rect.cpp.

{
    d_left += dx;
    d_right += dx;
    d_top += dy;
    d_bottom += dy;
}
void QwtDoubleRect::moveCenter ( const QwtDoublePoint pos )

moves the center to pos, leaving the size unchanged

Definition at line 594 of file qwt_double_rect.cpp.

References QwtDoublePoint::x(), and QwtDoublePoint::y().

Referenced by QwtPlotZoomer::end().

{
    moveCenter(pos.x(), pos.y());
}
void QwtDoubleRect::moveCenter ( double  dx,
double  dy 
)

moves the center to (x, y), leaving the size unchanged

Definition at line 600 of file qwt_double_rect.cpp.

References height(), moveTo(), and width().

{
    moveTo(x - width() / 2.0, y - height() / 2.0);
}
void QwtDoubleRect::moveLeft ( double  x )

moves x1() to x, leaving the size unchanged

Definition at line 546 of file qwt_double_rect.cpp.

References width(), and x().

Referenced by moveTo().

{
    const double w = width();
    d_left = x;
    d_right = d_left + w;
}
void QwtDoubleRect::moveRight ( double  x )

moves x1() to x, leaving the size unchanged

Definition at line 554 of file qwt_double_rect.cpp.

References width(), and x().

{
    const double w = width();
    d_right = x;
    d_left = d_right - w;
}
void QwtDoubleRect::moveTo ( double  x,
double  y 
)

moves left() to x and top() to y, leaving the size unchanged

Definition at line 578 of file qwt_double_rect.cpp.

References moveLeft(), and moveTop().

Referenced by moveCenter(), and moveTo().

{
    moveLeft(x);
    moveTop(y);
}
void QwtDoubleRect::moveTo ( const QwtDoublePoint p ) [inline]

Moves the top left corner of the rectangle to p, without changing the rectangles size.

Definition at line 473 of file qwt_double_rect.h.

References moveTo(), QwtDoublePoint::x(), and QwtDoublePoint::y().

{
    moveTo(p.x(), p.y());
}
void QwtDoubleRect::moveTop ( double  y )

moves y1() to y, leaving the size unchanged

Definition at line 562 of file qwt_double_rect.cpp.

References height(), and y().

Referenced by moveTo().

{
    const double h = height();
    d_top = y;
    d_bottom = d_top + h;
}
QwtDoubleRect QwtDoubleRect::normalized (  ) const

Returns a normalized rectangle, i.e. a rectangle that has a non-negative width and height.

It swaps x1 and x2 if x1() > x2(), and swaps y1 and y2 if y1() > y2().

Definition at line 376 of file qwt_double_rect.cpp.

Referenced by QwtPlotZoomer::end(), QwtPlotItem::invTransform(), operator&(), QwtPlotPicker::scaleRect(), and QwtPlotZoomer::zoom().

{
    QwtDoubleRect r;
    if ( d_right < d_left ) 
    {
        r.d_left = d_right;
        r.d_right = d_left;
    } 
    else 
    {
        r.d_left = d_left;
        r.d_right = d_right; 
    }
    if ( d_bottom < d_top ) 
    { 
        r.d_top = d_bottom; 
        r.d_bottom = d_top;
    } 
    else 
    {
        r.d_top = d_top;
        r.d_bottom = d_bottom;
    }
    return r;
}
bool QwtDoubleRect::operator!= ( const QwtDoubleRect other ) const

Returns true if this rect and other are different; otherwise returns false.

Definition at line 438 of file qwt_double_rect.cpp.

References operator==().

{
    return !operator==(other);
}
QwtDoubleRect QwtDoubleRect::operator& ( const QwtDoubleRect other ) const

Returns the intersection of this rectangle and rectangle other. Returns an empty rectangle if there is no intersection.

Definition at line 468 of file qwt_double_rect.cpp.

References bottom(), isNull(), left(), normalized(), QwtDoubleRect(), qwtMax, qwtMin, right(), and top().

{
    if (isNull() || other.isNull())
        return QwtDoubleRect();

    const QwtDoubleRect r1 = normalized();
    const QwtDoubleRect r2 = other.normalized();

    const double minX = qwtMax(r1.left(), r2.left());
    const double maxX = qwtMin(r1.right(), r2.right());
    const double minY = qwtMax(r1.top(), r2.top());
    const double maxY = qwtMin(r1.bottom(), r2.bottom());

    return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY);
}
QwtDoubleRect & QwtDoubleRect::operator&= ( const QwtDoubleRect r )

Intersects this rectangle with rectangle other.

Definition at line 492 of file qwt_double_rect.cpp.

{
    *this = *this & other;
    return *this;
}
bool QwtDoubleRect::operator== ( const QwtDoubleRect other ) const

Returns true if this rect and other are equal; otherwise returns false.

Definition at line 431 of file qwt_double_rect.cpp.

Referenced by operator!=().

{
    return d_left == other.d_left && d_right == other.d_right && 
        d_top == other.d_top && d_bottom == other.d_bottom;
}
QwtDoubleRect QwtDoubleRect::operator| ( const QwtDoubleRect other ) const

Returns the bounding rectangle of this rectangle and rectangle other. The bounding rectangle of a nonempty rectangle and an empty or invalid rectangle is defined to be the nonempty rectangle.

Definition at line 448 of file qwt_double_rect.cpp.

References isEmpty(), QwtDoubleRect(), qwtMax, and qwtMin.

{
    if ( isEmpty() ) 
        return other;

    if ( other.isEmpty() ) 
        return *this;
        
    const double minX = qwtMin(d_left, other.d_left);
    const double maxX = qwtMax(d_right, other.d_right);
    const double minY = qwtMin(d_top, other.d_top);
    const double maxY = qwtMax(d_bottom, other.d_bottom);

    return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY);
}
QwtDoubleRect & QwtDoubleRect::operator|= ( const QwtDoubleRect r )

Unites this rectangle with rectangle other.

Definition at line 485 of file qwt_double_rect.cpp.

{
    *this = *this | other;
    return *this;
}
double QwtDoubleRect::right (  ) const [inline]
void QwtDoubleRect::setBottom ( double  y ) [inline]

Set bottom.

Definition at line 434 of file qwt_double_rect.h.

References y().

Referenced by QmitkHistogram::boundingRect().

{ 
    d_bottom = y;
}
void QwtDoubleRect::setHeight ( double  h ) [inline]

Set the height, by bottom = top + h;.

Definition at line 464 of file qwt_double_rect.h.

Referenced by setSize().

{
    d_bottom = d_top + h;
}
void QwtDoubleRect::setLeft ( double  x ) [inline]

Set left.

Definition at line 416 of file qwt_double_rect.h.

References x().

{ 
    d_left = x;
}
void QwtDoubleRect::setRect ( double  left,
double  top,
double  width,
double  height 
)

Set the x-range from x1 to x2 and the y-range from y1 to y2.

Definition at line 351 of file qwt_double_rect.cpp.

References height(), left(), top(), and width().

{
    d_left = left;
    d_right = left + width;
    d_top = top;
    d_bottom = top + height;
}
void QwtDoubleRect::setRight ( double  x ) [inline]

Set right.

Definition at line 422 of file qwt_double_rect.h.

References x().

{ 
    d_right = x;
}
void QwtDoubleRect::setSize ( const QwtDoubleSize size )

Sets the size of the rectangle to size. Changes x2 and y2 only.

Definition at line 364 of file qwt_double_rect.cpp.

References QwtDoubleSize::height(), setHeight(), setWidth(), and QwtDoubleSize::width().

Referenced by QwtPlotZoomer::end().

{
    setWidth(size.width());
    setHeight(size.height());
}
void QwtDoubleRect::setTop ( double  y ) [inline]

Set top.

Definition at line 428 of file qwt_double_rect.h.

References y().

Referenced by QmitkHistogram::boundingRect().

{ 
    d_top = y;
}
void QwtDoubleRect::setWidth ( double  w ) [inline]

Set the width, by right = left + w;.

Definition at line 458 of file qwt_double_rect.h.

Referenced by QwtPlot::print(), QwtPlot::printCanvas(), and setSize().

{
    d_right = d_left + w;
}
void QwtDoubleRect::setX ( double  x ) [inline]

Set left.

Definition at line 404 of file qwt_double_rect.h.

References x().

{ 
    d_left = x;
}
void QwtDoubleRect::setY ( double  y ) [inline]

Set left.

Definition at line 410 of file qwt_double_rect.h.

References y().

{ 
    d_top = y;
}
QwtDoubleSize QwtDoubleRect::size (  ) const [inline]

Returns the size.

Definition at line 452 of file qwt_double_rect.h.

References height(), and width().

Referenced by QwtPlotZoomer::end(), and QwtPlotSpectrogram::renderImage().

{ 
    return QwtDoubleSize(width(), height());
}
double QwtDoubleRect::top (  ) const [inline]
QwtDoublePoint QwtDoubleRect::topLeft (  ) const [inline]

Definition at line 488 of file qwt_double_rect.h.

References left(), and top().

{
    return QwtDoublePoint(top(), left());
}
QwtDoublePoint QwtDoubleRect::topRight (  ) const [inline]

Definition at line 483 of file qwt_double_rect.h.

References right(), and top().

{
    return QwtDoublePoint(top(), right());
}
QRect QwtDoubleRect::toRect (  ) const

Definition at line 343 of file qwt_double_rect.cpp.

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

Referenced by QwtPlotSvgItem::render().

{
    return QRect(qRound(x()), qRound(y()), qRound(width()), qRound(height()));
}
QwtDoubleRect QwtDoubleRect::unite ( const QwtDoubleRect other ) const

Returns the bounding rectangle of this rectangle and rectangle other. r.unite(s) is equivalent to r|s.

Definition at line 406 of file qwt_double_rect.cpp.

{
    return *this | other;
}
double QwtDoubleRect::width (  ) const [inline]

Returns the width.

Definition at line 440 of file qwt_double_rect.h.

Referenced by QwtPlotZoomer::move(), moveCenter(), moveLeft(), moveRight(), QwtPlotSvgItem::render(), QwtPlotSpectrogram::renderImage(), setRect(), size(), and toRect().

{ 
    return  d_right - d_left; 
}
double QwtDoubleRect::x (  ) const [inline]

Returns x.

Definition at line 368 of file qwt_double_rect.h.

Referenced by moveLeft(), moveRight(), QwtPlotSvgItem::render(), QwtPlotSpectrogram::renderImage(), setLeft(), setRight(), setX(), and toRect().

{ 
    return d_left; 
}
double QwtDoubleRect::y (  ) const [inline]

Returns y.

Definition at line 374 of file qwt_double_rect.h.

Referenced by moveBottom(), moveTop(), QwtPlotSvgItem::render(), QwtPlotSpectrogram::renderImage(), setBottom(), setTop(), setY(), and toRect().

{ 
    return d_top; 
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines