rebase branch onto latest develop, report changes. hurt a little

This commit is contained in:
Dennis Luxen 2014-12-17 19:02:48 +01:00
parent 06f82d5e8a
commit 6da33cafe5
12 changed files with 496 additions and 504 deletions

View File

@ -71,7 +71,7 @@ file(GLOB ServerGlob Server/*.cpp)
file(GLOB DescriptorGlob descriptors/*.cpp) file(GLOB DescriptorGlob descriptors/*.cpp)
file(GLOB DatastructureGlob data_structures/search_engine_data.cpp data_structures/route_parameters.cpp Util/bearing.cpp) file(GLOB DatastructureGlob data_structures/search_engine_data.cpp data_structures/route_parameters.cpp Util/bearing.cpp)
list(REMOVE_ITEM DatastructureGlob data_structures/Coordinate.cpp) list(REMOVE_ITEM DatastructureGlob data_structures/Coordinate.cpp)
file(GLOB CoordinateGlob data_structures/Coordinate.cpp) file(GLOB CoordinateGlob data_structures/coordinate.cpp)
file(GLOB AlgorithmGlob algorithms/*.cpp) file(GLOB AlgorithmGlob algorithms/*.cpp)
file(GLOB HttpGlob Server/Http/*.cpp) file(GLOB HttpGlob Server/Http/*.cpp)
file(GLOB LibOSRMGlob Library/*.cpp) file(GLOB LibOSRMGlob Library/*.cpp)
@ -299,7 +299,7 @@ if(WITH_TOOLS OR BUILD_TOOLS)
else() else()
message(FATAL_ERROR "libgdal and/or development headers not found") message(FATAL_ERROR "libgdal and/or development headers not found")
endif() endif()
add_executable(osrm-cli tools/simpleclient.cpp $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:LOGGER>) add_executable(osrm-cli tools/simpleclient.cpp $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:COORDINATE>)
target_link_libraries(osrm-cli ${Boost_LIBRARIES} ${OPTIONAL_SOCKET_LIBS} OSRM) target_link_libraries(osrm-cli ${Boost_LIBRARIES} ${OPTIONAL_SOCKET_LIBS} OSRM)
target_link_libraries(osrm-cli ${TBB_LIBRARIES}) target_link_libraries(osrm-cli ${TBB_LIBRARIES})
add_executable(osrm-io-benchmark tools/io-benchmark.cpp $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:LOGGER>) add_executable(osrm-io-benchmark tools/io-benchmark.cpp $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:LOGGER>)

View File

@ -30,10 +30,6 @@ namespace boost { namespace interprocess { class named_mutex; } }
#include "OSRM_impl.h" #include "OSRM_impl.h"
#include "OSRM.h" #include "OSRM.h"
#include <osrm/Reply.h>
#include <osrm/RouteParameters.h>
#include <osrm/ServerPaths.h>
#include "../plugins/distance_table.hpp" #include "../plugins/distance_table.hpp"
#include "../plugins/hello_world.hpp" #include "../plugins/hello_world.hpp"
#include "../plugins/locate.hpp" #include "../plugins/locate.hpp"

View File

@ -1,484 +1,484 @@
/* /*
Copyright (c) 2013, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met: are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer. of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution. other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "../Util/MercatorUtil.h" #include "../Util/MercatorUtil.h"
#ifndef NDEBUG #ifndef NDEBUG
#include "../Util/simple_logger.hpp" #include "../Util/simple_logger.hpp"
#endif #endif
#include "../Util/string_util.hpp" #include "../Util/string_util.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <osrm/coordinate.hpp> #include <osrm/coordinate.hpp>
#ifndef NDEBUG #ifndef NDEBUG
#include <bitset> #include <bitset>
#endif #endif
#include <iostream> #include <iostream>
#include <limits> #include <limits>
FixedPointCoordinate::FixedPointCoordinate() FixedPointCoordinate::FixedPointCoordinate()
: lat(std::numeric_limits<int>::min()), lon(std::numeric_limits<int>::min()) : lat(std::numeric_limits<int>::min()), lon(std::numeric_limits<int>::min())
{ {
} }
FixedPointCoordinate::FixedPointCoordinate(int lat, int lon) : lat(lat), lon(lon) FixedPointCoordinate::FixedPointCoordinate(int lat, int lon) : lat(lat), lon(lon)
{ {
#ifndef NDEBUG #ifndef NDEBUG
if (0 != (std::abs(lat) >> 30)) if (0 != (std::abs(lat) >> 30))
{ {
std::bitset<32> y_coordinate_vector(lat); std::bitset<32> y_coordinate_vector(lat);
SimpleLogger().Write(logDEBUG) << "broken lat: " << lat SimpleLogger().Write(logDEBUG) << "broken lat: " << lat
<< ", bits: " << y_coordinate_vector; << ", bits: " << y_coordinate_vector;
} }
if (0 != (std::abs(lon) >> 30)) if (0 != (std::abs(lon) >> 30))
{ {
std::bitset<32> x_coordinate_vector(lon); std::bitset<32> x_coordinate_vector(lon);
SimpleLogger().Write(logDEBUG) << "broken lon: " << lon SimpleLogger().Write(logDEBUG) << "broken lon: " << lon
<< ", bits: " << x_coordinate_vector; << ", bits: " << x_coordinate_vector;
} }
#endif #endif
} }
void FixedPointCoordinate::Reset() void FixedPointCoordinate::Reset()
{ {
lat = std::numeric_limits<int>::min(); lat = std::numeric_limits<int>::min();
lon = std::numeric_limits<int>::min(); lon = std::numeric_limits<int>::min();
} }
bool FixedPointCoordinate::isSet() const bool FixedPointCoordinate::isSet() const
{ {
return (std::numeric_limits<int>::min() != lat) && (std::numeric_limits<int>::min() != lon); return (std::numeric_limits<int>::min() != lat) && (std::numeric_limits<int>::min() != lon);
} }
bool FixedPointCoordinate::is_valid() const bool FixedPointCoordinate::is_valid() const
{ {
if (lat > 90 * COORDINATE_PRECISION || lat < -90 * COORDINATE_PRECISION || if (lat > 90 * COORDINATE_PRECISION || lat < -90 * COORDINATE_PRECISION ||
lon > 180 * COORDINATE_PRECISION || lon < -180 * COORDINATE_PRECISION) lon > 180 * COORDINATE_PRECISION || lon < -180 * COORDINATE_PRECISION)
{ {
return false; return false;
} }
return true; return true;
} }
bool FixedPointCoordinate::operator==(const FixedPointCoordinate &other) const bool FixedPointCoordinate::operator==(const FixedPointCoordinate &other) const
{ {
return lat == other.lat && lon == other.lon; return lat == other.lat && lon == other.lon;
} }
double FixedPointCoordinate::ApproximateDistance(const int lat1, double FixedPointCoordinate::ApproximateDistance(const int lat1,
const int lon1, const int lon1,
const int lat2, const int lat2,
const int lon2) const int lon2)
{ {
BOOST_ASSERT(lat1 != std::numeric_limits<int>::min()); BOOST_ASSERT(lat1 != std::numeric_limits<int>::min());
BOOST_ASSERT(lon1 != std::numeric_limits<int>::min()); BOOST_ASSERT(lon1 != std::numeric_limits<int>::min());
BOOST_ASSERT(lat2 != std::numeric_limits<int>::min()); BOOST_ASSERT(lat2 != std::numeric_limits<int>::min());
BOOST_ASSERT(lon2 != std::numeric_limits<int>::min()); BOOST_ASSERT(lon2 != std::numeric_limits<int>::min());
double RAD = 0.017453292519943295769236907684886; double RAD = 0.017453292519943295769236907684886;
double lt1 = lat1 / COORDINATE_PRECISION; double lt1 = lat1 / COORDINATE_PRECISION;
double ln1 = lon1 / COORDINATE_PRECISION; double ln1 = lon1 / COORDINATE_PRECISION;
double lt2 = lat2 / COORDINATE_PRECISION; double lt2 = lat2 / COORDINATE_PRECISION;
double ln2 = lon2 / COORDINATE_PRECISION; double ln2 = lon2 / COORDINATE_PRECISION;
double dlat1 = lt1 * (RAD); double dlat1 = lt1 * (RAD);
double dlong1 = ln1 * (RAD); double dlong1 = ln1 * (RAD);
double dlat2 = lt2 * (RAD); double dlat2 = lt2 * (RAD);
double dlong2 = ln2 * (RAD); double dlong2 = ln2 * (RAD);
double dLong = dlong1 - dlong2; double dLong = dlong1 - dlong2;
double dLat = dlat1 - dlat2; double dLat = dlat1 - dlat2;
double aHarv = pow(sin(dLat / 2.0), 2.0) + cos(dlat1) * cos(dlat2) * pow(sin(dLong / 2.), 2); double aHarv = pow(sin(dLat / 2.0), 2.0) + cos(dlat1) * cos(dlat2) * pow(sin(dLong / 2.), 2);
double cHarv = 2. * atan2(sqrt(aHarv), sqrt(1.0 - aHarv)); double cHarv = 2. * atan2(sqrt(aHarv), sqrt(1.0 - aHarv));
// earth radius varies between 6,356.750-6,378.135 km (3,949.901-3,963.189mi) // earth radius varies between 6,356.750-6,378.135 km (3,949.901-3,963.189mi)
// The IUGG value for the equatorial radius is 6378.137 km (3963.19 miles) // The IUGG value for the equatorial radius is 6378.137 km (3963.19 miles)
const double earth = 6372797.560856; const double earth = 6372797.560856;
return earth * cHarv; return earth * cHarv;
} }
double FixedPointCoordinate::ApproximateDistance(const FixedPointCoordinate &coordinate_1, double FixedPointCoordinate::ApproximateDistance(const FixedPointCoordinate &coordinate_1,
const FixedPointCoordinate &coordinate_2) const FixedPointCoordinate &coordinate_2)
{ {
return ApproximateDistance( return ApproximateDistance(
coordinate_1.lat, coordinate_1.lon, coordinate_2.lat, coordinate_2.lon); coordinate_1.lat, coordinate_1.lon, coordinate_2.lat, coordinate_2.lon);
} }
float FixedPointCoordinate::ApproximateEuclideanDistance(const FixedPointCoordinate &coordinate_1, float FixedPointCoordinate::ApproximateEuclideanDistance(const FixedPointCoordinate &coordinate_1,
const FixedPointCoordinate &coordinate_2) const FixedPointCoordinate &coordinate_2)
{ {
return ApproximateEuclideanDistance( return ApproximateEuclideanDistance(
coordinate_1.lat, coordinate_1.lon, coordinate_2.lat, coordinate_2.lon); coordinate_1.lat, coordinate_1.lon, coordinate_2.lat, coordinate_2.lon);
} }
float FixedPointCoordinate::ApproximateEuclideanDistance(const int lat1, float FixedPointCoordinate::ApproximateEuclideanDistance(const int lat1,
const int lon1, const int lon1,
const int lat2, const int lat2,
const int lon2) const int lon2)
{ {
BOOST_ASSERT(lat1 != std::numeric_limits<int>::min()); BOOST_ASSERT(lat1 != std::numeric_limits<int>::min());
BOOST_ASSERT(lon1 != std::numeric_limits<int>::min()); BOOST_ASSERT(lon1 != std::numeric_limits<int>::min());
BOOST_ASSERT(lat2 != std::numeric_limits<int>::min()); BOOST_ASSERT(lat2 != std::numeric_limits<int>::min());
BOOST_ASSERT(lon2 != std::numeric_limits<int>::min()); BOOST_ASSERT(lon2 != std::numeric_limits<int>::min());
const float RAD = 0.017453292519943295769236907684886f; const float RAD = 0.017453292519943295769236907684886f;
const float float_lat1 = (lat1 / COORDINATE_PRECISION) * RAD; const float float_lat1 = (lat1 / COORDINATE_PRECISION) * RAD;
const float float_lon1 = (lon1 / COORDINATE_PRECISION) * RAD; const float float_lon1 = (lon1 / COORDINATE_PRECISION) * RAD;
const float float_lat2 = (lat2 / COORDINATE_PRECISION) * RAD; const float float_lat2 = (lat2 / COORDINATE_PRECISION) * RAD;
const float float_lon2 = (lon2 / COORDINATE_PRECISION) * RAD; const float float_lon2 = (lon2 / COORDINATE_PRECISION) * RAD;
const float x_value = (float_lon2 - float_lon1) * cos((float_lat1 + float_lat2) / 2.f); const float x_value = (float_lon2 - float_lon1) * cos((float_lat1 + float_lat2) / 2.f);
const float y_value = float_lat2 - float_lat1; const float y_value = float_lat2 - float_lat1;
const float earth_radius = 6372797.560856f; const float earth_radius = 6372797.560856f;
return sqrt(x_value * x_value + y_value * y_value) * earth_radius; return sqrt(x_value * x_value + y_value * y_value) * earth_radius;
} }
float float
FixedPointCoordinate::ComputePerpendicularDistance(const FixedPointCoordinate &source_coordinate, FixedPointCoordinate::ComputePerpendicularDistance(const FixedPointCoordinate &source_coordinate,
const FixedPointCoordinate &target_coordinate, const FixedPointCoordinate &target_coordinate,
const FixedPointCoordinate &point) const FixedPointCoordinate &point)
{ {
// initialize values // initialize values
const float x_value = static_cast<float>(lat2y(point.lat / COORDINATE_PRECISION)); const float x_value = static_cast<float>(lat2y(point.lat / COORDINATE_PRECISION));
const float y_value = point.lon / COORDINATE_PRECISION; const float y_value = point.lon / COORDINATE_PRECISION;
float a = static_cast<float>(lat2y(source_coordinate.lat / COORDINATE_PRECISION)); float a = static_cast<float>(lat2y(source_coordinate.lat / COORDINATE_PRECISION));
float b = source_coordinate.lon / COORDINATE_PRECISION; float b = source_coordinate.lon / COORDINATE_PRECISION;
float c = static_cast<float>(lat2y(target_coordinate.lat / COORDINATE_PRECISION)); float c = static_cast<float>(lat2y(target_coordinate.lat / COORDINATE_PRECISION));
float d = target_coordinate.lon / COORDINATE_PRECISION; float d = target_coordinate.lon / COORDINATE_PRECISION;
float p, q; float p, q;
if (std::abs(a - c) > std::numeric_limits<float>::epsilon()) if (std::abs(a - c) > std::numeric_limits<float>::epsilon())
{ {
const float slope = (d - b) / (c - a); // slope const float slope = (d - b) / (c - a); // slope
// Projection of (x,y) on line joining (a,b) and (c,d) // Projection of (x,y) on line joining (a,b) and (c,d)
p = ((x_value + (slope * y_value)) + (slope * slope * a - slope * b)) / p = ((x_value + (slope * y_value)) + (slope * slope * a - slope * b)) /
(1.f + slope * slope); (1.f + slope * slope);
q = b + slope * (p - a); q = b + slope * (p - a);
} }
else else
{ {
p = c; p = c;
q = y_value; q = y_value;
} }
float ratio; float ratio;
bool inverse_ratio = false; bool inverse_ratio = false;
// straight line segment on equator // straight line segment on equator
if (std::abs(c) < std::numeric_limits<float>::epsilon() && if (std::abs(c) < std::numeric_limits<float>::epsilon() &&
std::abs(a) < std::numeric_limits<float>::epsilon()) std::abs(a) < std::numeric_limits<float>::epsilon())
{ {
ratio = (q - b) / (d - b); ratio = (q - b) / (d - b);
} }
else else
{ {
if (std::abs(c) < std::numeric_limits<float>::epsilon()) if (std::abs(c) < std::numeric_limits<float>::epsilon())
{ {
// swap start/end // swap start/end
std::swap(a, c); std::swap(a, c);
std::swap(b, d); std::swap(b, d);
inverse_ratio = true; inverse_ratio = true;
} }
float nY = (d * p - c * q) / (a * d - b * c); float nY = (d * p - c * q) / (a * d - b * c);
// discretize the result to coordinate precision. it's a hack! // discretize the result to coordinate precision. it's a hack!
if (std::abs(nY) < (1.f / COORDINATE_PRECISION)) if (std::abs(nY) < (1.f / COORDINATE_PRECISION))
{ {
nY = 0.f; nY = 0.f;
} }
// compute ratio // compute ratio
ratio = (p - nY * a) / c; ratio = (p - nY * a) / c;
} }
if (std::isnan(ratio)) if (std::isnan(ratio))
{ {
ratio = (target_coordinate == point ? 1.f : 0.f); ratio = (target_coordinate == point ? 1.f : 0.f);
} }
else if (std::abs(ratio) <= std::numeric_limits<float>::epsilon()) else if (std::abs(ratio) <= std::numeric_limits<float>::epsilon())
{ {
ratio = 0.f; ratio = 0.f;
} }
else if (std::abs(ratio - 1.f) <= std::numeric_limits<float>::epsilon()) else if (std::abs(ratio - 1.f) <= std::numeric_limits<float>::epsilon())
{ {
ratio = 1.f; ratio = 1.f;
} }
// we need to do this, if we switched start/end coordinates // we need to do this, if we switched start/end coordinates
if (inverse_ratio) if (inverse_ratio)
{ {
ratio = 1.0f - ratio; ratio = 1.0f - ratio;
} }
// compute the nearest location // compute the nearest location
FixedPointCoordinate nearest_location; FixedPointCoordinate nearest_location;
BOOST_ASSERT(!std::isnan(ratio)); BOOST_ASSERT(!std::isnan(ratio));
if (ratio <= 0.f) if (ratio <= 0.f)
{ // point is "left" of edge { // point is "left" of edge
nearest_location = source_coordinate; nearest_location = source_coordinate;
} }
else if (ratio >= 1.f) else if (ratio >= 1.f)
{ // point is "right" of edge { // point is "right" of edge
nearest_location = target_coordinate; nearest_location = target_coordinate;
} }
else else
{ // point lies in between { // point lies in between
nearest_location.lat = static_cast<int>(y2lat(p) * COORDINATE_PRECISION); nearest_location.lat = static_cast<int>(y2lat(p) * COORDINATE_PRECISION);
nearest_location.lon = static_cast<int>(q * COORDINATE_PRECISION); nearest_location.lon = static_cast<int>(q * COORDINATE_PRECISION);
} }
BOOST_ASSERT(nearest_location.is_valid()); BOOST_ASSERT(nearest_location.is_valid());
return FixedPointCoordinate::ApproximateEuclideanDistance(point, nearest_location); return FixedPointCoordinate::ApproximateEuclideanDistance(point, nearest_location);
} }
float FixedPointCoordinate::ComputePerpendicularDistance(const FixedPointCoordinate &segment_source, float FixedPointCoordinate::ComputePerpendicularDistance(const FixedPointCoordinate &segment_source,
const FixedPointCoordinate &segment_target, const FixedPointCoordinate &segment_target,
const FixedPointCoordinate &query_location, const FixedPointCoordinate &query_location,
FixedPointCoordinate &nearest_location, FixedPointCoordinate &nearest_location,
float &ratio) float &ratio)
{ {
BOOST_ASSERT(query_location.is_valid()); BOOST_ASSERT(query_location.is_valid());
// initialize values // initialize values
const double x = lat2y(query_location.lat / COORDINATE_PRECISION); const double x = lat2y(query_location.lat / COORDINATE_PRECISION);
const double y = query_location.lon / COORDINATE_PRECISION; const double y = query_location.lon / COORDINATE_PRECISION;
const double a = lat2y(segment_source.lat / COORDINATE_PRECISION); const double a = lat2y(segment_source.lat / COORDINATE_PRECISION);
const double b = segment_source.lon / COORDINATE_PRECISION; const double b = segment_source.lon / COORDINATE_PRECISION;
const double c = lat2y(segment_target.lat / COORDINATE_PRECISION); const double c = lat2y(segment_target.lat / COORDINATE_PRECISION);
const double d = segment_target.lon / COORDINATE_PRECISION; const double d = segment_target.lon / COORDINATE_PRECISION;
double p, q /*,mX*/, nY; double p, q /*,mX*/, nY;
if (std::abs(a - c) > std::numeric_limits<double>::epsilon()) if (std::abs(a - c) > std::numeric_limits<double>::epsilon())
{ {
const double m = (d - b) / (c - a); // slope const double m = (d - b) / (c - a); // slope
// Projection of (x,y) on line joining (a,b) and (c,d) // Projection of (x,y) on line joining (a,b) and (c,d)
p = ((x + (m * y)) + (m * m * a - m * b)) / (1.f + m * m); p = ((x + (m * y)) + (m * m * a - m * b)) / (1.f + m * m);
q = b + m * (p - a); q = b + m * (p - a);
} }
else else
{ {
p = c; p = c;
q = y; q = y;
} }
nY = (d * p - c * q) / (a * d - b * c); nY = (d * p - c * q) / (a * d - b * c);
// discretize the result to coordinate precision. it's a hack! // discretize the result to coordinate precision. it's a hack!
if (std::abs(nY) < (1.f / COORDINATE_PRECISION)) if (std::abs(nY) < (1.f / COORDINATE_PRECISION))
{ {
nY = 0.f; nY = 0.f;
} }
// compute ratio // compute ratio
ratio = (p - nY * a) / c; // These values are actually n/m+n and m/m+n , we need ratio = (p - nY * a) / c; // These values are actually n/m+n and m/m+n , we need
// not calculate the explicit values of m an n as we // not calculate the explicit values of m an n as we
// are just interested in the ratio // are just interested in the ratio
if (std::isnan(ratio)) if (std::isnan(ratio))
{ {
ratio = (segment_target == query_location ? 1.f : 0.f); ratio = (segment_target == query_location ? 1.f : 0.f);
} }
else if (std::abs(ratio) <= std::numeric_limits<double>::epsilon()) else if (std::abs(ratio) <= std::numeric_limits<double>::epsilon())
{ {
ratio = 0.f; ratio = 0.f;
} }
else if (std::abs(ratio - 1.f) <= std::numeric_limits<double>::epsilon()) else if (std::abs(ratio - 1.f) <= std::numeric_limits<double>::epsilon())
{ {
ratio = 1.f; ratio = 1.f;
} }
// compute nearest location // compute nearest location
BOOST_ASSERT(!std::isnan(ratio)); BOOST_ASSERT(!std::isnan(ratio));
if (ratio <= 0.f) if (ratio <= 0.f)
{ {
nearest_location = segment_source; nearest_location = segment_source;
} }
else if (ratio >= 1.f) else if (ratio >= 1.f)
{ {
nearest_location = segment_target; nearest_location = segment_target;
} }
else else
{ {
// point lies in between // point lies in between
nearest_location.lat = static_cast<int>(y2lat(p) * COORDINATE_PRECISION); nearest_location.lat = static_cast<int>(y2lat(p) * COORDINATE_PRECISION);
nearest_location.lon = static_cast<int>(q * COORDINATE_PRECISION); nearest_location.lon = static_cast<int>(q * COORDINATE_PRECISION);
} }
BOOST_ASSERT(nearest_location.is_valid()); BOOST_ASSERT(nearest_location.is_valid());
const float approximate_distance = const float approximate_distance =
FixedPointCoordinate::ApproximateEuclideanDistance(query_location, nearest_location); FixedPointCoordinate::ApproximateEuclideanDistance(query_location, nearest_location);
BOOST_ASSERT(0. <= approximate_distance); BOOST_ASSERT(0. <= approximate_distance);
return approximate_distance; return approximate_distance;
} }
void FixedPointCoordinate::convertInternalLatLonToString(const int value, std::string &output) void FixedPointCoordinate::convertInternalLatLonToString(const int value, std::string &output)
{ {
char buffer[12]; char buffer[12];
buffer[11] = 0; // zero termination buffer[11] = 0; // zero termination
output = printInt<11, 6>(buffer, value); output = printInt<11, 6>(buffer, value);
} }
void FixedPointCoordinate::convertInternalCoordinateToString(const FixedPointCoordinate &coord, void FixedPointCoordinate::convertInternalCoordinateToString(const FixedPointCoordinate &coord,
std::string &output) std::string &output)
{ {
std::string tmp; std::string tmp;
tmp.reserve(23); tmp.reserve(23);
convertInternalLatLonToString(coord.lon, tmp); convertInternalLatLonToString(coord.lon, tmp);
output = tmp; output = tmp;
output += ","; output += ",";
convertInternalLatLonToString(coord.lat, tmp); convertInternalLatLonToString(coord.lat, tmp);
output += tmp; output += tmp;
} }
void void
FixedPointCoordinate::convertInternalReversedCoordinateToString(const FixedPointCoordinate &coord, FixedPointCoordinate::convertInternalReversedCoordinateToString(const FixedPointCoordinate &coord,
std::string &output) std::string &output)
{ {
std::string tmp; std::string tmp;
tmp.reserve(23); tmp.reserve(23);
convertInternalLatLonToString(coord.lat, tmp); convertInternalLatLonToString(coord.lat, tmp);
output = tmp; output = tmp;
output += ","; output += ",";
convertInternalLatLonToString(coord.lon, tmp); convertInternalLatLonToString(coord.lon, tmp);
output += tmp; output += tmp;
} }
void FixedPointCoordinate::Output(std::ostream &out) const void FixedPointCoordinate::Output(std::ostream &out) const
{ {
out << "(" << lat / COORDINATE_PRECISION << "," << lon / COORDINATE_PRECISION << ")"; out << "(" << lat / COORDINATE_PRECISION << "," << lon / COORDINATE_PRECISION << ")";
} }
float FixedPointCoordinate::GetBearing(const FixedPointCoordinate &first_coordinate, float FixedPointCoordinate::GetBearing(const FixedPointCoordinate &first_coordinate,
const FixedPointCoordinate &second_coordinate) const FixedPointCoordinate &second_coordinate)
{ {
const float lon_diff = const float lon_diff =
second_coordinate.lon / COORDINATE_PRECISION - first_coordinate.lon / COORDINATE_PRECISION; second_coordinate.lon / COORDINATE_PRECISION - first_coordinate.lon / COORDINATE_PRECISION;
const float lon_delta = DegreeToRadian(lon_diff); const float lon_delta = DegreeToRadian(lon_diff);
const float lat1 = DegreeToRadian(first_coordinate.lat / COORDINATE_PRECISION); const float lat1 = DegreeToRadian(first_coordinate.lat / COORDINATE_PRECISION);
const float lat2 = DegreeToRadian(second_coordinate.lat / COORDINATE_PRECISION); const float lat2 = DegreeToRadian(second_coordinate.lat / COORDINATE_PRECISION);
const float y = sin(lon_delta) * cos(lat2); const float y = sin(lon_delta) * cos(lat2);
const float x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon_delta); const float x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon_delta);
float result = RadianToDegree(std::atan2(y, x)); float result = RadianToDegree(std::atan2(y, x));
while (result < 0.f) while (result < 0.f)
{ {
result += 360.f; result += 360.f;
} }
while (result >= 360.f) while (result >= 360.f)
{ {
result -= 360.f; result -= 360.f;
} }
return result; return result;
} }
float FixedPointCoordinate::GetBearing(const FixedPointCoordinate &other) const float FixedPointCoordinate::GetBearing(const FixedPointCoordinate &other) const
{ {
const float lon_delta = const float lon_delta =
DegreeToRadian(lon / COORDINATE_PRECISION - other.lon / COORDINATE_PRECISION); DegreeToRadian(lon / COORDINATE_PRECISION - other.lon / COORDINATE_PRECISION);
const float lat1 = DegreeToRadian(other.lat / COORDINATE_PRECISION); const float lat1 = DegreeToRadian(other.lat / COORDINATE_PRECISION);
const float lat2 = DegreeToRadian(lat / COORDINATE_PRECISION); const float lat2 = DegreeToRadian(lat / COORDINATE_PRECISION);
const float y_value = std::sin(lon_delta) * std::cos(lat2); const float y_value = std::sin(lon_delta) * std::cos(lat2);
const float x_value = const float x_value =
std::cos(lat1) * std::sin(lat2) - std::sin(lat1) * std::cos(lat2) * std::cos(lon_delta); std::cos(lat1) * std::sin(lat2) - std::sin(lat1) * std::cos(lat2) * std::cos(lon_delta);
float result = RadianToDegree(std::atan2(y_value, x_value)); float result = RadianToDegree(std::atan2(y_value, x_value));
while (result < 0.f) while (result < 0.f)
{ {
result += 360.f; result += 360.f;
} }
while (result >= 360.f) while (result >= 360.f)
{ {
result -= 360.f; result -= 360.f;
} }
return result; return result;
} }
float FixedPointCoordinate::DegreeToRadian(const float degree) float FixedPointCoordinate::DegreeToRadian(const float degree)
{ {
return degree * (static_cast<float>(M_PI) / 180.f); return degree * (static_cast<float>(M_PI) / 180.f);
} }
float FixedPointCoordinate::RadianToDegree(const float radian) float FixedPointCoordinate::RadianToDegree(const float radian)
{ {
return radian * (180.f * static_cast<float>(M_1_PI)); return radian * (180.f * static_cast<float>(M_1_PI));
} }
// This distance computation does integer arithmetic only and is a lot faster than // This distance computation does integer arithmetic only and is a lot faster than
// the other distance function which are numerically correct('ish). // the other distance function which are numerically correct('ish).
// It preserves some order among the elements that make it useful for certain purposes // It preserves some order among the elements that make it useful for certain purposes
int FixedPointCoordinate::OrderedPerpendicularDistanceApproximation( int FixedPointCoordinate::OrderedPerpendicularDistanceApproximation(
const FixedPointCoordinate &input_point, const FixedPointCoordinate &input_point,
const FixedPointCoordinate &segment_source, const FixedPointCoordinate &segment_source,
const FixedPointCoordinate &segment_target) const FixedPointCoordinate &segment_target)
{ {
// initialize values // initialize values
const float x = static_cast<float>(lat2y(input_point.lat / COORDINATE_PRECISION)); const float x = static_cast<float>(lat2y(input_point.lat / COORDINATE_PRECISION));
const float y = input_point.lon / COORDINATE_PRECISION; const float y = input_point.lon / COORDINATE_PRECISION;
const float a = static_cast<float>(lat2y(segment_source.lat / COORDINATE_PRECISION)); const float a = static_cast<float>(lat2y(segment_source.lat / COORDINATE_PRECISION));
const float b = segment_source.lon / COORDINATE_PRECISION; const float b = segment_source.lon / COORDINATE_PRECISION;
const float c = static_cast<float>(lat2y(segment_target.lat / COORDINATE_PRECISION)); const float c = static_cast<float>(lat2y(segment_target.lat / COORDINATE_PRECISION));
const float d = segment_target.lon / COORDINATE_PRECISION; const float d = segment_target.lon / COORDINATE_PRECISION;
float p, q; float p, q;
if (a == c) if (a == c)
{ {
p = c; p = c;
q = y; q = y;
} }
else else
{ {
const float m = (d - b) / (c - a); // slope const float m = (d - b) / (c - a); // slope
// Projection of (x,y) on line joining (a,b) and (c,d) // Projection of (x,y) on line joining (a,b) and (c,d)
p = ((x + (m * y)) + (m * m * a - m * b)) / (1.f + m * m); p = ((x + (m * y)) + (m * m * a - m * b)) / (1.f + m * m);
q = b + m * (p - a); q = b + m * (p - a);
} }
const float nY = (d * p - c * q) / (a * d - b * c); const float nY = (d * p - c * q) / (a * d - b * c);
float ratio = (p - nY * a) / c; // These values are actually n/m+n and m/m+n , we need float ratio = (p - nY * a) / c; // These values are actually n/m+n and m/m+n , we need
// not calculate the explicit values of m an n as we // not calculate the explicit values of m an n as we
// are just interested in the ratio // are just interested in the ratio
if (std::isnan(ratio)) if (std::isnan(ratio))
{ {
ratio = (segment_target == input_point) ? 1.f : 0.f; ratio = (segment_target == input_point) ? 1.f : 0.f;
} }
// compute target quasi-location // compute target quasi-location
int dx, dy; int dx, dy;
if (ratio < 0.f) if (ratio < 0.f)
{ {
dx = input_point.lon - segment_source.lon; dx = input_point.lon - segment_source.lon;
dy = input_point.lat - segment_source.lat; dy = input_point.lat - segment_source.lat;
} }
else if (ratio > 1.f) else if (ratio > 1.f)
{ {
dx = input_point.lon - segment_target.lon; dx = input_point.lon - segment_target.lon;
dy = input_point.lat - segment_target.lat; dy = input_point.lat - segment_target.lat;
} }
else else
{ {
// point lies in between // point lies in between
dx = input_point.lon - static_cast<int>(q * COORDINATE_PRECISION); dx = input_point.lon - static_cast<int>(q * COORDINATE_PRECISION);
dy = input_point.lat - static_cast<int>(y2lat(p) * COORDINATE_PRECISION); dy = input_point.lat - static_cast<int>(y2lat(p) * COORDINATE_PRECISION);
} }
// return an approximation in the plane // return an approximation in the plane
return static_cast<int>(sqrt(dx * dx + dy * dy)); return static_cast<int>(sqrt(dx * dx + dy * dy));
} }

