diff options
author | Aaron McCarthy <mccarthy.aaron@gmail.com> | 2014-07-28 09:57:04 +1000 |
---|---|---|
committer | Aaron McCarthy <mccarthy.aaron@gmail.com> | 2014-12-04 05:31:54 +0100 |
commit | b8681cdb51cc5d7040ecbe08b014bace2444c6f1 (patch) | |
tree | ebfe6a4e4cbbf178b1df2339abf91f7b4c84a2cf /src/positioning/qgeocircle.cpp | |
parent | fddb7c51231e1649081de3a1d5f2ad191e9cd7dc (diff) | |
download | qtlocation-b8681cdb51cc5d7040ecbe08b014bace2444c6f1.tar.gz |
Add center() function to QGeoShape.
It is frequently useful to calculate the geometric center of a shape.
Both QGeoCircle and QGeoRectangle already define center() functions,
however, the application developer must cast each QGeoShape into either
a QGeoCirlce or QGeoRectangle before calling. Providing
QGeoShape::center() allows application code to be simplified.
Existing QGeoCircle::center() and QGeoRectangle::center() functions are
kept for compatibility.
Change-Id: I92b727ab5e713f70174588a27040446c992ae14e
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/positioning/qgeocircle.cpp')
-rw-r--r-- | src/positioning/qgeocircle.cpp | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/positioning/qgeocircle.cpp b/src/positioning/qgeocircle.cpp index 459ce824..61336d1f 100644 --- a/src/positioning/qgeocircle.cpp +++ b/src/positioning/qgeocircle.cpp @@ -151,7 +151,7 @@ bool QGeoCircle::operator!=(const QGeoCircle &other) const bool QGeoCirclePrivate::isValid() const { - return center.isValid() && !qIsNaN(radius) && radius >= -1e-7; + return m_center.isValid() && !qIsNaN(radius) && radius >= -1e-7; } bool QGeoCirclePrivate::isEmpty() const @@ -166,17 +166,17 @@ void QGeoCircle::setCenter(const QGeoCoordinate ¢er) { Q_D(QGeoCircle); - d->center = center; + d->m_center = center; } /*! - Returns the center coordinate of this geo circle. + Returns the center coordinate of this geo circle. Equivalent to QGeoShape::center(). */ QGeoCoordinate QGeoCircle::center() const { Q_D(const QGeoCircle); - return d->center; + return d->center(); } /*! @@ -205,13 +205,18 @@ bool QGeoCirclePrivate::contains(const QGeoCoordinate &coordinate) const return false; // see QTBUG-41447 for details - qreal distance = center.distanceTo(coordinate); + qreal distance = m_center.distanceTo(coordinate); if (qFuzzyCompare(distance, radius) || distance <= radius) return true; return false; } +QGeoCoordinate QGeoCirclePrivate::center() const +{ + return m_center; +} + /*! Extends the circle to include \a coordinate */ @@ -220,7 +225,7 @@ void QGeoCirclePrivate::extendShape(const QGeoCoordinate &coordinate) if (!isValid() || !coordinate.isValid() || contains(coordinate)) return; - radius = center.distanceTo(coordinate); + radius = m_center.distanceTo(coordinate); } /*! @@ -235,8 +240,8 @@ void QGeoCircle::translate(double degreesLatitude, double degreesLongitude) Q_D(QGeoCircle); - double lat = d->center.latitude(); - double lon = d->center.longitude(); + double lat = d->m_center.latitude(); + double lon = d->m_center.longitude(); lat += degreesLatitude; lon += degreesLongitude; @@ -262,7 +267,7 @@ void QGeoCircle::translate(double degreesLatitude, double degreesLongitude) lon -= 180; } - d->center = QGeoCoordinate(lat, lon); + d->m_center = QGeoCoordinate(lat, lon); } /*! @@ -290,12 +295,12 @@ QGeoCirclePrivate::QGeoCirclePrivate() } QGeoCirclePrivate::QGeoCirclePrivate(const QGeoCoordinate ¢er, qreal radius) -: QGeoShapePrivate(QGeoShape::CircleType), center(center), radius(radius) +: QGeoShapePrivate(QGeoShape::CircleType), m_center(center), radius(radius) { } QGeoCirclePrivate::QGeoCirclePrivate(const QGeoCirclePrivate &other) -: QGeoShapePrivate(QGeoShape::CircleType), center(other.center), +: QGeoShapePrivate(QGeoShape::CircleType), m_center(other.m_center), radius(other.radius) { } @@ -314,7 +319,7 @@ bool QGeoCirclePrivate::operator==(const QGeoShapePrivate &other) const const QGeoCirclePrivate &otherCircle = static_cast<const QGeoCirclePrivate &>(other); - return radius == otherCircle.radius && center == otherCircle.center; + return radius == otherCircle.radius && m_center == otherCircle.m_center; } QT_END_NAMESPACE |