2018-05-02 21:25:14 +02:00
|
|
|
#ifndef RECTD_H
|
|
|
|
#define RECTD_H
|
|
|
|
|
|
|
|
#include "pointd.h"
|
|
|
|
|
2019-01-08 21:42:28 +01:00
|
|
|
class RectC;
|
|
|
|
class Projection;
|
|
|
|
|
2018-05-02 21:25:14 +02:00
|
|
|
class RectD
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RectD() {}
|
|
|
|
RectD(const PointD &topLeft, const PointD &bottomRight)
|
|
|
|
: _tl(topLeft), _br(bottomRight) {}
|
2019-05-10 18:56:19 +02:00
|
|
|
RectD(const RectC &rect, const Projection &proj, int samples = 100);
|
2018-05-02 21:25:14 +02:00
|
|
|
|
|
|
|
PointD topLeft() const {return _tl;}
|
|
|
|
PointD bottomRight() const {return _br;}
|
2020-12-14 22:06:59 +01:00
|
|
|
PointD center() const
|
|
|
|
{return PointD((_tl.x() + _br.x()) / 2.0,
|
|
|
|
(_tl.y() + _br.y()) / 2.0);}
|
2018-05-02 21:25:14 +02:00
|
|
|
|
|
|
|
double left() const {return _tl.x();}
|
|
|
|
double right() const {return _br.x();}
|
|
|
|
double top() const {return _tl.y();}
|
|
|
|
double bottom() const {return _br.y();}
|
|
|
|
|
2019-01-08 21:42:28 +01:00
|
|
|
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;}
|
|
|
|
|
2018-05-02 21:25:14 +02:00
|
|
|
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();}
|
2020-12-12 10:19:48 +01:00
|
|
|
bool isValid() const
|
|
|
|
{return (_tl.isValid() && _br.isValid()
|
|
|
|
&& _tl.x() != _br.x() && _tl.y() != _br.y());}
|
2018-05-02 21:25:14 +02:00
|
|
|
|
2019-05-10 18:56:19 +02:00
|
|
|
RectC toRectC(const Projection &proj, int samples = 100) const;
|
|
|
|
|
2018-05-02 21:25:14 +02:00
|
|
|
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
|