summaryrefslogtreecommitdiff
path: root/src/helpers/MiscFunctions.cpp
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-05-25 18:40:03 +0200
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-05-25 18:40:03 +0200
commit08d4d987cf9e25332a358667332507fb3491ce9b (patch)
tree52dfe1c2fd9bf142b4247e0dfdb3e8ec1ae79ef2 /src/helpers/MiscFunctions.cpp
parent5635c6385f7bc99c415ef76b3c1b83a210073224 (diff)
return nearest mon if point out of range
Diffstat (limited to 'src/helpers/MiscFunctions.cpp')
-rw-r--r--src/helpers/MiscFunctions.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp
index ebc8c213..440bdc26 100644
--- a/src/helpers/MiscFunctions.cpp
+++ b/src/helpers/MiscFunctions.cpp
@@ -140,4 +140,10 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
}
return result;
+}
+
+float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Vector2D& p2) {
+ const float DX = std::max((double)0, std::max(p1.x - vec.x, vec.x - p2.x));
+ const float DY = std::max((double)0, std::max(p1.y - vec.y, vec.y - p2.y));
+ return DX * DX + DY * DY;
} \ No newline at end of file