# Marble

InstructionTransformation.cpp
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.