1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 14:53:21 +02:00

Fixed warious bounds wrapping issues

This commit is contained in:
Martin Tůma 2020-10-27 16:46:09 +01:00
parent fb4af33d89
commit f9abf21e6d
3 changed files with 19 additions and 8 deletions

View File

@ -15,7 +15,8 @@ public:
bool isNull() const bool isNull() const
{return _tl.isNull() && _br.isNull();} {return _tl.isNull() && _br.isNull();}
bool isValid() const bool isValid() const
{return (_tl.isValid() && _br.isValid() && _tl != _br);} {return (_tl.isValid() && _br.isValid()
&& _tl.lat() > _br.lat() && _tl.lon() < _br.lon());}
Coordinates topLeft() const {return _tl;} Coordinates topLeft() const {return _tl;}
Coordinates bottomRight() const {return _br;} Coordinates bottomRight() const {return _br;}

View File

@ -5,7 +5,12 @@
static inline double RB(qint32 val) static inline double RB(qint32 val)
{ {
return (val == -0x800000 || val == 0x800000) ? 180.0 : toWGS24(val); return (val == -0x800000 || val >= 0x800000) ? 180.0 : toWGS24(val);
}
static inline double LB(qint32 val)
{
return (val <= -0x800000) ? -180.0 : toWGS24(val);
} }
static void demangle(quint8 *data, quint32 size, quint32 key) static void demangle(quint8 *data, quint32 size, quint32 key)
@ -60,7 +65,8 @@ bool TREFile::init()
return false; return false;
_bounds = RectC(Coordinates(toWGS24(west), toWGS24(north)), _bounds = RectC(Coordinates(toWGS24(west), toWGS24(north)),
Coordinates(RB(east), toWGS24(south))); Coordinates(RB(east), toWGS24(south)));
Q_ASSERT(_bounds.left() <= _bounds.right()); if (!_bounds.isValid())
return false;
// Levels & subdivs info // Levels & subdivs info
quint32 levelsOffset, levelsSize, subdivSize; quint32 levelsOffset, levelsSize, subdivSize;
@ -193,9 +199,10 @@ bool TREFile::load(int idx)
sl.append(s); sl.append(s);
double min[2], max[2]; double min[2], max[2];
RectC bounds(Coordinates(toWGS24(lon - width), toWGS24(lat + height)), RectC bounds(Coordinates(LB(lon - width), toWGS24(lat + height)),
Coordinates(RB(lon + width), toWGS24(lat - height))); Coordinates(RB(lon + width), toWGS24(lat - height)));
Q_ASSERT(bounds.left() <= bounds.right()); if (!bounds.isValid())
goto error;
min[0] = bounds.left(); min[0] = bounds.left();
min[1] = bounds.bottom(); min[1] = bounds.bottom();

View File

@ -136,6 +136,9 @@ void IMGMap::updateTransform()
RectD prect(_dataBounds, _projection); RectD prect(_dataBounds, _projection);
_bounds = QRectF(_transform.proj2img(prect.topLeft()), _bounds = QRectF(_transform.proj2img(prect.topLeft()),
_transform.proj2img(prect.bottomRight())); _transform.proj2img(prect.bottomRight()));
// Adjust the bounds of world maps to avoid problems with wrapping
if (_dataBounds.left() == -180.0 || _dataBounds.right() == 180.0)
_bounds.adjust(0.5, 0, -0.5, 0);
} }
QPointF IMGMap::ll2xy(const Coordinates &c) QPointF IMGMap::ll2xy(const Coordinates &c)
@ -194,7 +197,7 @@ void IMGMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
QRectF polyRect(ttl, QPointF(ttl.x() + TILE_SIZE, QRectF polyRect(ttl, QPointF(ttl.x() + TILE_SIZE,
ttl.y() + TILE_SIZE)); ttl.y() + TILE_SIZE));
polyRect &= bounds().adjusted(0.5, 0.5, -0.5, -0.5); polyRect &= bounds();
RectD polyRectD(_transform.img2proj(polyRect.topLeft()), RectD polyRectD(_transform.img2proj(polyRect.topLeft()),
_transform.img2proj(polyRect.bottomRight())); _transform.img2proj(polyRect.bottomRight()));
_data.at(n)->polys(polyRectD.toRectC(_projection, 4), _zoom, _data.at(n)->polys(polyRectD.toRectC(_projection, 4), _zoom,
@ -204,7 +207,7 @@ void IMGMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
QRectF pointRect(QPointF(ttl.x() - TEXT_EXTENT, QRectF pointRect(QPointF(ttl.x() - TEXT_EXTENT,
ttl.y() - TEXT_EXTENT), QPointF(ttl.x() + TILE_SIZE ttl.y() - TEXT_EXTENT), QPointF(ttl.x() + TILE_SIZE
+ TEXT_EXTENT, ttl.y() + TILE_SIZE + TEXT_EXTENT)); + TEXT_EXTENT, ttl.y() + TILE_SIZE + TEXT_EXTENT));
pointRect &= bounds().adjusted(0.5, 0.5, -0.5, -0.5); pointRect &= bounds();
RectD pointRectD(_transform.img2proj(pointRect.topLeft()), RectD pointRectD(_transform.img2proj(pointRect.topLeft()),
_transform.img2proj(pointRect.bottomRight())); _transform.img2proj(pointRect.bottomRight()));
_data.at(n)->points(pointRectD.toRectC(_projection, 4), _data.at(n)->points(pointRectD.toRectC(_projection, 4),
@ -241,7 +244,7 @@ void IMGMap::setProjection(const Projection &projection)
_projection = projection; _projection = projection;
// Limit the bounds for some well known Mercator projections // Limit the bounds for some well known Mercator projections
// (GARMIN world maps have N/S bounds up to 90/-90!) // (world maps have N/S bounds up to 90/-90!)
_dataBounds = (_projection == PCS::pcs(3857) || _projection == PCS::pcs(3395)) _dataBounds = (_projection == PCS::pcs(3857) || _projection == PCS::pcs(3395))
? _data.first()->bounds() & OSM::BOUNDS : _data.first()->bounds(); ? _data.first()->bounds() & OSM::BOUNDS : _data.first()->bounds();