Skip to content

Commit 709ead1

Browse files
committed
layout move tool
1 parent 84bd0a1 commit 709ead1

6 files changed

Lines changed: 881 additions & 0 deletions

File tree

src/application/LayoutCanvasSnapping.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,4 +367,37 @@ LayoutSnapResult snapLayoutDragPoint(
367367
return result;
368368
}
369369

370+
LayoutDragSnapResult snapLayoutSelectionDrag(
371+
const safecrowd::domain::FacilityLayout2D& staticLayout,
372+
const std::string& floorId,
373+
const std::vector<safecrowd::domain::Point2D>& anchors,
374+
const safecrowd::domain::Point2D& rawDelta,
375+
const LayoutCanvasTransform& transform,
376+
const LayoutSnapOptions& options) {
377+
LayoutDragSnapResult result{.delta = rawDelta};
378+
if (anchors.empty()) {
379+
return result;
380+
}
381+
382+
double bestDistance = options.tolerancePixels;
383+
for (const auto& anchor : anchors) {
384+
const auto moved = anchor + rawDelta;
385+
const auto snapped = snapLayoutDragPoint(staticLayout, floorId, anchor, moved, transform, options);
386+
if (!snapped.snapped) {
387+
continue;
388+
}
389+
390+
const auto distance = screenDistance(transform, moved, snapped.point);
391+
if (distance <= bestDistance) {
392+
bestDistance = distance;
393+
result = {
394+
.delta = snapped.point - anchor,
395+
.snapped = true,
396+
};
397+
}
398+
}
399+
400+
return result;
401+
}
402+
370403
} // namespace safecrowd::application

src/application/LayoutCanvasSnapping.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <string>
4+
#include <vector>
45

56
#include "application/LayoutCanvasRendering.h"
67
#include "domain/FacilityLayout2D.h"
@@ -18,6 +19,11 @@ struct LayoutSnapResult {
1819
bool snapped{false};
1920
};
2021

22+
struct LayoutDragSnapResult {
23+
safecrowd::domain::Point2D delta{};
24+
bool snapped{false};
25+
};
26+
2127
LayoutSnapResult snapLayoutPoint(
2228
const safecrowd::domain::FacilityLayout2D& layout,
2329
const std::string& floorId,
@@ -33,4 +39,12 @@ LayoutSnapResult snapLayoutDragPoint(
3339
const LayoutCanvasTransform& transform,
3440
const LayoutSnapOptions& options = {});
3541

42+
LayoutDragSnapResult snapLayoutSelectionDrag(
43+
const safecrowd::domain::FacilityLayout2D& staticLayout,
44+
const std::string& floorId,
45+
const std::vector<safecrowd::domain::Point2D>& anchors,
46+
const safecrowd::domain::Point2D& rawDelta,
47+
const LayoutCanvasTransform& transform,
48+
const LayoutSnapOptions& options = {});
49+
3650
} // namespace safecrowd::application

0 commit comments

Comments
 (0)