1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 19:55:53 +01:00
GPXSee/src/map/rectd.h

56 lines
1.4 KiB
C++

#ifndef RECTD_H
#define RECTD_H
#include "pointd.h"
class RectC;
class Projection;
class RectD
{
public:
RectD() {}
RectD(const PointD &topLeft, const PointD &bottomRight)
: _tl(topLeft), _br(bottomRight) {}
RectD(const RectC &rect, const Projection &proj, int samples = 100);
PointD topLeft() const {return _tl;}
PointD bottomRight() const {return _br;}
double left() const {return _tl.x();}
double right() const {return _br.x();}
double top() const {return _tl.y();}
double bottom() const {return _br.y();}
void setLeft(double val) {_tl.rx() = val;}
void setRight(double val) {_br.rx() = val;}
void setTop(double val) {_tl.ry() = val;}
void setBottom(double val) {_br.ry() = val;}
double width() const {return (right() - left());}
double height() const {return (top() - bottom());}
bool contains(const PointD &p) const
{return (p.x() >= left() && p.x() <= right() && p.y() <= top()
&& p.y() >= bottom());}
bool isNull() const {return _tl.isNull() && _br.isNull();}
bool isValid() const {return !(_tl.isNull() || _br.isNull());}
RectC toRectC(const Projection &proj, int samples = 100) const;
private:
PointD _tl, _br;
};
#ifndef QT_NO_DEBUG
inline QDebug operator<<(QDebug dbg, const RectD &rect)
{
dbg.nospace() << "RectD(" << rect.topLeft() << ", " << rect.bottomRight()
<< ")";
return dbg.space();
}
#endif // QT_NO_DEBUG
#endif // RECTD_H