From 08d4d987cf9e25332a358667332507fb3491ce9b Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 25 May 2022 18:40:03 +0200 Subject: return nearest mon if point out of range --- src/helpers/MiscFunctions.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/helpers/MiscFunctions.cpp') 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 -- cgit v1.2.3