OpenTTD Source: src/viewport_kdtree.h Source File

OpenTTD Source 15.0-RC2

viewport_kdtree.h
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef VIEWPORT_KDTREE_H
11#define VIEWPORT_KDTREE_H
12
13#include "core/kdtree.hpp"
14#include "viewport_type.h"
15#include "station_base.h"
16#include "town_type.h"
17#include "signs_base.h"
18
19 struct ViewportSignKdtreeItem {
20 enum ItemType : uint16_t {
21 VKI_STATION,
22 VKI_WAYPOINT,
23 VKI_TOWN,
24 VKI_SIGN,
25 };
26 ItemType type;
27 std::variant<StationID, TownID, SignID> id;
28 int32_t center;
29 int32_t top;
30
31 bool operator== (const ViewportSignKdtreeItem &other) const
32 {
33 if (this->type != other.type) return false;
34 return this->id == other.id;
35 }
36
37 bool operator< (const ViewportSignKdtreeItem &other) const
38 {
39 if (this->type != other.type) return this->type < other.type;
40 return this->id < other.id;
41 }
42
43 static ViewportSignKdtreeItem MakeStation(StationID id);
44 static ViewportSignKdtreeItem MakeWaypoint(StationID id);
45 static ViewportSignKdtreeItem MakeTown(TownID id);
46 static ViewportSignKdtreeItem MakeSign(SignID id);
47};
48
49 struct Kdtree_ViewportSignXYFunc {
50 inline int32_t operator()(const ViewportSignKdtreeItem &item, int dim)
51 {
52 return (dim == 0) ? item.center : item.top;
53 }
54};
55
56using ViewportSignKdtree = Kdtree<ViewportSignKdtreeItem, Kdtree_ViewportSignXYFunc, int32_t, int32_t>;
57extern ViewportSignKdtree _viewport_sign_kdtree;
58
59void RebuildViewportKdtree();
60
61#endif
Kdtree
K-dimensional tree, specialised for 2-dimensional space.
Definition kdtree.hpp:33
kdtree.hpp
K-d tree template specialised for 2-dimensional Manhattan geometry.
signs_base.h
Base class for signs.
station_base.h
Base classes/functions for stations.
Kdtree_ViewportSignXYFunc
Definition viewport_kdtree.h:49
PoolID< uint16_t, struct StationIDTag, 64000, 0xFFFF >
ViewportSignKdtreeItem
Definition viewport_kdtree.h:19
town_type.h
Types related to towns.
viewport_type.h
Types related to viewports.