26 #include <olp/core/geo/coordinates/GeoCoordinates.h>
27 #include <olp/core/geo/tiling/TileKey.h>
28 #include <olp/core/geo/tiling/TileKeyUtils.h>
29 #include <boost/optional/optional.hpp>
51 bool is_slope_reversed;
52 int32_t sliding_window_half_size;
59 int32_t sliding_offset_x;
60 int32_t sliding_offset_y;
63 bool operator==(
const State& other)
const {
64 return x_end == other.x_end &&
65 is_slope_reversed == other.is_slope_reversed &&
66 sliding_window_half_size == other.sliding_window_half_size &&
67 delta_x == other.delta_x && delta_y == other.delta_y &&
68 y_step == other.y_step && x == other.x && y == other.y &&
69 error == other.error &&
70 sliding_offset_x == other.sliding_offset_x &&
71 sliding_offset_y == other.sliding_offset_y &&
72 tile_level == other.tile_level;
84 int tile_x = state.x + state.sliding_offset_x;
85 int tile_y = state.y + state.sliding_offset_y;
87 if (state.is_slope_reversed)
88 std::swap(tile_x, tile_y);
101 if (state.x > state.x_end) {
105 if (++state.sliding_offset_y > state.sliding_window_half_size) {
106 state.sliding_offset_y = -state.sliding_window_half_size;
107 if (++state.sliding_offset_x > state.sliding_window_half_size) {
108 state.sliding_offset_x = -state.sliding_window_half_size;
110 state.error += state.delta_y;
111 if (state.error * 2 >= state.delta_x) {
112 state.y += state.y_step;
113 state.error -= state.delta_x;
133 const int32_t sliding_window_half_size) {
134 int32_t x0 =
static_cast<int32_t
>(start_tile.
Column());
135 int32_t y0 =
static_cast<int32_t
>(start_tile.
Row());
136 int32_t x1 =
static_cast<int32_t
>(end_tile.
Column());
137 int32_t y1 =
static_cast<int32_t
>(end_tile.
Row());
139 const uint32_t tile_level = start_tile.
Level();
141 const bool should_reverse_slope = std::abs(y1 - y0) > std::abs(x1 - x0);
143 if (should_reverse_slope) {
153 const int32_t line_end = x1;
154 const int32_t delta_x = x1 - x0;
155 const int32_t delta_y = std::abs(y1 - y0);
156 const int32_t y_step = y0 > y1 ? -1 : 1;
157 const int32_t initial_x = x0;
158 const int32_t initial_y = y0;
160 return State{line_end,
161 should_reverse_slope,
162 sliding_window_half_size,
169 -sliding_window_half_size,
170 -sliding_window_half_size,
181 template <
typename InputIterator,
typename TilingScheme>
185 using difference_type = std::ptrdiff_t;
188 using iterator_category = std::forward_iterator_tag;
197 : iterator_(iterator), tiling_scheme_(), tile_level_(tile_level) {}
206 tiling_scheme_,
static_cast<GeoCoordinates>(*iterator_), tile_level_);
215 return iterator_ == other.iterator_;
219 return !(*
this == other);
223 InputIterator iterator_;
224 TilingScheme tiling_scheme_;
225 uint32_t tile_level_;
234 template <
typename TilingScheme,
typename InputIterator>
235 auto MakeTilingIterator(InputIterator iterator, uint32_t tile_level = 0)
236 -> TilingIterator<InputIterator, TilingScheme> {
237 return TilingIterator<InputIterator, TilingScheme>(iterator, tile_level);
244 template <
typename InputIterator>
247 using value_type = std::pair<
typename InputIterator::value_type,
248 typename InputIterator::value_type>;
249 using difference_type = std::ptrdiff_t;
250 using pointer = value_type*;
251 using reference = value_type&;
252 using iterator_category = std::forward_iterator_tag;
260 : current_value_(), next_it_(segment_it) {}
269 InputIterator segment_it)
270 : current_value_(initial_value), next_it_(segment_it) {}
272 value_type operator*()
const {
273 return std::make_pair(current_value_, *next_it_);
277 current_value_ = *next_it_;
283 return next_it_ == other.next_it_;
287 return !(*
this == other);
291 typename InputIterator::value_type current_value_;
292 InputIterator next_it_;
302 template <
typename InputIterator>
303 auto MakeAdjacentPairIterator(InputIterator iterator)
304 -> AdjacentPairIterator<InputIterator> {
305 return AdjacentPairIterator<InputIterator>(iterator);
316 template <
typename InputIterator,
317 typename ValueType =
typename InputIterator::value_type>
318 auto MakeAdjacentPairIterator(ValueType initial_value, InputIterator iterator)
319 -> AdjacentPairIterator<InputIterator> {
320 return AdjacentPairIterator<InputIterator>(initial_value, iterator);
331 template <
typename InputIterator,
332 typename IteratorType = AdjacentPairIterator<InputIterator>>
333 auto MakeAdjacentPairsRange(InputIterator begin, InputIterator end)
334 -> std::pair<IteratorType, IteratorType> {
336 return std::make_pair(MakeAdjacentPairIterator(begin),
337 MakeAdjacentPairIterator(end));
339 return std::make_pair(MakeAdjacentPairIterator(*begin, std::next(begin)),
340 MakeAdjacentPairIterator(end));
350 template <
typename InputIterator>
353 using value_type =
typename InputIterator::value_type;
354 using difference_type = std::ptrdiff_t;
355 using pointer = value_type*;
356 using reference = value_type&;
357 using iterator_category = std::forward_iterator_tag;
366 const uint32_t line_width)
367 : segment_it_(segment_it),
368 half_line_width_(static_cast<int32_t>(line_width) / 2) {}
373 std::tie(begin, end) = *segment_it_;
381 line_state_ = boost::none;
388 return segment_it_ == other.segment_it_ &&
389 half_line_width_ == other.half_line_width_ &&
390 line_state_ == other.line_state_;
394 return !(*
this == other);
398 InputIterator segment_it_;
399 int32_t half_line_width_;
400 boost::optional<detail::LineEvaluator::State> line_state_;
410 template <
typename InputIterator>
411 auto MakeLineSliceIterator(InputIterator iterator,
const uint32_t line_width)
412 -> LineSliceIterator<InputIterator> {
413 return LineSliceIterator<InputIterator>(iterator, line_width);
423 template <
typename InputIterator,
typename TilingScheme>
424 using TiledPathIterator = LineSliceIterator<
425 AdjacentPairIterator<TilingIterator<InputIterator, TilingScheme>>>;
447 template <
typename TilingScheme,
typename InputIterator>
448 auto MakeTiledPathRange(InputIterator begin, InputIterator end,
449 const uint32_t level,
const uint32_t path_width)
450 -> std::pair<TiledPathIterator<InputIterator, TilingScheme>,
451 TiledPathIterator<InputIterator, TilingScheme>> {
452 auto adjacent_pairs_range =
453 MakeAdjacentPairsRange(MakeTilingIterator<TilingScheme>(begin, level),
454 MakeTilingIterator<TilingScheme>(end));
455 return {MakeLineSliceIterator(adjacent_pairs_range.first, path_width),
456 MakeLineSliceIterator(adjacent_pairs_range.second, path_width)};
Iterator for iterating over adjacent pairs in a sequence.
Definition: PathTiling.h:245
AdjacentPairIterator(InputIterator segment_it)
Constructs an AdjacentPairIterator.
Definition: PathTiling.h:259
AdjacentPairIterator(typename InputIterator::value_type initial_value, InputIterator segment_it)
Constructs an AdjacentPairIterator with an initial value.
Definition: PathTiling.h:268
A geographic location that uses the WGS84 Coordinate System.
Definition: GeoCoordinates.h:38
An iterator that slices a line into tile segments.
Definition: PathTiling.h:351
LineSliceIterator(InputIterator segment_it, const uint32_t line_width)
Constructs a LineSliceIterator.
Definition: PathTiling.h:365
static TileKey GeoCoordinatesToTileKey(const ITilingScheme &tiling_scheme, const GeoCoordinates &geo_point, const std::uint32_t level)
Gets the key of the tile that contains geographic coordinates.
Addresses a tile in a quadtree.
Definition: TileKey.h:63
static TileKey FromRowColumnLevel(std::uint32_t row, std::uint32_t column, std::uint32_t level)
Creates a tile key.
constexpr std::uint32_t Column() const
Gets the tile column.
Definition: TileKey.h:219
constexpr std::uint32_t Row() const
Gets the tile row.
Definition: TileKey.h:200
constexpr std::uint32_t Level() const
Gets the tile level.
Definition: TileKey.h:191
Iterator for transforming input coordinates into TileKeys using a TilingScheme.
Definition: PathTiling.h:182
value_type operator*() const
Dereference operator.
Definition: PathTiling.h:204
TilingIterator(InputIterator iterator, const uint32_t tile_level=0)
Constructs a TilingIterator.
Definition: PathTiling.h:196
Implements Bresenham's line algorithm with a square sliding window.
Definition: PathTiling.h:43
static bool Iterate(State &state)
Iterates the state towards the end of the line.
Definition: PathTiling.h:100
static State Init(const TileKey start_tile, const TileKey end_tile, const int32_t sliding_window_half_size)
Initializes the line state between two tiles.
Definition: PathTiling.h:132
static TileKey Value(const State &state)
Evaluates the current tile key from the given state.
Definition: PathTiling.h:83
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24
Holds the state of the line traversal.
Definition: PathTiling.h:49