374bool QGeoPathPrivateBase::operator==(
const QGeoShapePrivate &other)
const
376 if (!QGeoShapePrivate::operator==(other))
379 const QGeoPathPrivateBase &otherBase =
static_cast<
const QGeoPathPrivateBase &>(other);
380 return m_path == otherBase.m_path;
400double QGeoPathPrivateBase::length(qsizetype indexFrom, qsizetype indexTo)
const
402 if (path().isEmpty())
405 bool wrap = indexTo == -1;
406 if (indexTo < 0 || indexTo >= path().size())
407 indexTo = path().size() - 1;
411 for (qsizetype i = indexFrom; i < indexTo; i++)
412 len += m_path[i].distanceTo(m_path[i + 1]);
414 len += m_path.last().distanceTo(m_path.first());
436void QGeoPathPrivateBase::translate(
double degreesLatitude,
double degreesLongitude)
439 QList<
double> deltaXs;
440 double minX, maxX, minLati, maxLati;
442 computeBBox(m_path, deltaXs, minX, maxX, minLati, maxLati, m_bbox);
444 if (degreesLatitude > 0.0)
445 degreesLatitude = qMin(degreesLatitude, 90.0 - maxLati);
447 degreesLatitude = qMax(degreesLatitude, -90.0 - minLati);
448 for (QGeoCoordinate &p: m_path) {
449 p.setLatitude(p.latitude() + degreesLatitude);
450 p.setLongitude(QLocationUtils::wrapLong(p.longitude() + degreesLongitude));
452 m_bbox.translate(degreesLatitude, degreesLongitude);
453 m_leftBoundWrapped = QWebMercator::coordToMercator(m_bbox.topLeft()).x();
480void QGeoPathPrivateBase::insertCoordinate(qsizetype index,
const QGeoCoordinate &coordinate)
482 if (index < 0 || index > m_path.size() || !coordinate.isValid())
484 m_path.insert(index, coordinate);
488void QGeoPathPrivateBase::replaceCoordinate(qsizetype index,
const QGeoCoordinate &coordinate)
490 if (index < 0 || index >= m_path.size() || !coordinate.isValid())
492 m_path[index] = coordinate;
510void QGeoPathPrivateBase::computeBoundingBox()
512 QList<
double> deltaXs;
513 double minX, maxX, minLati, maxLati;
515 computeBBox(m_path, deltaXs, minX, maxX, minLati, maxLati, m_bbox);
516 m_leftBoundWrapped = QWebMercator::coordToMercator(m_bbox.topLeft()).x();
546bool QGeoPathPrivate::operator==(
const QGeoShapePrivate &other)
const
548 if (!QGeoPathPrivateBase::operator==(other))
551 const QGeoPathPrivate &otherPath =
static_cast<
const QGeoPathPrivate &>(other);
552 return m_width == otherPath.m_width;
555bool QGeoPathPrivate::lineContains(
const QGeoCoordinate &coordinate)
const
572 double lineRadius = qMax(width() * 0.5, 0.2);
574 if (m_path.isEmpty())
576 else if (m_path.size() == 1)
577 return (m_path[0].distanceTo(coordinate) <= lineRadius);
579 Q_ASSERT(m_path.size() > 1);
580 const QDoubleVector2D pt = QWebMercator::coordToMercator(coordinate);
581 QDoubleVector2D last = QWebMercator::coordToMercator(m_path[0]);
582 for (qsizetype i = 1; i < m_path.size(); i++) {
583 const QDoubleVector2D here = QWebMercator::coordToMercator(m_path[i]);
585 if (here.x() > last.x() + 0.5)
586 last.setX(last.x() + 1.0);
587 else if (here.x() < last.x() - 0.5)
588 last.setX(last.x() - 1.0);
592 if (m_path[i].distanceTo(coordinate) <= lineRadius)
597 QDoubleVector2D p = pt;
599 QDoubleVector2D mid = (last + here) / 2.0;
601 if (p.x() > mid.x() + 0.5)
603 else if (p.x() < mid.x() - 0.5)
607 for (
int j = 0; j < 2; ++j) {
608 const QDoubleVector2D pml = p - last, hml = here - last;
609 const double u = (pml.x() * hml.x() + pml.y() * hml.y()) / hml.lengthSquared();
611 const QDoubleVector2D candidate = u > 0 ? u < 1 ? last + u * hml : here : last;
612 const double distance = coordinate.distanceTo(QWebMercator::mercatorToCoord(candidate));
613 if (distance <= lineRadius)
618
619
620
621
622
623
624
625
626
627
628
629 if (p.x() > qMin(last.x(), here.x()) + 0.5)
631 else if (p.x() < qMax(last.x(), here.x()) - 0.5)
690void QGeoPathPrivateEager::markDirty()
693 computeBBox(m_path, m_deltaXs, m_minX, m_maxX, m_minLati, m_maxLati, m_bbox);
694 m_leftBoundWrapped = QWebMercator::coordToMercator(m_bbox.topLeft()).x();
697void QGeoPathPrivateEager::translate(
double degreesLatitude,
double degreesLongitude)
699 if (degreesLatitude > 0.0)
700 degreesLatitude = qMin(degreesLatitude, 90.0 - m_maxLati);
702 degreesLatitude = qMax(degreesLatitude, -90.0 - m_minLati);
703 for (QGeoCoordinate &p: m_path) {
704 p.setLatitude(p.latitude() + degreesLatitude);
705 p.setLongitude(QLocationUtils::wrapLong(p.longitude() + degreesLongitude));
707 m_bbox.translate(degreesLatitude, degreesLongitude);
708 m_minLati += degreesLatitude;
709 m_maxLati += degreesLatitude;
710 m_leftBoundWrapped = QWebMercator::coordToMercator(m_bbox.topLeft()).x();
729 updateBBox(m_path, m_deltaXs, m_minX, m_maxX, m_minLati, m_maxLati, m_bbox);
738QGeoPathEager::QGeoPathEager(
const QList<QGeoCoordinate> &path,
const qreal &width) : QGeoPath()
740 d_ptr =
new QGeoPathPrivateEager(path, width);