Spatial-Hashing icon indicating copy to clipboard operation
Spatial-Hashing copied to clipboard

Interesting, could do with a little more doc please

Open hughperkins opened this issue 2 years ago • 3 comments

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?

hughperkins avatar Jun 19 '23 02:06 hughperkins

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();
        }

Sylmerria avatar Jul 04 '23 07:07 Sylmerria

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?

hughperkins avatar Jul 04 '23 09:07 hughperkins

(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 :) )

hughperkins avatar Jul 04 '23 10:07 hughperkins