From 5b2c7bbd4a628469bab4cbf7468067855e21e784 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 3 Aug 2018 16:08:51 +0200 Subject: [server] Fix snap to grid for call with ignored frame param --- src/server/mainwindow/mainwindow.cpp | 19 ++----------------- src/server/mainwindow/mainwindow.h | 2 +- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index 17bfdb2..ec69a4c 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -220,7 +220,7 @@ MainWindow::~MainWindow() } /** Squared euclidean distance (why is this not implemented in QPoint?) */ -int distance(QPoint a, QPoint b) +static int distance(QPoint a, QPoint b) { const int dx = a.x() - b.x(); const int dy = a.y() - b.y(); @@ -228,14 +228,6 @@ int distance(QPoint a, QPoint b) return sum; } -int distance(QPointF a, QPointF b) -{ - const qreal dx = a.x() - b.x(); - const qreal dy = a.y() - b.y(); - const qreal sum = dx * dx + dy * dy; - return int(sum); -} - /** * \brief: find the closest available frame. * @@ -249,16 +241,9 @@ int distance(QPointF a, QPointF b) * @param toIgnore, ignore this connectionframe when considering free slots * @return the free slot */ -QPoint MainWindow::closestFreeSlot(QPoint preferredPixels, ConnectionFrame* toIgnore) +QPoint MainWindow::closestFreeSlot(const QPoint preferredPixels, const ConnectionFrame* toIgnore) { const bool pickFirstOne = ( preferredPixels == QPoint(-1, -1) ); - if (!pickFirstOne && toIgnore != nullptr) { - // Check if we're already in the desired location and skip all the checks - QPoint desired = QPoint(preferredPixels.x() / getTileWidthPx(), preferredPixels.y() / getTileHeightPx()); - if (desired == toIgnore->getGridPosition()) { - return desired; - } - } const QSize& clientSize = serverApp->getCurrentRoom()->clientSize; #define GRID(X,Y) (grid[((X) * _tilesY) + (Y)]) bool *grid = new bool[_tilesX * _tilesY]; diff --git a/src/server/mainwindow/mainwindow.h b/src/server/mainwindow/mainwindow.h index a8bf974..86499af 100644 --- a/src/server/mainwindow/mainwindow.h +++ b/src/server/mainwindow/mainwindow.h @@ -75,7 +75,7 @@ private: int _lastClientCount; - QPoint closestFreeSlot(QPoint preferredPixels, ConnectionFrame* toIgnore); + QPoint closestFreeSlot(const QPoint preferredPixels, const ConnectionFrame* toIgnore); void placeFrameInFreeSlot(ConnectionFrame* frame, QPoint preferred = QPoint(-1, -1)); ConnectionFrame* createFrame(const QString &computerId = QString(), const QPoint *gridPosition = nullptr, bool fromRoomplan = false); void savePosition(ConnectionFrame *cf); -- cgit v1.2.3-55-g7522