using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
namespace NativeQuadTree
{
///
/// Examples on jobs for the NativeQuadTree
///
public static class QuadTreeJobs
{
///
/// Bulk insert many items into the tree
///
[BurstCompile]
public struct AddBulkJob : IJob where T : unmanaged
{
[ReadOnly]
public NativeArray> Elements;
public NativeQuadTree QuadTree;
public void Execute()
{
QuadTree.ClearAndBulkInsert(Elements);
}
}
///
/// Example on how to do a range query, it's better to write your own and do many queries in a batch
///
[BurstCompile]
public struct RangeQueryJob : IJob where T : unmanaged
{
[ReadOnly]
public AABB2D Bounds;
[ReadOnly]
public NativeQuadTree QuadTree;
public NativeList> Results;
public void Execute()
{
for (int i = 0; i < 1000; i++)
{
QuadTree.RangeQuery(Bounds, Results);
Results.Clear();
}
QuadTree.RangeQuery(Bounds, Results);
}
}
}
}