/// <summary> /// Inserts the given value into each intersecting bin. /// </summary> /// <param name="box"></param> /// <param name="value"></param> public void Insert(Interval3d box, T value) { box.MakeIncreasing(); var key0 = ToKey(box.A); var key1 = ToKey(box.B); for (int k = key0.K; k <= key1.K; k++) { for (int j = key0.J; j <= key1.J; j++) { for (int i = key0.I; i <= key1.I; i++) { var bin = GetBin(new BinKey(i, j, k)); // sync bin if necessary if (bin.Version != _version) { bin.Version = _version; bin.Clear(); } bin.Add(value); _count++; } } } }
/// <summary> /// Returns each intersecting bin. /// </summary> private IEnumerable <Bin> SearchImpl(Interval3d box) { box.MakeIncreasing(); (int i0, int j0, int k0) = IndicesAt(box.A); (int i1, int j1, int k1) = IndicesAt(box.B); var currQuery = NextQuery; for (int k = k0; k <= k1; k++) { for (int j = j0; j <= j1; j++) { for (int i = i0; i <= i1; i++) { var bin = GetBin(i, j, k); // skip bin if not synced or already visited if (bin.LastVersion != _currVersion || bin.LastQuery == currQuery) { continue; } bin.LastQuery = currQuery; yield return(bin); } } } }
/// <summary> /// Returns each intersecting bin. /// </summary> private IEnumerable <Bin> SearchImpl(Interval3d box) { box.MakeIncreasing(); var key0 = ToKey(box.A); var key1 = ToKey(box.B); for (int k = key0.K; k <= key1.K; k++) { for (int j = key0.J; j <= key1.J; j++) { for (int i = key0.I; i <= key1.I; i++) { // skip if no bin at key if (!_bins.TryGetValue(new BinKey(i, j, k), out Bin bin)) { continue; } // skip bin if not synced if (bin.LastVersion != _version) { continue; } yield return(bin); } } } }
/// <summary> /// Returns each intersecting bin. /// </summary> private IEnumerable <Bin> SearchImpl(Interval3d box) { box.MakeIncreasing(); var key0 = ToKey(box.A); var key1 = ToKey(box.B); for (int k = key0.K; k <= key1.K; k++) { for (int j = key0.J; j <= key1.J; j++) { for (int i = key0.I; i <= key1.I; i++) { if (_bins.TryGetValue(new BinKey(i, j, k), out Bin bin) && bin.Version == _version) { yield return(bin); } } } } }
/// <summary> /// Returns the contents of all intersecting bins. /// </summary> public void Search(Interval3d box, List <T> result) { box.MakeIncreasing(); var key0 = ToKey(box.A); var key1 = ToKey(box.B); for (int k = key0.K; k <= key1.K; k++) { for (int j = key0.J; j <= key1.J; j++) { for (int i = key0.I; i <= key1.I; i++) { if (_bins.TryGetValue(new BinKey(i, j, k), out Bin bin) && bin.Version == _version) { result.AddRange(bin); } } } } }
/// <summary> /// Inserts the given value into each intersecting bin. /// </summary> /// <param name="box"></param> /// <param name="value"></param> public void Insert(Interval3d box, T value) { box.MakeIncreasing(); (int i0, int j0, int k0) = IndicesAt(box.A); (int i1, int j1, int k1) = IndicesAt(box.B); var currQuery = NextQuery; for (int k = k0; k <= k1; k++) { for (int j = j0; j <= j1; j++) { for (int i = i0; i <= i1; i++) { var bin = GetBin(i, j, k); // skip bin if already visited if (bin.LastQuery == currQuery) { continue; } bin.LastQuery = currQuery; // sync bin if necessary if (bin.LastVersion != _currVersion) { bin.LastVersion = _currVersion; bin.Clear(); } bin.Add(value); _count++; } } } }