1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +01:00

RectC now uses the expected axis direction

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

View File

@ -105,7 +105,7 @@ HEADERS += src/config.h \
src/map/wms.h \
src/map/crs.h \
src/map/coordinatesystem.h \
src/map/point.h \
src/map/pointd.h \
src/data/graph.h \
src/data/poi.h \
src/data/waypoint.h \

View File

@ -150,7 +150,7 @@ void MapView::addWaypoints(const QList<Waypoint> &waypoints)
WaypointItem *wi = new WaypointItem(w, _map);
_waypoints.append(wi);
_wr.unite(wi->waypoint().coordinates());
_wr = _wr.united(wi->waypoint().coordinates());
wi->setZValue(1);
wi->setSize(_waypointSize);
wi->setColor(_waypointColor);

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;

View File

@ -8,7 +8,7 @@ RectC Path::boundingRect() const
return ret;
for (int i = 0; i < size(); i++)
ret.unite(at(i).coordinates());
ret = ret.united(at(i).coordinates());
return ret;
}

View File

@ -2,7 +2,7 @@
#define CT_H
#include "common/coordinates.h"
#include "point.h"
#include "pointd.h"
class CT {
public:

View File

@ -51,15 +51,15 @@ QRectF EmptyMap::bounds() const
return QRectF(ll2xy(Coordinates(-180, 85)), ll2xy(Coordinates(180, -85)));
}
int EmptyMap::zoomFit(const QSize &size, const RectC &br)
int EmptyMap::zoomFit(const QSize &size, const RectC &rect)
{
if (!br.isValid())
if (!rect.isValid())
_zoom = ZOOM_MAX;
else {
QRectF tbr(ll2m(br.topLeft()), ll2m(br.bottomRight()));
QRectF tbr(ll2m(rect.topLeft()), ll2m(rect.bottomRight()));
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
_zoom = limitZoom(scale2zoom(qMax(sc.x(), sc.y())));
_zoom = limitZoom(scale2zoom(qMax(sc.x(), -sc.y())));
}
return _zoom;

View File

@ -16,7 +16,7 @@ public:
qreal resolution(const QRectF &rect) const;
int zoom() const {return _zoom;}
int zoomFit(const QSize &size, const RectC &br);
int zoomFit(const QSize &size, const RectC &rect);
int zoomIn();
int zoomOut();

View File

@ -3,7 +3,7 @@
#include <cmath>
#include <QDebug>
#include "point.h"
#include "pointd.h"
class LinearUnits
{

View File

@ -24,7 +24,7 @@ public:
virtual qreal resolution(const QRectF &rect) const = 0;
virtual int zoom() const = 0;
virtual int zoomFit(const QSize &size, const RectC &br) = 0;
virtual int zoomFit(const QSize &size, const RectC &rect) = 0;
virtual int zoomIn() = 0;
virtual int zoomOut() = 0;

View File

@ -42,8 +42,8 @@ static int scale2zoom(qreal scale)
OnlineMap::OnlineMap(const QString &name, const QString &url,
const Range &zooms, const RectC &bounds, QObject *parent) :
Map(parent), _name(name), _zooms(zooms), _bounds(bounds),
_block(false), _valid(false)
Map(parent), _name(name), _zooms(zooms), _bounds(bounds), _block(false),
_valid(false)
{
QString dir(TILES_DIR + "/" + _name);
@ -90,15 +90,14 @@ int OnlineMap::limitZoom(int zoom) const
return zoom;
}
int OnlineMap::zoomFit(const QSize &size, const RectC &br)
int OnlineMap::zoomFit(const QSize &size, const RectC &rect)
{
if (!br.isValid())
if (!rect.isValid())
_zoom = _zooms.max();
else {
QRectF tbr(ll2m(br.topLeft()), ll2m(br.bottomRight()));
QRectF tbr(ll2m(rect.topLeft()), ll2m(rect.bottomRight()));
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
_zoom = limitZoom(scale2zoom(qMax(sc.x(), sc.y())));
_zoom = limitZoom(scale2zoom(qMax(sc.x(), -sc.y())));
}
return _zoom;

View File

@ -20,7 +20,7 @@ public:
qreal resolution(const QRectF &rect) const;
int zoom() const {return _zoom;}
int zoomFit(const QSize &size, const RectC &br);
int zoomFit(const QSize &size, const RectC &rect);
int zoomIn();
int zoomOut();

View File

@ -5,7 +5,8 @@
#include <QPointF>
#include <QDebug>
class PointD {
class PointD
{
public:
PointD() : _x(NAN), _y(NAN) {}
PointD(double x, double y) : _x(x), _y(y) {}

View File

@ -3,7 +3,7 @@
#include <QDebug>
#include "common/coordinates.h"
#include "point.h"
#include "pointd.h"
#include "linearunits.h"
#include "coordinatesystem.h"

View File

@ -4,7 +4,7 @@
#include <QTransform>
#include <QList>
#include <QDebug>
#include "point.h"
#include "pointd.h"
class ReferencePoint
{

View File

@ -60,15 +60,17 @@ void WMSMap::computeZooms(const RangeF &scaleDenominator)
void WMSMap::updateTransform()
{
double scaleDenominator = _zooms.at(_zoom);
double pixelSpan = sd2res(scaleDenominator);
double pixelSpan = sd2res(_zooms.at(_zoom));
if (_projection.isGeographic())
pixelSpan /= deg2rad(WGS84_RADIUS);
double sx = (_br.x() - _tl.x()) / pixelSpan;
double sy = (_tl.y() - _br.y()) / pixelSpan;
ReferencePoint tl(PointD(0, 0), _boundingBox.topLeft());
ReferencePoint br(PointD(_boundingBox.width() / pixelSpan,
-_boundingBox.height() / pixelSpan), _boundingBox.bottomRight());
ReferencePoint tl(PointD(0, 0), _tl);
ReferencePoint br(PointD(sx, sy), _br);
_transform = Transform(tl, br);
_bounds = QRectF(QPointF(0, 0), QSizeF(sx, sy));
}
bool WMSMap::loadWMS()
@ -82,10 +84,8 @@ bool WMSMap::loadWMS()
}
_projection = wms.projection();
RectC bb = wms.boundingBox().normalized();
_boundingBox = QRectF(_projection.ll2xy(Coordinates(bb.topLeft().lon(),
bb.bottomRight().lat())).toPointF(), _projection.ll2xy(Coordinates(
bb.bottomRight().lon(), bb.topLeft().lat())).toPointF());
_tl = _projection.ll2xy(wms.boundingBox().topLeft());
_br = _projection.ll2xy(wms.boundingBox().bottomRight());
_tileLoader = TileLoader(tileUrl(wms.version()), tilesDir(),
_setup.authorization());
@ -141,17 +141,6 @@ void WMSMap::emitLoaded()
emit loaded();
}
QRectF WMSMap::bounds() const
{
double pixelSpan = sd2res(_zooms.at(_zoom));
if (_projection.isGeographic())
pixelSpan /= deg2rad(WGS84_RADIUS);
QSizeF size(_boundingBox.width() / pixelSpan, -_boundingBox.height()
/ pixelSpan);
return QRectF(QPointF(0, 0), size);
}
qreal WMSMap::resolution(const QRectF &rect) const
{
Coordinates tl = xy2ll((rect.topLeft()));
@ -163,12 +152,13 @@ qreal WMSMap::resolution(const QRectF &rect) const
return ds/ps;
}
int WMSMap::zoomFit(const QSize &size, const RectC &br)
int WMSMap::zoomFit(const QSize &size, const RectC &rect)
{
if (br.isValid()) {
QRectF tbr(_projection.ll2xy(br.topLeft()).toPointF(),
_projection.ll2xy(br.bottomRight()).toPointF());
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
if (rect.isValid()) {
PointD tl(_projection.ll2xy(rect.topLeft()));
PointD br(_projection.ll2xy(rect.bottomRight()));
PointD sc((br.x() - tl.x()) / size.width(), (tl.y() - br.y())
/ size.height());
double resolution = qMax(qAbs(sc.x()), qAbs(sc.y()));
if (_projection.isGeographic())
resolution *= deg2rad(WGS84_RADIUS);

View File

@ -17,11 +17,11 @@ public:
const QString &name() const {return _name;}
QRectF bounds() const;
QRectF bounds() const {return _bounds;}
qreal resolution(const QRectF &rect) const;
int zoom() const {return _zoom;}
int zoomFit(const QSize &size, const RectC &br);
int zoomFit(const QSize &size, const RectC &rect);
int zoomIn();
int zoomOut();
@ -63,7 +63,8 @@ private:
Transform _transform;
CoordinateSystem _cs;
QVector<double> _zooms;
QRectF _boundingBox;
PointD _tl, _br;
QRectF _bounds;
int _zoom;
bool _block;

View File

@ -122,13 +122,14 @@ QRectF WMTSMap::bounds() const
return _bounds.isValid() ? tileBounds.intersected(bounds) : tileBounds;
}
int WMTSMap::zoomFit(const QSize &size, const RectC &br)
int WMTSMap::zoomFit(const QSize &size, const RectC &rect)
{
if (br.isValid()) {
QRectF tbr(_projection.ll2xy(br.topLeft()).toPointF(),
_projection.ll2xy(br.bottomRight()).toPointF());
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
qreal resolution = qMax(qAbs(sc.x()), qAbs(sc.y()));
if (rect.isValid()) {
PointD tl(_projection.ll2xy(rect.topLeft()));
PointD br(_projection.ll2xy(rect.bottomRight()));
PointD sc((br.x() - tl.x()) / size.width(), (tl.y() - br.y())
/ size.height());
double resolution = qMax(qAbs(sc.x()), qAbs(sc.y()));
if (_projection.isGeographic())
resolution *= deg2rad(WGS84_RADIUS);

View File

@ -21,7 +21,7 @@ public:
qreal resolution(const QRectF &rect) const;
int zoom() const {return _zoom;}
int zoomFit(const QSize &size, const RectC &br);
int zoomFit(const QSize &size, const RectC &rect);
int zoomIn();
int zoomOut();