1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
3
* Copyright (C) 1997 Josef Wilgen
4
* Copyright (C) 2002 Uwe Rathmann
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the Qwt License, Version 1.0
8
*****************************************************************************/
11
#ifndef QWT_DOUBLE_RECT_H
12
#define QWT_DOUBLE_RECT_H 1
14
#include "qwt_global.h"
15
#include "qwt_array.h"
17
#if QT_VERSION >= 0x040000
24
\typedef QPointF QwtDoublePoint
25
\brief This is a typedef, see Trolltech Documentation for QPointF
26
in QT assistant 4.x. As soon as Qt3 compatibility is dropped
27
this typedef will disappear.
29
typedef QPointF QwtDoublePoint;
32
\typedef QSizeF QwtDoubleSize
33
\brief This is a typedef, see Trolltech Documentation for QSizeF
34
in QT assistant 4.x. As soon as Qt3 compatibility is dropped
35
this typedef will disappear.
37
typedef QSizeF QwtDoubleSize;
40
\typedef QRectF QwtDoubleRect
41
\brief This is a typedef, see Trolltech Documentation for QRectF
42
in QT assistant 4.x. As soon as Qt3 compatibility is dropped
43
this typedef will disappear.
45
typedef QRectF QwtDoubleRect;
54
\brief The QwtDoublePoint class defines a point in double coordinates
57
class QWT_EXPORT QwtDoublePoint
61
QwtDoublePoint(double x, double y);
62
QwtDoublePoint(const QPoint &);
64
QPoint toPoint() const;
77
bool operator==(const QwtDoublePoint &) const;
78
bool operator!=(const QwtDoublePoint &) const;
80
const QwtDoublePoint operator-() const;
81
const QwtDoublePoint operator+(const QwtDoublePoint &) const;
82
const QwtDoublePoint operator-(const QwtDoublePoint &) const;
83
const QwtDoublePoint operator*(double) const;
84
const QwtDoublePoint operator/(double) const;
86
QwtDoublePoint &operator+=(const QwtDoublePoint &);
87
QwtDoublePoint &operator-=(const QwtDoublePoint &);
88
QwtDoublePoint &operator*=(double);
89
QwtDoublePoint &operator/=(double);
97
The QwtDoubleSize class defines a size in double coordinates
100
class QWT_EXPORT QwtDoubleSize
104
QwtDoubleSize(double width, double height);
105
QwtDoubleSize(const QSize &);
108
bool isEmpty() const;
109
bool isValid() const;
111
double width() const;
112
double height() const;
113
void setWidth( double w );
114
void setHeight( double h );
117
QwtDoubleSize expandedTo(const QwtDoubleSize &) const;
118
QwtDoubleSize boundedTo(const QwtDoubleSize &) const;
120
bool operator==(const QwtDoubleSize &) const;
121
bool operator!=(const QwtDoubleSize &) const;
123
const QwtDoubleSize operator+(const QwtDoubleSize &) const;
124
const QwtDoubleSize operator-(const QwtDoubleSize &) const;
125
const QwtDoubleSize operator*(double) const;
126
const QwtDoubleSize operator/(double) const;
128
QwtDoubleSize &operator+=(const QwtDoubleSize &);
129
QwtDoubleSize &operator-=(const QwtDoubleSize &);
130
QwtDoubleSize &operator*=(double c);
131
QwtDoubleSize &operator/=(double c);
139
The QwtDoubleRect class defines a size in double coordinates.
142
class QWT_EXPORT QwtDoubleRect
146
QwtDoubleRect(double left, double top, double width, double height);
147
QwtDoubleRect(const QwtDoublePoint&, const QwtDoubleSize &);
149
QwtDoubleRect(const QRect &);
150
QRect toRect() const;
153
bool isEmpty() const;
154
bool isValid() const;
156
QwtDoubleRect normalized() const;
162
double right() const;
164
double bottom() const;
169
void setLeft(double);
170
void setRight(double);
172
void setBottom(double);
174
QwtDoublePoint center() const;
176
void moveLeft(double x);
177
void moveRight(double x);
178
void moveTop(double y );
179
void moveBottom(double y );
180
void moveTo(double x, double y);
181
void moveTo(const QwtDoublePoint &);
182
void moveBy(double dx, double dy);
183
void moveCenter(const QwtDoublePoint &);
184
void moveCenter(double dx, double dy);
186
void setRect(double x1, double x2, double width, double height);
188
double width() const;
189
double height() const;
190
QwtDoubleSize size() const;
192
void setWidth(double w );
193
void setHeight(double h );
194
void setSize(const QwtDoubleSize &);
196
QwtDoubleRect operator|(const QwtDoubleRect &r) const;
197
QwtDoubleRect operator&(const QwtDoubleRect &r) const;
198
QwtDoubleRect &operator|=(const QwtDoubleRect &r);
199
QwtDoubleRect &operator&=(const QwtDoubleRect &r);
200
bool operator==( const QwtDoubleRect &) const;
201
bool operator!=( const QwtDoubleRect &) const;
203
bool contains(const QwtDoublePoint &p, bool proper = false) const;
204
bool contains(double x, double y, bool proper = false) const;
205
bool contains(const QwtDoubleRect &r, bool proper=false) const;
207
QwtDoubleRect unite(const QwtDoubleRect &) const;
208
QwtDoubleRect intersect(const QwtDoubleRect &) const;
209
bool intersects(const QwtDoubleRect &) const;
211
QwtDoublePoint bottomRight() const;
212
QwtDoublePoint topRight() const;
213
QwtDoublePoint topLeft() const;
214
QwtDoublePoint bottomLeft() const;
224
Returns true if the point is null; otherwise returns false.
226
A point is considered to be null if both the x- and y-coordinates
229
inline bool QwtDoublePoint::isNull() const
231
return d_x == 0.0 && d_y == 0.0;
234
//! Returns the x-coordinate of the point.
235
inline double QwtDoublePoint::x() const
240
//! Returns the y-coordinate of the point.
241
inline double QwtDoublePoint::y() const
246
//! Returns a reference to the x-coordinate of the point.
247
inline double &QwtDoublePoint::rx()
252
//! Returns a reference to the y-coordinate of the point.
253
inline double &QwtDoublePoint::ry()
258
//! Sets the x-coordinate of the point to the value specified by x.
259
inline void QwtDoublePoint::setX(double x)
264
//! Sets the y-coordinate of the point to the value specified by y.
265
inline void QwtDoublePoint::setY(double y)
271
Rounds the coordinates of this point to the nearest integer and
272
returns a QPoint with these rounded coordinates.
274
inline QPoint QwtDoublePoint::toPoint() const
276
return QPoint(qRound(d_x), qRound(d_y));
280
Returns true if the width is 0 and the height is 0;
281
otherwise returns false.
283
inline bool QwtDoubleSize::isNull() const
285
return d_width == 0.0 && d_height == 0.0;
289
Returns true if the width is <= 0.0 or the height is <= 0.0,
292
inline bool QwtDoubleSize::isEmpty() const
294
return d_width <= 0.0 || d_height <= 0.0;
298
Returns true if the width is equal to or greater than 0.0 and the height
299
is equal to or greater than 0.0; otherwise returns false.
301
inline bool QwtDoubleSize::isValid() const
303
return d_width >= 0.0 && d_height >= 0.0;
306
//! Returns the width.
307
inline double QwtDoubleSize::width() const
312
//! Returns the height.
313
inline double QwtDoubleSize::height() const
318
//! Sets the width to width.
319
inline void QwtDoubleSize::setWidth(double width)
324
//! Sets the height to height.
325
inline void QwtDoubleSize::setHeight(double height)
331
Returns true if the rectangle is a null rectangle; otherwise returns false.
332
A null rectangle has both the width and the height set to 0.
333
A null rectangle is also empty and invalid.
335
\sa QwtDoubleRect::isEmpty, QwtDoubleRect::isValid
337
inline bool QwtDoubleRect::isNull() const
339
return d_right == d_left && d_bottom == d_top;
343
Returns true if the rectangle is empty; otherwise returns false.
344
An empty rectangle has a width() <= 0 or height() <= 0.
345
An empty rectangle is not valid. isEmpty() == !isValid()
347
\sa QwtDoubleRect::isNull, QwtDoubleRect::isValid
349
inline bool QwtDoubleRect::isEmpty() const
351
return d_left >= d_right || d_top >= d_bottom;
355
Returns true if the rectangle is valid; otherwise returns false.
356
A valid rectangle has a width() > 0 and height() > 0.
357
Note that non-trivial operations like intersections are not defined
358
for invalid rectangles. isValid() == !isEmpty()
360
\sa isNull(), isEmpty(), and normalized().
362
inline bool QwtDoubleRect::isValid() const
364
return d_left < d_right && d_top < d_bottom;
368
inline double QwtDoubleRect::x() const
374
inline double QwtDoubleRect::y() const
380
inline double QwtDoubleRect::left() const
386
inline double QwtDoubleRect::right() const
392
inline double QwtDoubleRect::top() const
398
inline double QwtDoubleRect::bottom() const
404
inline void QwtDoubleRect::setX(double x)
410
inline void QwtDoubleRect::setY(double y)
416
inline void QwtDoubleRect::setLeft(double x)
422
inline void QwtDoubleRect::setRight(double x)
428
inline void QwtDoubleRect::setTop(double y)
434
inline void QwtDoubleRect::setBottom(double y)
439
//! Returns the width
440
inline double QwtDoubleRect::width() const
442
return d_right - d_left;
445
//! Returns the height
446
inline double QwtDoubleRect::height() const
448
return d_bottom - d_top;
452
inline QwtDoubleSize QwtDoubleRect::size() const
454
return QwtDoubleSize(width(), height());
457
//! Set the width, by right = left + w;
458
inline void QwtDoubleRect::setWidth(double w)
460
d_right = d_left + w;
463
//! Set the height, by bottom = top + h;
464
inline void QwtDoubleRect::setHeight(double h)
466
d_bottom = d_top + h;
470
Moves the top left corner of the rectangle to p,
471
without changing the rectangles size.
473
inline void QwtDoubleRect::moveTo(const QwtDoublePoint &p)
475
moveTo(p.x(), p.y());
478
inline QwtDoublePoint QwtDoubleRect::bottomRight() const
480
return QwtDoublePoint(bottom(), right());
483
inline QwtDoublePoint QwtDoubleRect::topRight() const
485
return QwtDoublePoint(top(), right());
488
inline QwtDoublePoint QwtDoubleRect::topLeft() const
490
return QwtDoublePoint(top(), left());
493
inline QwtDoublePoint QwtDoubleRect::bottomLeft() const
495
return QwtDoublePoint(bottom(), left());
499
#endif // QT_VERSION < 0x040000
501
#endif // QWT_DOUBLE_RECT_H