File indexing completed on 2024-12-22 04:27:03

0001 /*
0002     SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KOSMINDOORMAP_POLEOFINACCESSIBILITYFINDER_H
0008 #define KOSMINDOORMAP_POLEOFINACCESSIBILITYFINDER_H
0009 
0010 #include <QPointF>
0011 
0012 #include <queue>
0013 
0014 class QPolygonF;
0015 
0016 namespace KOSMIndoorMap {
0017 
0018 /** Computes the Pole Of Inaccessibility of a polygon.
0019  *  That is, the point furthest away from the polygon outline,
0020  *  which is where we usually want to place a label.
0021  *
0022  *  @see https://github.com/mapbox/polylabel
0023  */
0024 class PoleOfInaccessibilityFinder
0025 {
0026 public:
0027     explicit PoleOfInaccessibilityFinder();
0028     ~PoleOfInaccessibilityFinder();
0029 
0030     QPointF find(const QPolygonF &poly);
0031 
0032 private:
0033     struct Cell {
0034         explicit Cell(const QPointF &_center, double _size, const QPolygonF &poly);
0035 
0036         bool operator<(const Cell &other) const;
0037         double maximumDistance() const;
0038 
0039         QPointF center;
0040         double size;
0041         double distance;
0042     };
0043 
0044     class CellPriorityQueue : public std::priority_queue<Cell, std::vector<Cell>>
0045     {
0046     public:
0047         void clear();
0048     };
0049     CellPriorityQueue m_queue;
0050 };
0051 
0052 }
0053 
0054 #endif // KOSMINDOORMAP_POLEOFINACCESSIBILITYFINDER_H