Map API refactoring
[GPXSee.git] / src / map / rectd.h
blobc8355b401c400e81ee975f5700d07cae6a092563
1 #ifndef RECTD_H
2 #define RECTD_H
4 #include "pointd.h"
6 class RectC;
7 class Projection;
9 class RectD
11 public:
12 RectD() {}
13 RectD(const PointD &topLeft, const PointD &bottomRight)
14 : _tl(topLeft), _br(bottomRight) {}
15 RectD(const RectC &rect, const Projection &proj, int samples = 100);
17 PointD topLeft() const {return _tl;}
18 PointD bottomRight() const {return _br;}
19 PointD center() const
20 {return PointD((_tl.x() + _br.x()) / 2.0,
21 (_tl.y() + _br.y()) / 2.0);}
23 double left() const {return _tl.x();}
24 double right() const {return _br.x();}
25 double top() const {return _tl.y();}
26 double bottom() const {return _br.y();}
28 void setLeft(double val) {_tl.rx() = val;}
29 void setRight(double val) {_br.rx() = val;}
30 void setTop(double val) {_tl.ry() = val;}
31 void setBottom(double val) {_br.ry() = val;}
33 double width() const {return (right() - left());}
34 double height() const {return (top() - bottom());}
36 bool contains(const PointD &p) const
37 {return (p.x() >= left() && p.x() <= right() && p.y() <= top()
38 && p.y() >= bottom());}
40 bool isNull() const {return _tl.isNull() && _br.isNull();}
41 bool isValid() const
42 {return (_tl.isValid() && _br.isValid()
43 && _tl.x() != _br.x() && _tl.y() != _br.y());}
45 RectC toRectC(const Projection &proj, int samples = 100) const;
47 private:
48 PointD _tl, _br;
51 #ifndef QT_NO_DEBUG
52 inline QDebug operator<<(QDebug dbg, const RectD &rect)
54 dbg.nospace() << "RectD(" << rect.topLeft() << ", " << rect.bottomRight()
55 << ")";
56 return dbg.space();
58 #endif // QT_NO_DEBUG
60 #endif // RECTD_H