[Marble-commits] KDE/kdeedu/marble/src/lib/routing
Dennis Nienhüser
earthwings at gentoo.org
Sun Sep 26 20:32:42 CEST 2010
SVN commit 1179998 by nienhueser:
The distance to the next instruction is not a good threshold to determine a deviation from the route. Use a fixed threshold instead (250 m atm) and check all waypoints, not only instruction points.
M +23 -7 RoutingModel.cpp
M +3 -0 RoutingModel.h
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingModel.cpp #1179997:1179998
@@ -75,6 +75,8 @@
QMap<RoutingInstruction::TurnType,QPixmap> m_turnTypePixmaps;
void importPlacemark( const GeoDataPlacemark *placemark );
+
+ bool deviatedFromRoute( const GeoDataCoordinates &position, const QVector<GeoDataCoordinates> &waypoints ) const;
};
RoutingModelPrivate::RoutingModelPrivate()
@@ -103,6 +105,21 @@
m_turnTypePixmaps[RoutingInstruction::RoundaboutExit] = QPixmap( ":/data/bitmaps/turn-roundabout-far.png");
}
+bool RoutingModelPrivate::deviatedFromRoute( const GeoDataCoordinates &position, const QVector<GeoDataCoordinates> &waypoints ) const
+{
+ /** @todo: It might make sense to take other factors into account here:
+ * Position accuracy, speed, transport type */
+ /** @todo: Cache bounding box / expected next target for a quicker check */
+ qreal const threshold = 250.0 / EARTH_RADIUS;
+ foreach( const GeoDataCoordinates &coordinate, waypoints ) {
+ if ( distanceSphere( position, coordinate ) < threshold ) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
void RoutingModelPrivate::importPlacemark( const GeoDataPlacemark *placemark )
{
GeoDataGeometry* geometry = placemark->geometry();
@@ -438,21 +455,20 @@
totalTimeRemaining = 0.0;
totalDistanceRemaining = 0.0;
}
-
- if( d->m_nextInstructionIndex > 0 && distanceRemaining < instructions[d->m_nextInstructionIndex-1].instructionDistance ) {
- d->m_routeLeft = false;
}
- else {
- d->m_routeLeft = true;
- }
- }
d->m_nextInstructionDistance = distanceRemaining;
d->m_totalTimeRemaining = totalTimeRemaining;
d->m_totalDistanceRemaining = totalDistanceRemaining;
emit nextInstruction( d->m_totalTimeRemaining, d->m_totalDistanceRemaining );
+
+ bool const deviated = d->deviatedFromRoute( location, wayPoints );
+ if ( deviated != d->m_routeLeft ) {
+ d->m_routeLeft = deviated;
+ emit deviatedFromRoute( d->m_routeLeft );
}
}
+}
qreal RoutingModel::remainingTime() const
{
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingModel.h #1179997:1179998
@@ -35,6 +35,8 @@
{
Q_OBJECT
+ Q_PROPERTY( bool deviatedFromRoute READ deviatedFromRoute NOTIFY deviatedFromRoute )
+
public:
struct Duration
{
@@ -164,6 +166,7 @@
*/
void nextInstruction( qint32 totalTimeRemaining, qreal totalDistanceRemaining );
void routeCalculated( int );
+ void deviatedFromRoute( bool deviated );
private:
RoutingModelPrivate *const d;
More information about the Marble-commits
mailing list