2017-06-29 22:29:27 +02:00
|
|
|
#ifndef RECTC_H
|
|
|
|
#define RECTC_H
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include "coordinates.h"
|
|
|
|
|
|
|
|
class RectC
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RectC() {}
|
|
|
|
RectC(const Coordinates &topLeft, const Coordinates &bottomRight)
|
|
|
|
: _tl(topLeft), _br(bottomRight) {}
|
2018-04-13 21:14:12 +02:00
|
|
|
RectC(const Coordinates ¢er, double radius);
|
2017-06-29 22:29:27 +02:00
|
|
|
|
|
|
|
bool isNull() const
|
2017-06-30 18:15:22 +02:00
|
|
|
{return _tl.isNull() && _br.isNull();}
|
|
|
|
bool isValid() const
|
2020-10-27 16:46:09 +01:00
|
|
|
{return (_tl.isValid() && _br.isValid()
|
|
|
|
&& _tl.lat() > _br.lat() && _tl.lon() < _br.lon());}
|
2017-06-29 22:29:27 +02:00
|
|
|
|
|
|
|
Coordinates topLeft() const {return _tl;}
|
|
|
|
Coordinates bottomRight() const {return _br;}
|
|
|
|
Coordinates center() const
|
|
|
|
{return Coordinates((_tl.lon() + _br.lon()) / 2.0,
|
|
|
|
(_tl.lat() + _br.lat()) / 2.0);}
|
|
|
|
|
2018-09-22 14:17:24 +02:00
|
|
|
double top() const {return _tl.lat();}
|
|
|
|
double bottom() const {return _br.lat();}
|
|
|
|
double left() const {return _tl.lon();}
|
|
|
|
double right() const {return _br.lon();}
|
|
|
|
|
2020-02-17 09:47:47 +01:00
|
|
|
double width() const {return (right() - left());}
|
|
|
|
double height() const {return (top() - bottom());}
|
|
|
|
|
2019-05-10 18:56:19 +02:00
|
|
|
void setLeft(double val) {_tl.rlon() = val;}
|
|
|
|
void setRight(double val) {_br.rlon() = val;}
|
|
|
|
void setTop(double val) {_tl.rlat() = val;}
|
|
|
|
void setBottom(double val) {_br.rlat() = val;}
|
|
|
|
|
2017-06-29 22:29:27 +02:00
|
|
|
RectC operator|(const RectC &r) const;
|
|
|
|
RectC &operator|=(const RectC &r) {*this = *this | r; return *this;}
|
2018-04-02 23:27:42 +02:00
|
|
|
RectC operator&(const RectC &r) const;
|
|
|
|
RectC &operator&=(const RectC &r) {*this = *this & r; return *this;}
|
2017-06-29 22:29:27 +02:00
|
|
|
|
2018-04-16 20:26:10 +02:00
|
|
|
RectC united(const Coordinates &c) const;
|
2017-06-29 22:29:27 +02:00
|
|
|
|
2019-05-10 18:56:19 +02:00
|
|
|
bool intersects(const RectC &r) const
|
|
|
|
{return (right() >= r.left() && bottom() <= r.top() && left() <= r.right()
|
|
|
|
&& top() >= r.bottom());}
|
|
|
|
bool contains(const Coordinates&c) const
|
|
|
|
{return (c.lon() >= left() && c.lon() <= right() && c.lat() <= top()
|
|
|
|
&& c.lat() >= bottom());}
|
|
|
|
|
2017-06-29 22:29:27 +02:00
|
|
|
private:
|
|
|
|
Coordinates _tl, _br;
|
|
|
|
};
|
|
|
|
|
2018-02-13 23:03:18 +01:00
|
|
|
#ifndef QT_NO_DEBUG
|
2017-06-29 22:29:27 +02:00
|
|
|
QDebug operator<<(QDebug dbg, const RectC &rect);
|
2018-02-13 23:03:18 +01:00
|
|
|
#endif // QT_NO_DEBUG
|
2017-06-29 22:29:27 +02:00
|
|
|
|
|
|
|
#endif // RECTC_H
|