Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make classes with only a single funtion free standing functions #1870

Merged
merged 6 commits into from
Jan 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions include/engine/api_response_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "guidance/segment_list.hpp"
#include "guidance/textual_route_annotation.hpp"

#include "engine/douglas_peucker.hpp"
#include "engine/internal_route_result.hpp"
#include "engine/object_encoder.hpp"
#include "engine/phantom_node.hpp"
Expand Down Expand Up @@ -49,7 +48,6 @@ template <typename DataFacadeT> class ApiResponseGenerator
using DataFacade = DataFacadeT;
using Segments = guidance::SegmentList<DataFacade>;
using Segment = detail::Segment;
using RouteNameExtractor = ExtractRouteNames<DataFacade, Segment>;

ApiResponseGenerator(DataFacade *facade);

Expand Down Expand Up @@ -121,7 +119,6 @@ void ApiResponseGenerator<DataFacadeT>::DescribeRoute(const RouteParameters &con
}

RouteNames route_names;
RouteNameExtractor generate_route_names;

if (raw_route.has_alternative())
{
Expand Down Expand Up @@ -157,7 +154,7 @@ void ApiResponseGenerator<DataFacadeT>::DescribeRoute(const RouteParameters &con
// generate names for both the main path and the alternative route
auto path_segments = BuildRouteSegments(segment_list);
auto alternate_segments = BuildRouteSegments(alternate_segment_list);
route_names = generate_route_names(path_segments, alternate_segments, facade);
route_names = extractRouteNames(path_segments, alternate_segments, facade);

util::json::Array json_alternate_names_array;
util::json::Array json_alternate_names;
Expand All @@ -173,7 +170,7 @@ void ApiResponseGenerator<DataFacadeT>::DescribeRoute(const RouteParameters &con
// generate names for the main route on its own
auto path_segments = BuildRouteSegments(segment_list);
std::vector<detail::Segment> alternate_segments;
route_names = generate_route_names(path_segments, alternate_segments, facade);
route_names = extractRouteNames(path_segments, alternate_segments, facade);
}

util::json::Array json_route_names;
Expand Down Expand Up @@ -244,9 +241,9 @@ util::json::Value ApiResponseGenerator<DataFacadeT>::GetGeometry(const bool retu
const Segments &segments) const
{
if (return_encoded)
return PolylineFormatter().printEncodedString(segments.Get());
return polylineEncodeAsJSON(segments.Get());
else
return PolylineFormatter().printUnencodedString(segments.Get());
return polylineUnencodedAsJSON(segments.Get());
}

template <typename DataFacadeT>
Expand All @@ -257,11 +254,12 @@ ApiResponseGenerator<DataFacadeT>::BuildRouteSegments(const Segments &segment_li
for (const auto &segment : segment_list.Get())
{
const auto current_turn = segment.turn_instruction;
if (extractor::TurnInstructionsClass::TurnIsNecessary(current_turn) &&
if (extractor::isTurnNecessary(current_turn) &&
(extractor::TurnInstruction::EnterRoundAbout != current_turn))
{

detail::Segment seg = {segment.name_id, static_cast<int32_t>(segment.length),
detail::Segment seg = {segment.name_id,
static_cast<int32_t>(segment.length),
static_cast<std::size_t>(result.size())};
result.emplace_back(std::move(seg));
}
Expand Down
50 changes: 24 additions & 26 deletions include/engine/douglas_peucker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,16 @@

#include "engine/segment_information.hpp"

#include <array>
#include <stack>
#include <utility>
#include <vector>
#include <iterator>

namespace osrm
{
namespace engine
{

/* This class object computes the bitvector of indicating generalized input
* points according to the (Ramer-)Douglas-Peucker algorithm.
*
* Input is vector of pairs. Each pair consists of the point information and a
* bit indicating if the points is present in the generalization.
* Note: points may also be pre-selected*/

static const std::array<int, 19> DOUGLAS_PEUCKER_THRESHOLDS{{
namespace detail
{
const constexpr int DOUGLAS_PEUCKER_THRESHOLDS[19] = {
512440, // z0
256720, // z1
122560, // z2
Expand All @@ -39,22 +31,28 @@ static const std::array<int, 19> DOUGLAS_PEUCKER_THRESHOLDS{{
20, // z15
8, // z16
6, // z17
4 // z18
}};
4, // z18
};

class DouglasPeucker
const constexpr auto DOUGLAS_PEUCKER_THRESHOLDS_SIZE =
sizeof(DOUGLAS_PEUCKER_THRESHOLDS) / sizeof(*DOUGLAS_PEUCKER_THRESHOLDS);
} // ns detail

// These functions compute the bitvector of indicating generalized input
// points according to the (Ramer-)Douglas-Peucker algorithm.
//
// Input is vector of pairs. Each pair consists of the point information and a
// bit indicating if the points is present in the generalization.
// Note: points may also be pre-selected*/
void douglasPeucker(std::vector<SegmentInformation>::iterator begin,
std::vector<SegmentInformation>::iterator end,
const unsigned zoom_level);

// Convenience range-based function
inline void douglasPeucker(std::vector<SegmentInformation> &geometry, const unsigned zoom_level)
{
public:
using RandomAccessIt = std::vector<SegmentInformation>::iterator;

using GeometryRange = std::pair<RandomAccessIt, RandomAccessIt>;
// Stack to simulate the recursion
std::stack<GeometryRange> recursion_stack;

public:
void Run(RandomAccessIt begin, RandomAccessIt end, const unsigned zoom_level);
void Run(std::vector<SegmentInformation> &input_geometry, const unsigned zoom_level);
};
douglasPeucker(begin(geometry), end(geometry), zoom_level);
}
}
}

Expand Down
7 changes: 3 additions & 4 deletions include/engine/guidance/segment_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,13 @@ void SegmentList<DataFacadeT>::Finalize(const bool extract_alternative,

if (allow_simplification)
{
DouglasPeucker polyline_generalizer;
polyline_generalizer.Run(segments.begin(), segments.end(), zoom_level);
douglasPeucker(segments, zoom_level);
}

std::uint32_t necessary_segments = 0; // a running index that counts the necessary pieces
via_indices.push_back(0);
const auto markNecessarySegments = [this, &necessary_segments](SegmentInformation &first,
const SegmentInformation &second)
const auto markNecessarySegments =
[this, &necessary_segments](SegmentInformation &first, const SegmentInformation &second)
{
if (!first.necessary)
return;
Expand Down
2 changes: 1 addition & 1 deletion include/engine/guidance/textual_route_annotation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ inline util::json::Array AnnotateRoute(const std::vector<SegmentInformation> &ro
{
util::json::Array json_instruction_row;
extractor::TurnInstruction current_instruction = segment.turn_instruction;
if (extractor::TurnInstructionsClass::TurnIsNecessary(current_instruction))
if (extractor::isTurnNecessary(current_instruction))
{
if (extractor::TurnInstruction::EnterRoundAbout == current_instruction)
{
Expand Down
6 changes: 3 additions & 3 deletions include/engine/plugins/match.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ template <class DataFacadeT> class MapMatchingPlugin : public BasePlugin

if (input_coords.size() - 1 > current_coordinate && 0 < current_coordinate)
{
double turn_angle = util::ComputeAngle::OfThreeFixedPointCoordinates(
input_coords[current_coordinate - 1], input_coords[current_coordinate],
input_coords[current_coordinate + 1]);
double turn_angle = util::ComputeAngle(input_coords[current_coordinate - 1],
input_coords[current_coordinate],
input_coords[current_coordinate + 1]);

// sharp turns indicate a possible uturn
if (turn_angle <= 90.0 || turn_angle >= 270.0)
Expand Down
21 changes: 7 additions & 14 deletions include/engine/polyline_compressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define POLYLINECOMPRESSOR_H_

#include "osrm/coordinate.hpp"
#include "engine/segment_information.hpp"

#include <string>
#include <vector>
Expand All @@ -10,21 +11,13 @@ namespace osrm
{
namespace engine
{
// Encodes geometry into polyline format.
// See: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
std::string polylineEncode(const std::vector<SegmentInformation> &geometry);

struct SegmentInformation;

class PolylineCompressor
{
private:
std::string encode_vector(std::vector<int> &numbers) const;

std::string encode_number(const int number_to_encode) const;

public:
std::string get_encoded_string(const std::vector<SegmentInformation> &polyline) const;

std::vector<util::FixedPointCoordinate> decode_string(const std::string &geometry_string) const;
};
// Decodes geometry from polyline format
// See: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
std::vector<util::FixedPointCoordinate> polylineDecode(const std::string &polyline);
}
}

Expand Down
13 changes: 6 additions & 7 deletions include/engine/polyline_formatter.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef POLYLINE_FORMATTER_HPP
#define POLYLINE_FORMATTER_HPP

#include "engine/segment_information.hpp"
#include "osrm/json_container.hpp"

#include <string>
Expand All @@ -11,14 +12,12 @@ namespace osrm
namespace engine
{

struct SegmentInformation;
// Encodes geometry into polyline format, returning an encoded JSON object
// See: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
util::json::String polylineEncodeAsJSON(const std::vector<SegmentInformation> &geometry);

struct PolylineFormatter
{
util::json::String printEncodedString(const std::vector<SegmentInformation> &polyline) const;

util::json::Array printUnencodedString(const std::vector<SegmentInformation> &polyline) const;
};
// Does not encode the geometry in polyline format, instead returning an unencoded JSON object
util::json::Array polylineUnencodedAsJSON(const std::vector<SegmentInformation> &geometry);
}
}

Expand Down
Loading