/// <summary> /// Returns index of the child closest to the point. /// </summary> public int FindClosestChild(double [] point, bool normalize) { double[] normalizedPoint = point.ShallowCopy(); if (normalize) { VectorS.NormalizeByDiff(normalizedPoint, ValueMin, ValueBounds); } double minDist = double.MaxValue; int best = -1; for (int c = 0; c < Children.Length; ++c) { double dist = VectorS.SquaredDistance(Children[c].Center, normalizedPoint); if (dist < minDist) { minDist = dist; best = c; } } return(best); }
public void Test_SquaredDistance() { Assert.AreEqual(2, VectorS.SquaredDistance(new double[] { 1, 3 }, new double[] { 2, 4 })); }