summaryrefslogtreecommitdiffstats
path: root/src/location/quickmapitems/qdeclarativegeomapitemutils.cpp
diff options
context:
space:
mode:
authorMatthias Rauter <matthias.rauter@qt.io>2023-01-26 17:18:50 +0100
committerMatthias Rauter <matthias.rauter@qt.io>2023-02-14 16:31:13 +0100
commit8b9ecad4bed0150adcbdf91db3f5f9507a156fd6 (patch)
tree6cd08872c366a32ed041701654d15559325fd464 /src/location/quickmapitems/qdeclarativegeomapitemutils.cpp
parentb842a6cdcce0ee43a48ec084180d9dc065b599a1 (diff)
Correct and improve the rendering of QuickMapItems
Various MapItems were not rendered correctly, especially in corner cases. This change ensures that MapItems are rendered correctly in the vast majority of cases. All MapItems are shown correctly if they wrap around the globe and appear twice on the map. Circles that span around the globe or are located near poles are shown correclty and filled all the way to the border of the map. Polygons are shown correctly including their holes. The code was simplified and some artefacts of previous implementations were removed. Fixes: QTBUG-110701 Fixes: QTBUG-110511 Pick-to: 6.5 Change-Id: I1110659989436cd5a93f6ec26f75caa06d5f2b71 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/location/quickmapitems/qdeclarativegeomapitemutils.cpp')
-rw-r--r--src/location/quickmapitems/qdeclarativegeomapitemutils.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/location/quickmapitems/qdeclarativegeomapitemutils.cpp b/src/location/quickmapitems/qdeclarativegeomapitemutils.cpp
index 6a79b33b..a1501dd6 100644
--- a/src/location/quickmapitems/qdeclarativegeomapitemutils.cpp
+++ b/src/location/quickmapitems/qdeclarativegeomapitemutils.cpp
@@ -16,6 +16,31 @@ QT_BEGIN_NAMESPACE
namespace QDeclarativeGeoMapItemUtils {
+double distanceSqrPointLine(double p0_x
+ , double p0_y
+ , double p1_x
+ , double p1_y
+ , double p2_x
+ , double p2_y)
+{
+ const double t_x = p2_x - p1_x;
+ const double t_y = p2_y - p1_y;
+ const double p_x = p0_x - p1_x;
+ const double p_y = p0_y - p1_y;
+ const double tsqr = t_x * t_x + t_y * t_y;
+
+ if (tsqr == 0)
+ return qInf();
+
+ double alpha = (p_x * t_x + p_y * t_y) / tsqr;
+ alpha = qBound<double>(0, alpha, 1);
+
+ const double dx = p_x - t_x * alpha;
+ const double dy = p_y - t_y * alpha;
+
+ return dx * dx + dy * dy;
+}
+
void wrapPath(const QList<QGeoCoordinate> &perimeter,
const QGeoCoordinate &geoLeftBound,
const QGeoProjectionWebMercator &p,
@@ -150,6 +175,22 @@ void projectBbox(const QList<QDoubleVector2D> &clippedBbox,
projectedBbox.closeSubpath();
}
+
+QRectF boundingRectangleFromList(const QList<QDoubleVector2D> &list)
+{
+ double xMin = qInf();
+ double xMax = -qInf();
+ double yMin = qInf();
+ double yMax = -qInf();
+ for (const auto &coord : list) {
+ xMin = qMin(xMin, coord.x());
+ xMax = qMax(xMax, coord.x());
+ yMin = qMin(yMin, coord.y());
+ yMax = qMax(yMax, coord.y());
+ }
+ return QRectF(xMin, yMin, xMax - xMin, yMax - yMin);
+}
+
} // namespace QDeclarativeGeoMapItemUtils
QT_END_NAMESPACE