[Marble-commits] KDE/kdeedu/marble/src/lib/routing
Dennis Nienhüser
earthwings at gentoo.org
Mon Aug 2 20:47:40 CEST 2010
SVN commit 1158407 by nienhueser:
Allow slacker routes to replace similar ones with lower scores. Fix detection whether routes contain turn instructions.
M +20 -10 AlternativeRoutesModel.cpp
--- trunk/KDE/kdeedu/marble/src/lib/routing/AlternativeRoutesModel.cpp #1158406:1158407
@@ -72,7 +72,7 @@
/**
* (Primitive) scoring for routes
*/
- static bool lessThan( const GeoDataDocument* one, const GeoDataDocument* two );
+ static bool higherScore( const GeoDataDocument* one, const GeoDataDocument* two );
/**
* Returns true if the given route contains instructions (placemarks with turn instructions)
@@ -191,7 +191,7 @@
return 1 - distance / lengthA;
}
-bool AlternativeRoutesModelPrivate::lessThan( const GeoDataDocument* one, const GeoDataDocument* two )
+bool AlternativeRoutesModelPrivate::higherScore( const GeoDataDocument* one, const GeoDataDocument* two )
{
bool hasInstructonsA = hasInstructions( one );
bool hasInstructonsB = hasInstructions( two );
@@ -211,21 +211,18 @@
bool AlternativeRoutesModelPrivate::hasInstructions( const GeoDataDocument* document )
{
+ QStringList blacklist = QStringList() << "" << "Route" << "Tessellated";
QVector<GeoDataFolder*> folders = document->folderList();
foreach( const GeoDataFolder *folder, folders ) {
foreach( const GeoDataPlacemark *placemark, folder->placemarkList() ) {
- GeoDataGeometry* geometry = placemark->geometry();
- GeoDataLineString* lineString = dynamic_cast<GeoDataLineString*>( geometry );
- if ( !lineString && !placemark->name().isEmpty() && placemark->name() != "Route" ) {
+ if ( !blacklist.contains( placemark->name() ) ) {
return true;
}
}
}
foreach( const GeoDataPlacemark *placemark, document->placemarkList() ) {
- GeoDataGeometry* geometry = placemark->geometry();
- GeoDataLineString* lineString = dynamic_cast<GeoDataLineString*>( geometry );
- if ( !lineString && !placemark->name().isEmpty() && placemark->name() != "Route" ) {
+ if ( !blacklist.contains( placemark->name() ) ) {
return true;
}
}
@@ -309,7 +306,7 @@
void AlternativeRoutesModel::addRestrainedRoutes()
{
Q_ASSERT( d->m_routes.isEmpty() );
- qSort( d->m_restrainedRoutes.begin(), d->m_restrainedRoutes.end(), AlternativeRoutesModelPrivate::lessThan );
+ qSort( d->m_restrainedRoutes.begin(), d->m_restrainedRoutes.end(), AlternativeRoutesModelPrivate::higherScore );
foreach( GeoDataDocument* route, d->m_restrainedRoutes ) {
if ( !d->filter( route ) ) {
@@ -339,7 +336,20 @@
return;
} else if ( d->m_routes.isEmpty() && !d->m_restrainedRoutes.isEmpty() ) {
d->m_restrainedRoutes.push_back( document );
- } else if ( !d->filter( document ) ) {
+ } else {
+ for ( int i=0; i<d->m_routes.size(); ++i ) {
+ qreal similarity = AlternativeRoutesModelPrivate::similarity( document, d->m_routes.at( i ) );
+ if ( similarity > 0.8 ) {
+ if ( AlternativeRoutesModelPrivate::higherScore( document, d->m_routes.at( i ) ) ) {
+ d->m_routes[i] = document;
+ QModelIndex changed = index( i );
+ emit dataChanged( changed, changed );
+ }
+
+ return;
+ }
+ }
+
Q_ASSERT( !d->m_routes.isEmpty() );
int affected = d->m_routes.size();
beginInsertRows( QModelIndex(), affected, affected );
More information about the Marble-commits
mailing list