From 96aff572756ea7bce39f4858db79d0712371253a Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 16 Dec 2013 17:36:36 +0100 Subject: [PATCH] fixes #731, perpendicular projection to nearest location --- DataStructures/EdgeBasedNode.h | 10 ++++++---- features/nearest/pick.feature | 18 +++++++++--------- features/testbot/projection.feature | 22 +++++++++++----------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/DataStructures/EdgeBasedNode.h b/DataStructures/EdgeBasedNode.h index 117758c13..38403ca16 100644 --- a/DataStructures/EdgeBasedNode.h +++ b/DataStructures/EdgeBasedNode.h @@ -4,6 +4,8 @@ #include #include "Coordinate.h" +#include "../Util/MercatorUtil.h" +#include "../typedefs.h" struct EdgeBasedNode { @@ -29,11 +31,11 @@ struct EdgeBasedNode { return std::numeric_limits::max(); } - const double x = inputPoint.lat/COORDINATE_PRECISION; + const double x = lat2y(inputPoint.lat/COORDINATE_PRECISION); const double y = inputPoint.lon/COORDINATE_PRECISION; - const double a = lat1/COORDINATE_PRECISION; + const double a = lat2y(lat1/COORDINATE_PRECISION); const double b = lon1/COORDINATE_PRECISION; - const double c = lat2/COORDINATE_PRECISION; + const double c = lat2y(lat2/COORDINATE_PRECISION); const double d = lon2/COORDINATE_PRECISION; double p,q,mX,nY; if(std::fabs(a-c) > std::numeric_limits::epsilon() ){ @@ -66,7 +68,7 @@ struct EdgeBasedNode { // return std::sqrt(((d - y)*(d - y) + (c - x)*(c - x))); } // point lies in between - nearest_location.lat = p*COORDINATE_PRECISION; + nearest_location.lat = y2lat(p)*COORDINATE_PRECISION; nearest_location.lon = q*COORDINATE_PRECISION; // return std::sqrt((p-x)*(p-x) + (q-y)*(q-y)); return (p-x)*(p-x) + (q-y)*(q-y); diff --git a/features/nearest/pick.feature b/features/nearest/pick.feature index c0761f62d..08e665243 100644 --- a/features/nearest/pick.feature +++ b/features/nearest/pick.feature @@ -59,12 +59,12 @@ Feature: Locating Nearest node on a Way - pick closest way Given the node locations | node | lat | lon | | a | -85 | -180 | - | b | 0 | 0 | - | c | 85 | 180 | - | x | -70 | -100 | - | y | 70 | 100 | - | v | 1 | 1 | - | w | -1 | -1 | + | b | -85 | -160 | + | c | -85 | -140 | + | x | 75 | -180 | + | y | 75 | -180 | + | v | 1 | 1 | + | w | -1 | -1 | And the ways | nodes | @@ -73,6 +73,6 @@ Feature: Locating Nearest node on a Way - pick closest way When I request nearest I should get | in | out | | x | a | - | y | c | - | v | b | - | w | b | + | y | a | + | v | c | + | w | c | diff --git a/features/testbot/projection.feature b/features/testbot/projection.feature index 6d94480dc..20898f17f 100644 --- a/features/testbot/projection.feature +++ b/features/testbot/projection.feature @@ -1,6 +1,6 @@ -@routing @projection @todo +@routing @projection Feature: Projection to nearest point on road -Waypoints should be projected perpendicular onto the closest road, also at high latitudes. +Waypoints are projected perpendiculary onto the closest road Background: The coordinas below was calculated using http://www.movable-type.co.uk/scripts/latlong.html @@ -24,15 +24,15 @@ Waypoints should be projected perpendicular onto the closest road, also at high Scenario: Projection onto way at high latitudes, 1km distance When I route I should get | from | to | route | compass | bearing | distance | - | b | a | abc | SW | 225 | 1000m +-3 | - | b | c | abc | NE | 45 | 1000m +-3 | - | a | d | abc | NE | 45 | 1000m +-3 | - | d | a | abc | SW | 225 | 1000m +-3 | - | c | d | abc | SW | 225 | 1000m +-3 | - | d | c | abc | NE | 45 | 1000m +-3 | + | b | a | abc | SW | 225 | 1000m +-7 | + | b | c | abc | NE | 45 | 1000m +-7 | + | a | d | abc | NE | 45 | 1000m +-7 | + | d | a | abc | SW | 225 | 1000m +-7 | + | c | d | abc | SW | 225 | 1000m +-7 | + | d | c | abc | NE | 45 +-1 | 1000m +-7 | - Scenario: Projection onto way at high latitudes, no distance + Scenario: Projection onto way at high latitudes, no distance When I route I should get | from | to | route | distance | - | d | b | abc | 0m | - | b | d | abc | 0m | + | d | b | abc | 0m +-4 | + | b | d | abc | 0m +-4 |