381bool QGeoPathPrivate::operator==(
const QGeoShapePrivate &other)
const
383 if (!QGeoShapePrivate::operator==(other))
386 const QGeoPathPrivate &otherPath =
static_cast<
const QGeoPathPrivate &>(other);
387 if (m_path.size() != otherPath.m_path.size())
389 return m_width == otherPath.m_width && m_path == otherPath.m_path;
397bool QGeoPathPrivate::lineContains(
const QGeoCoordinate &coordinate)
const
414 double lineRadius = qMax(width() * 0.5, 0.2);
416 if (m_path.isEmpty())
418 else if (m_path.size() == 1)
419 return (m_path[0].distanceTo(coordinate) <= lineRadius);
421 Q_ASSERT(m_path.size() > 1);
422 const QDoubleVector2D pt = QWebMercator::coordToMercator(coordinate);
423 QDoubleVector2D last = QWebMercator::coordToMercator(m_path[0]);
424 for (qsizetype i = 1; i < m_path.size(); i++) {
425 const QDoubleVector2D here = QWebMercator::coordToMercator(m_path[i]);
427 if (here.x() > last.x() + 0.5)
428 last.setX(last.x() + 1.0);
429 else if (here.x() < last.x() - 0.5)
430 last.setX(last.x() - 1.0);
434 if (m_path[i].distanceTo(coordinate) <= lineRadius)
439 QDoubleVector2D p = pt;
441 QDoubleVector2D mid = (last + here) / 2.0;
443 if (p.x() > mid.x() + 0.5)
445 else if (p.x() < mid.x() - 0.5)
449 for (
int j = 0; j < 2; ++j) {
450 const QDoubleVector2D pml = p - last, hml = here - last;
451 const double u = (pml.x() * hml.x() + pml.y() * hml.y()) / hml.lengthSquared();
453 const QDoubleVector2D candidate = u > 0 ? u < 1 ? last + u * hml : here : last;
454 const double distance = coordinate.distanceTo(QWebMercator::mercatorToCoord(candidate));
455 if (distance <= lineRadius)
460
461
462
463
464
465
466
467
468
469
470
471 if (p.x() > qMin(last.x(), here.x()) + 0.5)
473 else if (p.x() < qMax(last.x(), here.x()) - 0.5)
503double QGeoPathPrivate::length(qsizetype indexFrom, qsizetype indexTo)
const
505 if (path().isEmpty())
508 bool wrap = indexTo == -1;
509 if (indexTo < 0 || indexTo >= path().size())
510 indexTo = path().size() - 1;
514 for (qsizetype i = indexFrom; i < indexTo; i++)
515 len += m_path[i].distanceTo(m_path[i+1]);
517 len += m_path.last().distanceTo(m_path.first());
539void QGeoPathPrivate::translate(
double degreesLatitude,
double degreesLongitude)
542 QList<
double> m_deltaXs;
543 double m_minX, m_maxX, m_minLati, m_maxLati;
545 computeBBox(m_path, m_deltaXs, m_minX, m_maxX, m_minLati, m_maxLati, m_bbox);
547 if (degreesLatitude > 0.0)
548 degreesLatitude = qMin(degreesLatitude, 90.0 - m_maxLati);
550 degreesLatitude = qMax(degreesLatitude, -90.0 - m_minLati);
551 for (QGeoCoordinate &p: m_path) {
552 p.setLatitude(p.latitude() + degreesLatitude);
553 p.setLongitude(QLocationUtils::wrapLong(p.longitude() + degreesLongitude));
555 m_bbox.translate(degreesLatitude, degreesLongitude);
556 m_leftBoundWrapped = QWebMercator::coordToMercator(m_bbox.topLeft()).x();
566size_t QGeoPathPrivate::hash(size_t seed)
const
568 const size_t res = qHashRange(m_path.cbegin(), m_path.cend(), seed);
569 return qHashMulti(seed, res, m_width);
595void QGeoPathPrivate::insertCoordinate(qsizetype index,
const QGeoCoordinate &coordinate)
597 if (index < 0 || index > m_path.size() || !coordinate.isValid())
599 m_path.insert(index, coordinate);
603void QGeoPathPrivate::replaceCoordinate(qsizetype index,
const QGeoCoordinate &coordinate)
605 if (index < 0 || index >= m_path.size() || !coordinate.isValid())
607 m_path[index] = coordinate;
630void QGeoPathPrivate::computeBoundingBox()
632 QList<
double> m_deltaXs;
633 double m_minX, m_maxX, m_minLati, m_maxLati;
635 computeBBox(m_path, m_deltaXs, m_minX, m_maxX, m_minLati, m_maxLati, m_bbox);
636 m_leftBoundWrapped = QWebMercator::coordToMercator(m_bbox.topLeft()).x();
666void QGeoPathPrivateEager::translate(
double degreesLatitude,
double degreesLongitude)
668 if (degreesLatitude > 0.0)
669 degreesLatitude = qMin(degreesLatitude, 90.0 - m_maxLati);
671 degreesLatitude = qMax(degreesLatitude, -90.0 - m_minLati);
672 for (QGeoCoordinate &p: m_path) {
673 p.setLatitude(p.latitude() + degreesLatitude);
674 p.setLongitude(QLocationUtils::wrapLong(p.longitude() + degreesLongitude));
676 m_bbox.translate(degreesLatitude, degreesLongitude);
677 m_minLati += degreesLatitude;
678 m_maxLati += degreesLatitude;
679 m_leftBoundWrapped = QWebMercator::coordToMercator(m_bbox.topLeft()).x();
693 computeBBox(m_path, m_deltaXs, m_minX, m_maxX, m_minLati, m_maxLati, m_bbox);
699 updateBBox(m_path, m_deltaXs, m_minX, m_maxX, m_minLati, m_maxLati, m_bbox);
708QGeoPathEager::QGeoPathEager(
const QList<QGeoCoordinate> &path,
const qreal &width) : QGeoPath()
710 d_ptr =
new QGeoPathPrivateEager(path, width);