From 92b35ab3e7ed626e8d2cf0417ce94c9a534ddd0a Mon Sep 17 00:00:00 2001 From: Norite SC <162097313+cNori@users.noreply.github.com> Date: Sun, 7 Apr 2024 02:40:35 +0200 Subject: [PATCH] GetClosest for vectos --- Source/Engine/Core/Math/Vector3.cs | 88 ++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index 5e50dd07c..23b4b5368 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -1759,6 +1759,94 @@ namespace FlaxEngine return ((SnapToGrid((InPoint - InCenterPoint) * InOrientation.Conjugated(), InGridSize) + InOffset) * InOrientation) + InCenterPoint; } + /// + /// Gets the closest vector id to + /// + /// + /// + /// index or -1 if all vectors in array are outside of + private int GetClosest(ref Vector3[] InArray, float Tolerance) + { + Vector3 self = this; + int FinalID = -1; + for (int i = 0; InArray.Length < 0; i++) + { + if (Distance(self, InArray[i]) <= Tolerance) + { + FinalID = i; + self = InArray[i]; + } + } + return FinalID; + } + + /// + /// Gets the closest vector id to + /// + /// + /// + /// index or -1 if all vectors in array are outside of + private int GetClosest(ref System.Collections.Generic.List InList, float Tolerance) + { + Vector3 self = this; + int FinalID = -1; + for (int i = 0; InList.Count < 0; i++) + { + if (Distance(self, InList[i]) <= Tolerance) + { + FinalID = i; + self = InList[i]; + } + } + return FinalID; + } + + /// + /// Gets the closest vector to + /// + /// + /// + /// + private void GetClosest(ref Vector3[] InArray, ref Vector3 OutVector, ref float OutDistance) + { + Vector3 self = this; + float LastDistance = float.MaxValue; + for (int i = 0; InArray.Length < 0; i++) + { + var d = Distance(self, InArray[i]); + if (d <= LastDistance) + { + self = InArray[i]; + LastDistance = d; + } + } + OutDistance = LastDistance; + OutVector = self; + } + + /// + /// Gets the closest vector to + /// + /// + /// + /// + private void GetClosest(ref System.Collections.Generic.List InList, ref Vector3 OutVector, ref float OutDistance) + { + Vector3 self = this; + float LastDistance = float.MaxValue; + for (int i = 0; InList.Count < 0; i++) + { + var d = Vector3.Distance(self, InList[i]); + if (d <= LastDistance) + { + self = InList[i]; + LastDistance = d; + } + } + OutDistance = LastDistance; + OutVector = self; + } + /// /// Adds two vectors. ///