File: qwt_double_rect.h

package info (click to toggle)
libqwt 4.2.0-6
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 9,832 kB
  • ctags: 5,512
  • sloc: cpp: 22,973; ansic: 244; makefile: 64
file content (420 lines) | stat: -rw-r--r-- 9,262 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#ifndef QWT_DOUBLE_RECT_H
#define QWT_DOUBLE_RECT_H 1

#include <qpoint.h>
#include <qsize.h>
#include <qrect.h>
#include "qwt_global.h"

/*!
  The QwtDoublePoint class defines a point in double coordinates
*/

class QWT_EXPORT QwtDoublePoint
{
public:
    QwtDoublePoint();
    QwtDoublePoint(double x, double y);
    QwtDoublePoint(const QPoint &);

    inline bool isNull()    const;

    inline double x() const;
    inline double y() const;
    inline void setX(double x);
    inline void setY(double y);

    inline double &rx();
    inline double &ry();

    bool operator==(const QwtDoublePoint &) const;
    bool operator!=(const QwtDoublePoint &) const;

    const QwtDoublePoint operator-() const;
    const QwtDoublePoint operator+(const QwtDoublePoint &) const;
    const QwtDoublePoint operator-(const QwtDoublePoint &) const;
    const QwtDoublePoint operator*(double) const;
    const QwtDoublePoint operator/(double) const;

    QwtDoublePoint &operator+=(const QwtDoublePoint &);
    QwtDoublePoint &operator-=(const QwtDoublePoint &);
    QwtDoublePoint &operator*=(double);
    QwtDoublePoint &operator/=(double);

private:
    double d_x;
    double d_y;
};

/*!
  The QwtDoubleSize class defines a size in double coordinates
*/

class QWT_EXPORT QwtDoubleSize
{
public:
    QwtDoubleSize();
    QwtDoubleSize(double width, double height);
    QwtDoubleSize(const QSize &);

    inline bool isNull() const;
    inline bool isEmpty() const;
    inline bool isValid() const;

    inline double width() const;
    inline double height() const;
    inline void setWidth( double w );
    inline void setHeight( double h );
    void transpose();

    QwtDoubleSize expandedTo(const QwtDoubleSize &) const;
    QwtDoubleSize boundedTo(const QwtDoubleSize &) const;

    inline double &rwidth();
    inline double &rheight();

    bool operator==(const QwtDoubleSize &) const;
    bool operator!=(const QwtDoubleSize &) const;

    const QwtDoubleSize operator-() const;
    const QwtDoubleSize operator+(const QwtDoubleSize &) const;
    const QwtDoubleSize operator-(const QwtDoubleSize &) const;
    const QwtDoubleSize operator*(double) const;
    const QwtDoubleSize operator/(double) const;

    QwtDoubleSize &operator+=(const QwtDoubleSize &);
    QwtDoubleSize &operator-=(const QwtDoubleSize &);
    QwtDoubleSize &operator*=(double c);
    QwtDoubleSize &operator/=(double c);

private:
    double d_width;
    double d_height;
};

/*!
  The QwtDoubleRect class defines a size in double coordinates.
*/

class QWT_EXPORT QwtDoubleRect  
{
public:
    QwtDoubleRect();
    QwtDoubleRect(double x1, double x2, double y1, double y2);
    QwtDoubleRect(double x, double y, const QwtDoubleSize &);

    inline bool isNull()    const;
    inline bool isEmpty()   const;
    inline bool isValid()   const;

    QwtDoubleRect normalize() const;

    inline double x1()  const;
    inline double x2()  const;
    inline double y1()  const;
    inline double y2()  const;

    inline double &rx1();
    inline double &rx2();
    inline double &ry1();
    inline double &ry2();

    inline void setX1(double);
    inline void setX2(double);
    inline void setY1(double);
    inline void setY2(double);

    QwtDoublePoint center()  const;

    void moveX(double x);
    void moveY(double y );
    void move(double x, double y);
    void moveBy(double dx, double dy);
    void moveCenter(const QwtDoublePoint &);
    void moveCenter(double dx, double dy);

    void setRect(double x1, double x2, double y1, double y2);

    inline double width()   const;
    inline double height()  const;
    inline QwtDoubleSize size() const;

    inline void setWidth(double w );
    inline void setHeight(double h );
    void setSize(const QwtDoubleSize &);

    QwtDoubleRect  operator|(const QwtDoubleRect &r) const;
    QwtDoubleRect  operator&(const QwtDoubleRect &r) const;
    QwtDoubleRect &operator|=(const QwtDoubleRect &r);
    QwtDoubleRect &operator&=(const QwtDoubleRect &r);
    bool operator==( const QwtDoubleRect &) const;
    bool operator!=( const QwtDoubleRect &) const;

    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;

private:
    double d_x1;
    double d_x2;
    double d_y1;
    double d_y2;
};

/*! 
  Returns TRUE if both the x value and the y value are 0; 
  otherwise returns FALSE. 
*/
inline bool QwtDoublePoint::isNull() const
{ 
    return d_x == 0.0 && d_y == 0.0; 
}

//! Returns the x coordinate of the point. 
inline double QwtDoublePoint::x() const
{ 
    return d_x; 
}

