Marble

InstructionTransformation.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2010 Dennis Nienhüser <nienhueser@kde.org>
4//
5
6#include "InstructionTransformation.h"
7
8#include <cmath>
9
10namespace Marble
11{
12
14{
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
static RoutingInstructions process(const RoutingWaypoints &waypoints)
Transforms waypoints and metadata into driving directions.
Stores data related to one instruction: Road name, angle to predecessor, associated waypoints etc.
qreal bearing(const RoutingPoint &other) const
Calculates the bearing of the line defined by this point and the given other point.
Stores one line of gosmore/routino output.
RoutingPoint point() const
Associated geo point.
Binds a QML item to a specific geodetic location in screen coordinates.
bool isEmpty() const const
T & last()
void push_back(parameter_type value)
qsizetype size() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:54:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.