View File

@ -28,9 +28,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef RAW_ROUTE_DATA_H #ifndef RAW_ROUTE_DATA_H
#define RAW_ROUTE_DATA_H #define RAW_ROUTE_DATA_H
#include "../DataStructures/phantom_node.hpp" #include "../data_structures/phantom_node.hpp"
#include "../DataStructures/TravelMode.h" #include "../data_structures/travel_mode.hpp"
#include "../DataStructures/TurnInstructions.h" #include "../data_structures/turn_instructions.hpp"
#include "../typedefs.h" #include "../typedefs.h"
#include <osrm/coordinate.hpp> #include <osrm/coordinate.hpp>

View File

@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef PHANTOM_NODES_H #ifndef PHANTOM_NODES_H
#define PHANTOM_NODES_H #define PHANTOM_NODES_H
#include "../DataStructures/TravelMode.h" #include "travel_mode.hpp"
#include "../typedefs.h" #include "../typedefs.h"
#include <osrm/coordinate.hpp> #include <osrm/coordinate.hpp>

View File

@ -29,7 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../typedefs.h" #include "../typedefs.h"
#include "../algorithms/polyline_formatter.hpp" #include "../algorithms/polyline_formatter.hpp"
#include "../data_structures/raw_route_data.hpp" #include "../data_structures/internal_route_result.hpp"
#include "../data_structures/turn_instructions.hpp" #include "../data_structures/turn_instructions.hpp"
DescriptionFactory::DescriptionFactory() : entire_length(0) { via_indices.push_back(0); } DescriptionFactory::DescriptionFactory() : entire_length(0) { via_indices.push_back(0); }

