1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-06-27 11:39:16 +02:00

RectC now uses the expected axis direction

+ some more refactoring
This commit is contained in:
2018-04-16 20:26:10 +02:00
parent b26a10a5b3
commit 9e36451001
19 changed files with 90 additions and 115 deletions

View File

@ -45,39 +45,34 @@ RectC RectC::operator|(const RectC &r) const
double l1 = _tl.lon();
double r1 = _tl.lon();
if (_br.lon() - _tl.lon() < 0)
if (_br.lon() < _tl.lon())
l1 = _br.lon();
else
r1 = _br.lon();
double l2 = r._tl.lon();
double r2 = r._tl.lon();
if (r._br.lon() - r._tl.lon() < 0)
if (r._br.lon() < r._tl.lon())
l2 = r._br.lon();
else
r2 = r._br.lon();
double t1 = _tl.lat();
double b1 = _tl.lat();
if (_br.lat() - _tl.lat() < 0)
if (_br.lat() > _tl.lat())
t1 = _br.lat();
else
b1 = _br.lat();
double t2 = r._tl.lat();
double b2 = r._tl.lat();
if (r._br.lat() - r._tl.lat() < 0)
if (r._br.lat() > r._tl.lat())
t2 = r._br.lat();
else
b2 = r._br.lat();
RectC tmp;
tmp._tl.setLon(qMin(l1, l2));
tmp._br.setLon(qMax(r1, r2));
tmp._tl.setLat(qMin(t1, t2));
tmp._br.setLat(qMax(b1, b2));
return tmp;
return RectC(Coordinates(qMin(l1, l2), qMax(t1, t2)),
Coordinates(qMax(r1, r2), qMin(b1, b2)));
}
RectC RectC::operator&(const RectC &r) const
@ -87,14 +82,14 @@ RectC RectC::operator&(const RectC &r) const
double l1 = _tl.lon();
double r1 = _tl.lon();
if (_br.lon() - _tl.lon() < 0)
if (_br.lon() < _tl.lon())
l1 = _br.lon();
else
r1 = _br.lon();
double l2 = r._tl.lon();
double r2 = r._tl.lon();
if (r._br.lon() - r._tl.lon() < 0)
if (r._br.lon() < r._tl.lon())
l2 = r._br.lon();
else
r2 = r._br.lon();
@ -104,67 +99,56 @@ RectC RectC::operator&(const RectC &r) const
double t1 = _tl.lat();
double b1 = _tl.lat();
if (_br.lat() - _tl.lat() < 0)
if (_br.lat() > _tl.lat())
t1 = _br.lat();
else
b1 = _br.lat();
double t2 = r._tl.lat();
double b2 = r._tl.lat();
if (r._br.lat() - r._tl.lat() < 0)
if (r._br.lat() > r._tl.lat())
t2 = r._br.lat();
else
b2 = r._br.lat();
if (t1 > b2 || t2 > b1)
if (b1 > t2 || b2 > t1)
return RectC();
RectC tmp;
tmp._tl.setLon(qMax(l1, l2));
tmp._br.setLon(qMin(r1, r2));
tmp._tl.setLat(qMax(t1, t2));
tmp._br.setLat(qMin(b1, b2));
return tmp;
return RectC(Coordinates(qMax(l1, l2), qMin(t1, t2)),
Coordinates(qMin(r1, r2), qMax(b1, b2)));
}
RectC RectC::normalized() const
RectC RectC::united(const Coordinates &c) const
{
RectC r;
if (c.isNull())
return *this;
if (isNull())
return RectC(c, c);
if (_br.lon() < _tl.lon()) {
r._tl.setLon(_br.lon());
r._br.setLon(_tl.lon());
} else {
r._tl.setLon(_tl.lon());
r._br.setLon(_br.lon());
}
if (_br.lat() < _tl.lat()) {
r._tl.setLat(_br.lat());
r._br.setLat(_tl.lat());
} else {
r._tl.setLat(_tl.lat());
r._br.setLat(_br.lat());
}
double l = _tl.lon();
double r = _tl.lon();
if (_br.lon() < _tl.lon())
l = _br.lon();
else
r = _br.lon();
return r;
}
double t = _tl.lat();
double b = _tl.lat();
if (_br.lat() > _tl.lat())
t = _br.lat();
else
b = _br.lat();
void RectC::unite(const Coordinates &c)
{
if (isNull()) {
_tl = c;
_br = c;
} else {
if (c.lon() < _tl.lon())
_tl.setLon(c.lon());
if (c.lon() > _br.lon())
_br.setLon(c.lon());
if (c.lat() > _br.lat())
_br.setLat(c.lat());
if (c.lat() < _tl.lat())
_tl.setLat(c.lat());
}
if (c.lon() < l)
l = c.lon();
if (c.lon() > r)
r = c.lon();
if (c.lat() < b)
b = c.lat();
if (c.lat() > t)
t = c.lat();
return RectC(Coordinates(l, t), Coordinates(r, b));
}
#ifndef QT_NO_DEBUG

View File

@ -28,8 +28,7 @@ public:
RectC operator&(const RectC &r) const;
RectC &operator&=(const RectC &r) {*this = *this & r; return *this;}
void unite(const Coordinates &c);
RectC normalized() const;
RectC united(const Coordinates &c) const;
private:
Coordinates _tl, _br;