Spatial-Hashing
Spatial-Hashing copied to clipboard
Interesting, could do with a little more doc please
Hi,
This looks interesting. Dont suppose.. could you provide an example of how to query the k nearest items to a point in space please?
Hi !
You have code sample on Test assembly. An example of query :
public void SpatialHashSimpleQuerry()
{
SpatialHash<Item> sh = new SpatialHash<Item>(new Bounds(new float3(15F), new float3(30F)), new float3(1F), 15, Allocator.Temp);
var item = new Item { Center = new float3(5.5F), Size = new float3(1.1F) };
sh.Add(ref item);
Assert.AreEqual(1, sh.ItemCount);
Assert.AreEqual(3 * 3 * 3, sh.BucketItemCount);
var querryBound = new Bounds(5.5F, 0.1F);
var results = new NativeList<Item>(5, Allocator.TempJob);
sh.Query(querryBound, results);
Assert.AreEqual(1, results.Length);
Assert.AreEqual(item, results[0]);
//check clear result
results.Dispose();
sh.Dispose();
}
Ok. Where is k in this example? Like, let's say I want the closest 3 points, in a hash containing 10s or 100s of points, how would I obtain these?
(Also, if the tests are the doc, I feel it might be useful to add some docstring to each test, explaining what the test is doing, and what each of the variables etc in the test represent :) )