area.h
Go to the documentation of this file.
1 /* Copyright 2018-2019 TomTom N.V., 2014 Gareth Cross
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7 http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License. */
14 
15 #pragma once
16 
17 #include <cmath>
18 #include <stdexcept>
19 #include <tuple>
20 #include <utility>
21 
22 #include "coordinates.h"
23 #include "mercator.h"
24 #include "tile_id.h"
25 
31 struct Area
32 {
36 
42  Area(TileId center, int blocks) : center(std::move(center))
43  {
44  if (blocks < 0)
45  {
46  throw std::invalid_argument("The number of blocks has to be positive");
47  }
48 
49  TileCoordinate const& center_tile = center.coord;
50 
51  // An Area is defined through its left top and right bottom coordinates. These points will be calculated.
52  // Furthermore, constraints from the documentation https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#X_and_Y
53  // are satisfied.
54  int const min_x = std::max(0, center_tile.x - blocks);
55  int const min_y = std::max(0, center_tile.y - blocks);
56  int const max_x = std::min(zoomToMaxTiles(center.zoom), center_tile.x + blocks);
57  int const max_y = std::min(zoomToMaxTiles(center.zoom), center_tile.y + blocks);
58 
59  left_top = { min_x, min_y };
60  right_bottom = { max_x, max_y };
61  }
62 };
63 
64 inline bool operator==(Area const& self, Area const& other)
65 {
66  return std::tie(self.left_top, self.right_bottom, self.center) ==
67  std::tie(other.left_top, other.right_bottom, other.center);
68 }
69 
75 inline bool areaContainsTile(Area const& haystack, TileId const& needle)
76 {
77  bool const in_area = needle.coord >= haystack.left_top && needle.coord <= haystack.right_bottom;
78  bool const corresponds = haystack.center.tile_server == needle.tile_server && haystack.center.zoom == needle.zoom;
79  return in_area && corresponds;
80 }
coordinates.h
Area::Area
Area(TileId center, int blocks)
Creates a square area with the center center and the radius blocks.
Definition: area.h:42
zoomToMaxTiles
int zoomToMaxTiles(int zoom)
Definition: mercator.h:42
TileCoordinateGeneric::x
NumericType x
Definition: coordinates.h:43
TileId::zoom
int zoom
Definition: tile_id.h:35
TileId::tile_server
std::string tile_server
Definition: tile_id.h:33
Area
Definition: area.h:31
operator==
bool operator==(Area const &self, Area const &other)
Definition: area.h:64
tile_id.h
Area::center
TileId center
Definition: area.h:35
mercator.h
TileId
Definition: tile_id.h:31
TileCoordinateGeneric< int >
TileCoordinateGeneric::y
NumericType y
Definition: coordinates.h:43
Area::right_bottom
TileCoordinate right_bottom
Definition: area.h:34
areaContainsTile
bool areaContainsTile(Area const &haystack, TileId const &needle)
Definition: area.h:75
std
TileId::coord
TileCoordinate coord
Definition: tile_id.h:34
Area::left_top
TileCoordinate left_top
Definition: area.h:33


rviz_satellite
Author(s): Gareth Cross , Andre Schröder
autogenerated on Thu May 4 2023 02:47:22