382bool QGeoPathPrivate::operator==(
const QGeoShapePrivate &other)
const
384 if (!QGeoShapePrivate::operator==(other))
387 const QGeoPathPrivate &otherPath =
static_cast<
const QGeoPathPrivate &>(other);
388 if (m_path.size() != otherPath.m_path.size())
390 return m_width == otherPath.m_width && m_path == otherPath.m_path;
398bool QGeoPathPrivate::lineContains(
const QGeoCoordinate &coordinate)
const
413 const_cast<QGeoPathPrivate &>(*
this).computeBoundingBox();
415 double lineRadius = qMax(width() * 0.5, 0.2);
417 if (m_path.isEmpty())
419 else if (m_path.size() == 1)
420 return (m_path[0].distanceTo(coordinate) <= lineRadius);
422 QDoubleVector2D p = QWebMercator::coordToMercator(coordinate);
423 if (p.x() < m_leftBoundWrapped)
424 p.setX(p.x() + m_leftBoundWrapped);
428 if (!m_path.isEmpty()) {
429 a = QWebMercator::coordToMercator(m_path[0]);
430 if (a.x() < m_leftBoundWrapped)
431 a.setX(a.x() + m_leftBoundWrapped);
433 for (qsizetype i = 1; i < m_path.size(); i++) {
434 b = QWebMercator::coordToMercator(m_path[i]);
435 if (b.x() < m_leftBoundWrapped)
436 b.setX(b.x() + m_leftBoundWrapped);
440 double u = ((p.x() - a.x()) * (b.x() - a.x()) + (p.y() - a.y()) * (b.y() - a.y()) ) / (b - a).lengthSquared();
441 QDoubleVector2D intersection(a.x() + u * (b.x() - a.x()) , a.y() + u * (b.y() - a.y()) );
443 QDoubleVector2D candidate = ( (p-a).length() < (p-b).length() ) ? a : b;
446 && (p-intersection).length() < (p-candidate).length() )
447 candidate = intersection;
450 if (candidate.x() > 1.0)
451 candidate.setX(candidate.x() - m_leftBoundWrapped);
453 QGeoCoordinate closest = QWebMercator::mercatorToCoord(candidate);
455 double distanceMeters = coordinate.distanceTo(closest);
456 if (distanceMeters <= lineRadius)
465 return (m_path[0].distanceTo(coordinate) <= lineRadius);
485double QGeoPathPrivate::length(qsizetype indexFrom, qsizetype indexTo)
const
487 if (path().isEmpty())
490 bool wrap = indexTo == -1;
491 if (indexTo < 0 || indexTo >= path().size())
492 indexTo = path().size() - 1;
496 for (qsizetype i = indexFrom; i < indexTo; i++)
497 len += m_path[i].distanceTo(m_path[i+1]);
499 len += m_path.last().distanceTo(m_path.first());
521void QGeoPathPrivate::translate(
double degreesLatitude,
double degreesLongitude)
524 QList<
double> m_deltaXs;
525 double m_minX, m_maxX, m_minLati, m_maxLati;
527 computeBBox(m_path, m_deltaXs, m_minX, m_maxX, m_minLati, m_maxLati, m_bbox);
529 if (degreesLatitude > 0.0)
530 degreesLatitude = qMin(degreesLatitude, 90.0 - m_maxLati);
532 degreesLatitude = qMax(degreesLatitude, -90.0 - m_minLati);
533 for (QGeoCoordinate &p: m_path) {
534 p.setLatitude(p.latitude() + degreesLatitude);
535 p.setLongitude(QLocationUtils::wrapLong(p.longitude() + degreesLongitude));
537 m_bbox.translate(degreesLatitude, degreesLongitude);
538 m_leftBoundWrapped = QWebMercator::coordToMercator(m_bbox.topLeft()).x();
548size_t QGeoPathPrivate::hash(size_t seed)
const
550 const size_t res = qHashRange(m_path.cbegin(), m_path.cend(), seed);
551 return qHashMulti(seed, res, m_width);
577void QGeoPathPrivate::insertCoordinate(qsizetype index,
const QGeoCoordinate &coordinate)
579 if (index < 0 || index > m_path.size() || !coordinate.isValid())
581 m_path.insert(index, coordinate);
585void QGeoPathPrivate::replaceCoordinate(qsizetype index,
const QGeoCoordinate &coordinate)
587 if (index < 0 || index >= m_path.size() || !coordinate.isValid())
589 m_path[index] = coordinate;
612void QGeoPathPrivate::computeBoundingBox()
614 QList<
double> m_deltaXs;
615 double m_minX, m_maxX, m_minLati, m_maxLati;
617 computeBBox(m_path, m_deltaXs, m_minX, m_maxX, m_minLati, m_maxLati, m_bbox);
618 m_leftBoundWrapped = QWebMercator::coordToMercator(m_bbox.topLeft()).x();
648void QGeoPathPrivateEager::translate(
double degreesLatitude,
double degreesLongitude)
650 if (degreesLatitude > 0.0)
651 degreesLatitude = qMin(degreesLatitude, 90.0 - m_maxLati);
653 degreesLatitude = qMax(degreesLatitude, -90.0 - m_minLati);
654 for (QGeoCoordinate &p: m_path) {
655 p.setLatitude(p.latitude() + degreesLatitude);
656 p.setLongitude(QLocationUtils::wrapLong(p.longitude() + degreesLongitude));
658 m_bbox.translate(degreesLatitude, degreesLongitude);
659 m_minLati += degreesLatitude;
660 m_maxLati += degreesLatitude;
661 m_leftBoundWrapped = QWebMercator::coordToMercator(m_bbox.topLeft()).x();
675 computeBBox(m_path, m_deltaXs, m_minX, m_maxX, m_minLati, m_maxLati, m_bbox);
681 updateBBox(m_path, m_deltaXs, m_minX, m_maxX, m_minLati, m_maxLati, m_bbox);
690QGeoPathEager::QGeoPathEager(
const QList<QGeoCoordinate> &path,
const qreal &width) : QGeoPath()
692 d_ptr =
new QGeoPathPrivateEager(path, width);