//! Returns the y coordinate of the point. 
inline double QwtDoublePoint::y() const
{   
    return d_y; 
}

//! Sets the x coordinate of the point to x. 
inline void QwtDoublePoint::setX(double x)
{ 
    d_x = x; 
}

//! Sets the y coordinate of the point to x. 
inline void QwtDoublePoint::setY(double y)
{ 
    d_y = y; 
}

//! Returns a reference to the x coordinate of the point. 
inline double &QwtDoublePoint::rx()
{ 
    return d_x; 
}

//! Returns a reference to the y coordinate of the point. 
inline double &QwtDoublePoint::ry()
{ 
    return d_y; 
}

/*!
  Returns TRUE if the width is 0 and the height is 0; 
  otherwise returns FALSE.
*/
inline bool QwtDoubleSize::isNull() const
{ 
    return d_width == 0.0 && d_height == 0.0; 
}

/*! 
  Returns TRUE if the width is <= 0 or the height is <= 0, 
  otherwise FALSE. 
*/
inline bool QwtDoubleSize::isEmpty() const
{ 
    return d_width <= 0.0 || d_height <= 0.0; 
}

/*!
  Returns TRUE if the width is equal to or greater than 0 and the height 
  is equal to or greater than 0; otherwise returns FALSE.
*/
inline bool QwtDoubleSize::isValid() const
{ 
    return d_width >= 0.0 && d_height >= 0.0; 
}

//! Returns the width. 
inline double QwtDoubleSize::width() const
{ 
    return d_width; 
}

//! Returns the height. 
inline double QwtDoubleSize::height() const
{ 
    return d_height; 
}

//! Sets the width to width. 
inline void QwtDoubleSize::setWidth(double width)
{ 
    d_width = width; 
}

//! Sets the height to height. 
inline void QwtDoubleSize::setHeight(double height)
{ 
    d_height = height; 
}

//! Returns a reference to the width. 
inline double &QwtDoubleSize::rwidth()
{ 
    return d_width; 
}

//! Returns a reference to the height. 
inline double &QwtDoubleSize::rheight()
{   
    return d_height; 
}

/*!
  Returns TRUE if the rectangle is a null rectangle; 
  otherwise returns FALSE. 

  A rect is null when x1() == x2() && y1() == y2().
*/
inline bool QwtDoubleRect::isNull() const
{ 
    return d_x2 == d_x1 && d_y2 == d_y1;
}

/*!
  Returns TRUE if the rectangle is a empty rectangle; 
  otherwise returns FALSE. 

  A rect is null when x1() >= x2() && y1() >= y2().
*/
inline bool QwtDoubleRect::isEmpty() const
{ 
    return d_x1 >= d_x2 || d_y1 >= d_y2; 
}

/*!
  Returns TRUE if the rectangle is a valid rectangle; 
  otherwise returns FALSE. 

  A rect is valid when x1() <= x2() && y1() <= y2().
*/
inline bool QwtDoubleRect::isValid() const
{ 
    return d_x1 <= d_x2 && d_y1 <= d_y2; 
}

//! Returns x1
inline double QwtDoubleRect::x1() const
{ 
    return d_x1; 
}

//! Returns x2
inline double QwtDoubleRect::x2() const
{ 
    return d_x2; 
}

//! Returns y1
inline double QwtDoubleRect::y1() const
{ 
    return d_y1; 
}

//! Returns y2
inline double QwtDoubleRect::y2() const
{ 
    return d_y2; 
}

//! Returns a reference to x1
inline double &QwtDoubleRect::rx1()
{ 
    return d_x1; 
}

//! Returns a reference to x2
inline double &QwtDoubleRect::rx2()
{ 
    return d_x2; 
}

//! Returns a reference to y1
inline double &QwtDoubleRect::ry1()
{ 
    return d_y1; 
}

//! Returns a reference to y2
inline double &QwtDoubleRect::ry2()
{ 
    return d_y2; 
}

//! Set x1  
inline void QwtDoubleRect::setX1(double x1)
{ 
    d_x1 = x1;
}

//! Set x2  
inline void QwtDoubleRect::setX2(double x2)
{ 
    d_x2 = x2;
}

//! Set y1  
inline void QwtDoubleRect::setY1(double y1)
{ 
    d_y1 = y1;
}

//! Set y2  
inline void QwtDoubleRect::setY2(double y2)
{ 
    d_y2 = y2;
}

//! Returns the width
inline double QwtDoubleRect::width() const
{ 
    return  d_x2 - d_x1; 
}

//! Returns the height
inline double QwtDoubleRect::height() const
{ 
    return  d_y2 - d_y1; 
}

//! Returns the size
inline QwtDoubleSize QwtDoubleRect::size() const
{ 
    return QwtDoubleSize(width(), height());
}

//! Set the width, by x2 = x1 + w;
inline void QwtDoubleRect::setWidth(double w)
{
    d_x2 = d_x1 + w;
}

//! Set the height, by y2 = y1 + h;
inline void QwtDoubleRect::setHeight(double h)
{
    d_y2 = d_y1 + h;
}

#endif // QWT_DOUBLE_RECT_H