Fix walking direction heading for real this time

This commit is contained in:
Markus Koch 2020-05-06 14:52:13 +02:00
parent fff25e0a24
commit aea4f3e799

View File

@ -237,6 +237,7 @@ int dijkstra_search_route_to_geojson(struct dijkstra_search *search,
struct dijkstra_node *node_last = NULL; struct dijkstra_node *node_last = NULL;
float heading = -1.0; float heading = -1.0;
float last_heading = 0; float last_heading = 0;
float heading_diff;
char *relative_direction_str = NULL; char *relative_direction_str = NULL;
char *format_str = NULL; char *format_str = NULL;
int offset = 0; int offset = 0;
@ -249,9 +250,14 @@ int dijkstra_search_route_to_geojson(struct dijkstra_search *search,
node = (struct dijkstra_node*) l->data; node = (struct dijkstra_node*) l->data;
if (node_last) { if (node_last) {
heading = atan2f((node->position.y - node_last->position.y), (node->position.x - node_last->position.x)) / (M_PI * 2) * 360; heading = atan2f((node->position.y - node_last->position.y), (node->position.x - node_last->position.x)) / (M_PI * 2) * 360;
if (last_heading - heading > 25) { if (heading < 0.0)
heading += 360;
heading_diff = last_heading - heading;
if (fabsf(heading_diff) > 180)
heading_diff = heading - last_heading;
if (heading_diff > 25) {
relative_direction_str = "right"; relative_direction_str = "right";
} else if (last_heading - heading < -25) { } else if (heading_diff < -25) {
relative_direction_str = "left"; relative_direction_str = "left";
} else { } else {
relative_direction_str = "straight"; relative_direction_str = "straight";