From 4530ec13540684937bb7a4a5c797e2e5744bee7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 15 Apr 2018 17:32:25 +0200 Subject: [PATCH] Code cleanup --- src/map/atlas.cpp | 17 ++++++++++------- src/map/offlinemap.cpp | 8 +++----- src/map/offlinemap.h | 8 ++++---- src/map/transform.h | 6 ++++-- src/map/wmsmap.cpp | 8 ++++---- src/map/wmtsmap.cpp | 2 +- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/map/atlas.cpp b/src/map/atlas.cpp index 33142a73..2061bda6 100644 --- a/src/map/atlas.cpp +++ b/src/map/atlas.cpp @@ -75,8 +75,9 @@ void Atlas::computeBounds() } for (int i = 0; i < _maps.count(); i++) - _bounds.append(QPair(QRectF(TL(_maps.at(i)), - BR(_maps.at(i))), QRectF(offsets.at(i), _maps.at(i)->bounds().size()))); + _bounds.append(QPair(QRectF(TL(_maps.at(i)).toPointF(), + BR(_maps.at(i)).toPointF()), QRectF(offsets.at(i), + _maps.at(i)->bounds().size()))); } Atlas::Atlas(const QString &fileName, QObject *parent) @@ -166,7 +167,8 @@ qreal Atlas::resolution(const QRectF &rect) const int idx = _zooms.at(_zoom).first; for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) { - if (_bounds.at(i).second.contains(_maps.at(i)->xy2pp(rect.center()))) { + if (_bounds.at(i).second.contains(_maps.at(i)->xy2pp(rect.center()) + .toPointF())) { idx = i; break; } @@ -187,7 +189,8 @@ int Atlas::zoomFit(const QSize &size, const RectC &br) for (int z = 0; z < _zooms.count(); z++) { for (int i = _zooms.at(z).first; i <= _zooms.at(z).second; i++) { - if (!_bounds.at(i).first.contains(_maps.at(i)->ll2pp(br.center()))) + if (!_bounds.at(i).first.contains(_maps.at(i)->ll2pp(br.center()) + .toPointF())) continue; QRect sbr = QRectF(_maps.at(i)->ll2xy(br.topLeft()), @@ -226,11 +229,11 @@ QPointF Atlas::ll2xy(const Coordinates &c) QPointF pp; if (_mapIndex >= 0) - pp = _maps.at(_mapIndex)->ll2pp(c); + pp = _maps.at(_mapIndex)->ll2pp(c).toPointF(); if (_mapIndex < 0 || !_bounds.at(_mapIndex).first.contains(pp)) { _mapIndex = _zooms.at(_zoom).first; for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) { - pp = _maps.at(i)->ll2pp(c); + pp = _maps.at(i)->ll2pp(c).toPointF(); if (_bounds.at(i).first.contains(pp)) { _mapIndex = i; break; @@ -247,7 +250,7 @@ Coordinates Atlas::xy2ll(const QPointF &p) int idx = _zooms.at(_zoom).first; for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) { - if (_bounds.at(i).second.contains(_maps.at(i)->xy2pp(p))) { + if (_bounds.at(i).second.contains(_maps.at(i)->xy2pp(p).toPointF())) { idx = i; break; } diff --git a/src/map/offlinemap.cpp b/src/map/offlinemap.cpp index 9d921715..21f11c56 100644 --- a/src/map/offlinemap.cpp +++ b/src/map/offlinemap.cpp @@ -325,7 +325,7 @@ void OfflineMap::draw(QPainter *painter, const QRectF &rect) QPointF OfflineMap::ll2xy(const Coordinates &c) const { - QPointF p(_transform.proj2img(_projection.ll2xy(c).toPointF())); + QPointF p(_transform.proj2img(_projection.ll2xy(c))); return _ozf ? QPointF(p.x() * _scale.x(), p.y() * _scale.y()) : p; } @@ -363,10 +363,8 @@ int OfflineMap::zoomFit(const QSize &size, const RectC &rect) if (!rect.isValid()) rescale(0); else { - QPointF tl(_transform.proj2img(_projection.ll2xy(rect.topLeft()) - .toPointF())); - QPointF br(_transform.proj2img(_projection.ll2xy(rect.bottomRight()) - .toPointF())); + QPointF tl(_transform.proj2img(_projection.ll2xy(rect.topLeft()))); + QPointF br(_transform.proj2img(_projection.ll2xy(rect.bottomRight()))); QRect sbr(QRectF(tl, br).toRect().normalized()); for (int i = 0; i < _ozf->zooms(); i++) { diff --git a/src/map/offlinemap.h b/src/map/offlinemap.h index bddaf803..f69543ae 100644 --- a/src/map/offlinemap.h +++ b/src/map/offlinemap.h @@ -41,11 +41,11 @@ public: bool isValid() const {return _valid;} QString errorString() const {return _errorString;} - QPointF ll2pp(const Coordinates &c) const - {return _projection.ll2xy(c).toPointF();} - QPointF xy2pp(const QPointF &p) const + PointD ll2pp(const Coordinates &c) const + {return _projection.ll2xy(c);} + PointD xy2pp(const QPointF &p) const {return _transform.img2proj(p);} - QPointF pp2xy(const QPointF &p) const + QPointF pp2xy(const PointD &p) const {return _transform.proj2img(p);} private: diff --git a/src/map/transform.h b/src/map/transform.h index b8efe330..d113e895 100644 --- a/src/map/transform.h +++ b/src/map/transform.h @@ -30,8 +30,10 @@ public: Transform(const ReferencePoint &p, const PointD &scale); Transform(double matrix[16]); - QPointF proj2img(const QPointF &p) const {return _proj2img.map(p);} - QPointF img2proj(const QPointF &p) const {return _img2proj.map(p);} + QPointF proj2img(const PointD &p) const + {return _proj2img.map(p.toPointF());} + PointD img2proj(const QPointF &p) const + {return _img2proj.map(p);} bool isValid() const {return _proj2img.isInvertible() && _img2proj.isInvertible();} diff --git a/src/map/wmsmap.cpp b/src/map/wmsmap.cpp index dc93ff42..a9aec069 100644 --- a/src/map/wmsmap.cpp +++ b/src/map/wmsmap.cpp @@ -202,7 +202,7 @@ int WMSMap::zoomOut() QPointF WMSMap::ll2xy(const Coordinates &c) const { - return _transform.proj2img(_projection.ll2xy(c).toPointF()); + return _transform.proj2img(_projection.ll2xy(c)); } Coordinates WMSMap::xy2ll(const QPointF &p) const @@ -220,13 +220,13 @@ void WMSMap::draw(QPainter *painter, const QRectF &rect) QList tiles; for (int i = tl.x(); i < br.x(); i++) { for (int j = tl.y(); j < br.y(); j++) { - QPointF ttl(_transform.img2proj(QPointF(i * TILE_SIZE, + PointD ttl(_transform.img2proj(QPointF(i * TILE_SIZE, j * TILE_SIZE))); - QPointF tbr(_transform.img2proj(QPointF(i * TILE_SIZE + TILE_SIZE + PointD tbr(_transform.img2proj(QPointF(i * TILE_SIZE + TILE_SIZE - 1, j * TILE_SIZE + TILE_SIZE - 1))); QRectF bbox = (_cs.axisOrder() == CoordinateSystem::YX) ? QRectF(QPointF(tbr.y(), tbr.x()), QPointF(ttl.y(), ttl.x())) - : QRectF(ttl, tbr); + : QRectF(ttl.toPointF(), tbr.toPointF()); tiles.append(Tile(QPoint(i, j), _zoom, bbox)); } diff --git a/src/map/wmtsmap.cpp b/src/map/wmtsmap.cpp index abc5d887..aeb31ca3 100644 --- a/src/map/wmtsmap.cpp +++ b/src/map/wmtsmap.cpp @@ -200,7 +200,7 @@ void WMTSMap::draw(QPainter *painter, const QRectF &rect) QPointF WMTSMap::ll2xy(const Coordinates &c) const { - return _transform.proj2img(_projection.ll2xy(c).toPointF()); + return _transform.proj2img(_projection.ll2xy(c)); } Coordinates WMTSMap::xy2ll(const QPointF &p) const