7#include "poleofinaccessibilityfinder_p.h"
8#include "scenegeometry_p.h"
20static double pointToPolygonDistance(
const QPointF &point,
const QPolygonF &poly)
22 auto dist = std::numeric_limits<double>::max();
23 for (
auto i = 0; i < poly.
size(); ++i) {
24 const auto p1 = poly.
at(i);
25 const auto p2 = poly.
at((i + 1) % poly.
size());
26 dist = std::min(dist, SceneGeometry::distanceToLine(
QLineF(p1, p2), point));
31void PoleOfInaccessibilityFinder::CellPriorityQueue::clear()
37PoleOfInaccessibilityFinder::Cell::Cell(
const QPointF &_center,
double _size,
const QPolygonF &poly)
40 ,
distance(pointToPolygonDistance(_center, poly))
44double PoleOfInaccessibilityFinder::Cell::maximumDistance()
const
46 return distance + size * std::sqrt(2.0);
49bool PoleOfInaccessibilityFinder::Cell::operator<(
const PoleOfInaccessibilityFinder::Cell &other)
const
51 return maximumDistance() < other.maximumDistance();
55PoleOfInaccessibilityFinder::PoleOfInaccessibilityFinder() =
default;
56PoleOfInaccessibilityFinder::~PoleOfInaccessibilityFinder() =
default;
61 const auto cellSize = std::min(boundingBox.width(), boundingBox.height());
62 auto h = cellSize / 2.0;
63 if (cellSize == 0.0) {
64 return boundingBox.center();
68 for (
auto x = boundingBox.left(); x < boundingBox.right(); x += cellSize) {
69 for (
auto y = boundingBox.top(); y < boundingBox.bottom(); y += cellSize) {
70 m_queue.push(Cell(
QPointF(x + h, y + h), h, poly));
75 auto bestCell = Cell(SceneGeometry::polygonCentroid(poly), 0, poly);
76 const auto bboxCell = Cell(boundingBox.center(), 0, poly);
77 if (bboxCell.distance > bestCell.distance) {
81 while (!m_queue.empty()) {
82 auto cell = m_queue.top();
85 if (cell.distance > bestCell.distance) {
89 if (cell.maximumDistance() - bestCell.distance <= 0.00002) {
94 m_queue.push(Cell(
QPointF(cell.center.x() - h, cell.center.y() - h), h, poly));
95 m_queue.push(Cell(
QPointF(cell.center.x() + h, cell.center.y() - h), h, poly));
96 m_queue.push(Cell(
QPointF(cell.center.x() - h, cell.center.y() + h), h, poly));
97 m_queue.push(Cell(
QPointF(cell.center.x() + h, cell.center.y() + h), h, poly));
101 return bestCell.center;
int distance(const GeoCoordinates &coord1, const GeoCoordinates &coord2)
OSM-based multi-floor indoor maps for buildings.
const_reference at(qsizetype i) const const
qsizetype size() const const
QRectF boundingRect() const const
bool containsPoint(const QPointF &point, Qt::FillRule fillRule) const const
QTextStream & center(QTextStream &stream)