View File

@ -30,7 +30,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../algorithms/douglas_peucker.hpp" #include "../algorithms/douglas_peucker.hpp"
#include "../data_structures/phantom_node.hpp" #include "../data_structures/phantom_node.hpp"
#include "../data_structures/json_container.hpp"
#include "../data_structures/segment_information.hpp" #include "../data_structures/segment_information.hpp"
#include "../data_structures/turn_instructions.hpp" #include "../data_structures/turn_instructions.hpp"

View File

@ -28,8 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef DESCRIPTOR_BASE_HPP #ifndef DESCRIPTOR_BASE_HPP
#define DESCRIPTOR_BASE_HPP #define DESCRIPTOR_BASE_HPP
#include "../data_structures/internal_route_result.hpp"
#include "../data_structures/phantom_node.hpp" #include "../data_structures/phantom_node.hpp"
#include "../data_structures/raw_route_data.hpp"
#include "../typedefs.h" #include "../typedefs.h"
#include <osrm/json_container.hpp> #include <osrm/json_container.hpp>

View File

@ -32,7 +32,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "description_factory.hpp" #include "description_factory.hpp"
#include "../algorithms/object_encoder.hpp" #include "../algorithms/object_encoder.hpp"
#include "../algorithms/route_name_extraction.hpp" #include "../algorithms/route_name_extraction.hpp"
#include "../data_structures/json_container.hpp"
#include "../data_structures/segment_information.hpp" #include "../data_structures/segment_information.hpp"
#include "../data_structures/turn_instructions.hpp" #include "../data_structures/turn_instructions.hpp"
#include "../Util/bearing.hpp" #include "../Util/bearing.hpp"
@ -355,7 +354,7 @@ template <class DataFacadeT> class JSONDescriptor final : public BaseDescriptor<
json_instruction_row.values.push_back( json_instruction_row.values.push_back(
cast::integral_to_string(static_cast<unsigned>(segment.length)) + "m"); cast::integral_to_string(static_cast<unsigned>(segment.length)) + "m");
const double bearing_value = (segment.bearing / 10.); const double bearing_value = (segment.bearing / 10.);
json_instruction_row.values.push_back(Azimuth::Get(bearing_value)); json_instruction_row.values.push_back(Bearing::Get(bearing_value));
json_instruction_row.values.push_back( json_instruction_row.values.push_back(
static_cast<unsigned>(round(bearing_value))); static_cast<unsigned>(round(bearing_value)));
json_instruction_row.values.push_back(segment.travel_mode); json_instruction_row.values.push_back(segment.travel_mode);
@ -385,7 +384,7 @@ template <class DataFacadeT> class JSONDescriptor final : public BaseDescriptor<
json_last_instruction_row.values.push_back(necessary_segments_running_index - 1); json_last_instruction_row.values.push_back(necessary_segments_running_index - 1);
json_last_instruction_row.values.push_back(0); json_last_instruction_row.values.push_back(0);
json_last_instruction_row.values.push_back("0m"); json_last_instruction_row.values.push_back("0m");
json_last_instruction_row.values.push_back(Azimuth::Get(0.0)); json_last_instruction_row.values.push_back(Bearing::Get(0.0));
json_last_instruction_row.values.push_back(0.); json_last_instruction_row.values.push_back(0.);
json_instruction_array.values.push_back(json_last_instruction_row); json_instruction_array.values.push_back(json_last_instruction_row);
} }

View File

@ -30,7 +30,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../typedefs.h" #include "../typedefs.h"
#include "../data_structures/travel_mode.hpp" #include "../data_structures/travel_mode.hpp"
#include <osrm/Coordinate.h>
#include <boost/assert.hpp> #include <boost/assert.hpp>

View File

@ -30,7 +30,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "plugin_base.hpp" #include "plugin_base.hpp"
#include "../data_structures/json_container.hpp"
#include "../Util/cast.hpp" #include "../Util/cast.hpp"
#include "../Util/json_renderer.hpp" #include "../Util/json_renderer.hpp"

View File

@ -28,10 +28,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef ROUTING_BASE_HPP #ifndef ROUTING_BASE_HPP
#define ROUTING_BASE_HPP #define ROUTING_BASE_HPP
#include "../data_structures/raw_route_data.hpp" #include "../data_structures/internal_route_result.hpp"
#include "../data_structures/search_engine_data.hpp" #include "../data_structures/search_engine_data.hpp"
#include "../data_structures/turn_instructions.hpp" #include "../data_structures/turn_instructions.hpp"
// #include "../Util/simple_logger.hpp.h" // #include "../Util/simple_logger.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>