2011-11-17 12:56:45 -05:00
|
|
|
/*
|
2013-10-14 07:42:28 -04:00
|
|
|
|
|
|
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
Redistributions of source code must retain the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer.
|
|
|
|
Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
other materials provided with the distribution.
|
|
|
|
|
|
|
|
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
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
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
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
2011-11-17 12:56:45 -05:00
|
|
|
|
|
|
|
#include "DescriptionFactory.h"
|
|
|
|
|
2014-05-02 13:07:55 -04:00
|
|
|
DescriptionFactory::DescriptionFactory() : entireLength(0) {}
|
2011-11-17 12:56:45 -05:00
|
|
|
|
2014-05-02 13:07:55 -04:00
|
|
|
DescriptionFactory::~DescriptionFactory() {}
|
2011-11-17 12:56:45 -05:00
|
|
|
|
2014-03-28 12:13:00 -04:00
|
|
|
inline double DescriptionFactory::DegreeToRadian(const double degree) const
|
|
|
|
{
|
2014-05-02 13:07:55 -04:00
|
|
|
return degree * (M_PI / 180.);
|
2012-06-11 10:36:33 -04:00
|
|
|
}
|
|
|
|
|
2014-03-28 12:13:00 -04:00
|
|
|
inline double DescriptionFactory::RadianToDegree(const double radian) const
|
|
|
|
{
|
2014-05-02 13:07:55 -04:00
|
|
|
return radian * (180. / M_PI);
|
2012-06-11 10:36:33 -04:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:07:55 -04:00
|
|
|
double DescriptionFactory::GetBearing(const FixedPointCoordinate &A, const FixedPointCoordinate &B)
|
|
|
|
const
|
2014-03-28 12:13:00 -04:00
|
|
|
{
|
2014-05-02 13:07:55 -04:00
|
|
|
double delta_long = DegreeToRadian(B.lon / COORDINATE_PRECISION - A.lon / COORDINATE_PRECISION);
|
2012-06-11 10:36:33 -04:00
|
|
|
|
2014-05-02 13:07:55 -04:00
|
|
|
const double lat1 = DegreeToRadian(A.lat / COORDINATE_PRECISION);
|
|
|
|
const double lat2 = DegreeToRadian(B.lat / COORDINATE_PRECISION);
|
2012-06-11 10:36:33 -04:00
|
|
|
|
2013-12-12 18:35:23 -05:00
|
|
|
const double y = sin(delta_long) * cos(lat2);
|
|
|
|
const double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(delta_long);
|
2012-06-11 10:36:33 -04:00
|
|
|
double result = RadianToDegree(atan2(y, x));
|
2014-03-28 12:13:00 -04:00
|
|
|
while (result < 0.)
|
|
|
|
{
|
2012-06-11 10:36:33 -04:00
|
|
|
result += 360.;
|
2013-11-13 15:52:01 -05:00
|
|
|
}
|
2014-03-28 12:13:00 -04:00
|
|
|
|
|
|
|
while (result >= 360.)
|
|
|
|
{
|
2012-06-11 10:36:33 -04:00
|
|
|
result -= 360.;
|
2013-11-13 15:52:01 -05:00
|
|
|
}
|
2012-06-11 10:36:33 -04:00
|
|
|
return result;
|
2011-11-17 12:56:45 -05:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:58:37 -04:00
|
|
|
void DescriptionFactory::SetStartSegment(const PhantomNode &source)
|
2014-03-28 12:13:00 -04:00
|
|
|
{
|
|
|
|
start_phantom = source;
|
2014-05-08 12:04:05 -04:00
|
|
|
AppendSegment(source.location, PathData(0, source.name_id, TurnInstruction::HeadOn, source.forward_weight));
|
2011-11-17 12:56:45 -05:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:58:37 -04:00
|
|
|
void DescriptionFactory::SetEndSegment(const PhantomNode &target)
|
2014-03-28 12:13:00 -04:00
|
|
|
{
|
2013-12-12 18:35:23 -05:00
|
|
|
target_phantom = target;
|
2014-05-08 05:18:46 -04:00
|
|
|
path_description.emplace_back(
|
2014-05-08 12:04:05 -04:00
|
|
|
target.location, target.name_id, 0, target.reverse_weight, TurnInstruction::NoTurn, true);
|
2011-11-17 12:56:45 -05:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:07:55 -04:00
|
|
|
void DescriptionFactory::AppendSegment(const FixedPointCoordinate &coordinate,
|
|
|
|
const PathData &path_point)
|
2014-04-01 10:13:54 -04:00
|
|
|
{
|
2014-05-02 13:07:55 -04:00
|
|
|
if ((1 == path_description.size()) && (path_description.back().location == coordinate))
|
2014-04-01 10:13:54 -04:00
|
|
|
{
|
2014-05-02 13:07:55 -04:00
|
|
|
path_description.back().name_id = path_point.name_id;
|
2014-04-01 10:13:54 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-08 05:18:46 -04:00
|
|
|
path_description.emplace_back(coordinate,
|
|
|
|
path_point.name_id,
|
|
|
|
path_point.segment_duration,
|
|
|
|
0,
|
|
|
|
path_point.turn_instruction);
|
2014-04-01 10:13:54 -04:00
|
|
|
}
|
2011-11-17 12:56:45 -05:00
|
|
|
}
|
|
|
|
|
2014-05-16 10:09:40 -04:00
|
|
|
JSON::Value DescriptionFactory::AppendEncodedPolylineString(const bool return_encoded)
|
2014-05-02 13:07:55 -04:00
|
|
|
{
|
|
|
|
if (return_encoded)
|
|
|
|
{
|
2014-05-16 10:09:40 -04:00
|
|
|
return polyline_compressor.printEncodedString(path_description);
|
2014-05-02 13:07:55 -04:00
|
|
|
}
|
2014-05-16 10:09:40 -04:00
|
|
|
return polyline_compressor.printUnencodedString(path_description);
|
2011-11-17 12:56:45 -05:00
|
|
|
}
|
|
|
|
|
2014-05-16 10:09:40 -04:00
|
|
|
JSON::Value DescriptionFactory::AppendUnencodedPolylineString() const
|
2014-05-02 13:07:55 -04:00
|
|
|
{
|
2014-05-16 10:09:40 -04:00
|
|
|
return polyline_compressor.printUnencodedString(path_description);
|
2011-11-17 12:56:45 -05:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:07:55 -04:00
|
|
|
void DescriptionFactory::BuildRouteSummary(const double distance, const unsigned time)
|
|
|
|
{
|
2014-05-16 10:09:40 -04:00
|
|
|
summary.source_name_id = start_phantom.name_id;
|
|
|
|
summary.target_name_id = target_phantom.name_id;
|
2012-02-10 11:14:30 -05:00
|
|
|
summary.BuildDurationAndLengthStrings(distance, time);
|
2011-11-17 12:56:45 -05:00
|
|
|
}
|