2020-12-13 19:40:09 +01:00
|
|
|
#include <cmath>
|
2018-06-30 12:14:58 +02:00
|
|
|
#include <QLineF>
|
|
|
|
#include "map.h"
|
|
|
|
|
2020-12-13 19:40:09 +01:00
|
|
|
|
|
|
|
#define SAMPLES 100
|
|
|
|
|
2023-05-06 21:53:40 +02:00
|
|
|
static void growLeft(const Coordinates &c, RectC &rect)
|
2020-12-13 19:40:09 +01:00
|
|
|
{
|
|
|
|
if (c.lon() < rect.left())
|
|
|
|
rect.setLeft(c.lon());
|
|
|
|
}
|
|
|
|
|
2023-05-06 21:53:40 +02:00
|
|
|
static void growRight(const Coordinates &c, RectC &rect)
|
2020-12-13 19:40:09 +01:00
|
|
|
{
|
|
|
|
if (c.lon() > rect.right())
|
|
|
|
rect.setRight(c.lon());
|
|
|
|
}
|
|
|
|
|
2023-05-06 21:53:40 +02:00
|
|
|
static void growTop(const Coordinates &c, RectC &rect)
|
2020-12-13 19:40:09 +01:00
|
|
|
{
|
|
|
|
if (c.lat() > rect.top())
|
|
|
|
rect.setTop(c.lat());
|
|
|
|
}
|
|
|
|
|
2023-05-06 21:53:40 +02:00
|
|
|
static void growBottom(const Coordinates &c, RectC &rect)
|
2020-12-13 19:40:09 +01:00
|
|
|
{
|
|
|
|
if (c.lat() < rect.bottom())
|
|
|
|
rect.setBottom(c.lat());
|
|
|
|
}
|
|
|
|
|
2023-05-04 09:38:35 +02:00
|
|
|
RectC Map::llBounds(const Projection &proj)
|
2020-12-13 19:40:09 +01:00
|
|
|
{
|
2023-05-04 09:38:35 +02:00
|
|
|
Q_UNUSED(proj);
|
|
|
|
|
|
|
|
/* We use bounds() and xy2ll() here as this fallback implementation is
|
|
|
|
used ONLY for maps providing those functions since map creation. */
|
2020-12-13 19:40:09 +01:00
|
|
|
QRectF b(bounds());
|
|
|
|
double dx = b.width() / SAMPLES;
|
|
|
|
double dy = b.height() / SAMPLES;
|
|
|
|
|
|
|
|
Coordinates tl(xy2ll(b.topLeft()));
|
|
|
|
Coordinates br(xy2ll(b.bottomRight()));
|
|
|
|
RectC rect(tl, br);
|
|
|
|
|
|
|
|
for (int i = 0; i <= SAMPLES; i++) {
|
|
|
|
double x = b.left() + i * dx;
|
2023-05-06 21:53:40 +02:00
|
|
|
growBottom(xy2ll(QPointF(x, b.bottom())), rect);
|
|
|
|
growTop(xy2ll(QPointF(x, b.top())), rect);
|
2020-12-13 19:40:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i <= SAMPLES; i++) {
|
|
|
|
double y = b.top() + i * dy;
|
2023-05-06 21:53:40 +02:00
|
|
|
growLeft(xy2ll(QPointF(b.left(), y)), rect);
|
|
|
|
growRight(xy2ll(QPointF(b.right(), y)), rect);
|
2020-12-13 19:40:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2018-06-30 12:14:58 +02:00
|
|
|
qreal Map::resolution(const QRectF &rect)
|
|
|
|
{
|
|
|
|
qreal cy = rect.center().y();
|
|
|
|
QPointF cl(rect.left(), cy);
|
|
|
|
QPointF cr(rect.right(), cy);
|
|
|
|
|
|
|
|
qreal ds = xy2ll(cl).distanceTo(xy2ll(cr));
|
|
|
|
qreal ps = QLineF(cl, cr).length();
|
|
|
|
|
|
|
|
return ds/ps;
|
|
|
|
}
|