Cool! Some speed results:
99 points:
9
9
999 points:
90
73
4999 points:
457
338
...So the second method gets faster when the pointcount increases. But it never gets slower! :)
I guess that if you would sort the point positions (while retaining the index of the original point someway) spatially before searching you could develop even faster method as the sorting is one time only operation (that can be done "during loading"), and does not slow down anything during runtime.
99 points:
9
9
999 points:
90
73
4999 points:
457
338
...So the second method gets faster when the pointcount increases. But it never gets slower! :)
I guess that if you would sort the point positions (while retaining the index of the original point someway) spatially before searching you could develop even faster method as the sorting is one time only operation (that can be done "during loading"), and does not slow down anything during runtime.