Marble

InstructionTransformation.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2010 Dennis Nienhüser <[email protected]>
4 //
5 
6 #include "InstructionTransformation.h"
7 
8 #include <cmath>
9 
10 namespace Marble
11 {
12 
14 {
15  RoutingInstructions result;
16 
17  int lastAngle = 0;
18  for( int i = 0; i < model.size(); ++i ) {
19  const RoutingWaypoint &item = model[i];
20  int newAngle = 180 + lastAngle;
21  if ( i < model.size() - 1 ) {
22  newAngle = qRound( 180.0 / M_PI * item.point().bearing( model[i+1].point() ) );
23  }
24  int angle = ( newAngle - lastAngle + 540 ) % 360;
25  Q_ASSERT( angle >= 0 && angle <= 360 );
26  if ( result.isEmpty() || !result.last().append( item, angle ) ) {
27  result.push_back( RoutingInstruction( item ) );
28  }
29  lastAngle = newAngle;
30  }
31 
32  for ( int i = 0; i < result.size(); ++i ) {
33  result[i].setSuccessor( i < result.size() - 1 ? &result[i+1] : nullptr );
34  result[i].setPredecessor( i ? &result[i-1] : nullptr );
35  }
36 
37  return result;
38 }
39 
40 } // namespace Marble
qreal bearing(const RoutingPoint &other) const
Calculates the bearing of the line defined by this point and the given other point.
bool isEmpty() const const
T & last()
void push_back(const T &value)
RoutingPoint point() const
Associated geo point.
Stores one line of gosmore/routino output.
Binds a QML item to a specific geodetic location in screen coordinates.
static RoutingInstructions process(const RoutingWaypoints &waypoints)
Transforms waypoints and metadata into driving directions.
int size() const const
Stores data related to one instruction: Road name, angle to predecessor, associated waypoints etc.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Sep 23 2023 04:12:06 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.