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 <http://www.gnu.org/licenses/>.
8 /** @file town_kdtree.h Declarations for accessing the k-d tree of towns */
10 #ifndef VIEWPORT_KDTREE_H
11 #define VIEWPORT_KDTREE_H
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"
19 struct ViewportSignKdtreeItem
{
20 enum ItemType
: uint16
{
35 bool operator== (const ViewportSignKdtreeItem
&other
) const
37 if (this->type
!= other
.type
) return false;
41 return this->id
.station
== other
.id
.station
;
43 return this->id
.town
== other
.id
.town
;
45 return this->id
.sign
== other
.id
.sign
;
51 bool operator< (const ViewportSignKdtreeItem
&other
) const
53 if (this->type
!= other
.type
) return this->type
< other
.type
;
57 return this->id
.station
< other
.id
.station
;
59 return this->id
.town
< other
.id
.town
;
61 return this->id
.sign
< other
.id
.sign
;
67 static ViewportSignKdtreeItem
MakeStation(StationID id
);
68 static ViewportSignKdtreeItem
MakeWaypoint(StationID id
);
69 static ViewportSignKdtreeItem
MakeTown(TownID id
);
70 static ViewportSignKdtreeItem
MakeSign(SignID id
);
73 inline int32
Kdtree_ViewportSignXYFunc(const ViewportSignKdtreeItem
&item
, int dim
)
75 return (dim
== 0) ? item
.center
: item
.top
;
78 typedef Kdtree
<ViewportSignKdtreeItem
, decltype(&Kdtree_ViewportSignXYFunc
), int32
, int32
> ViewportSignKdtree
;
79 extern ViewportSignKdtree _viewport_sign_kdtree
;
81 void RebuildViewportKdtree();