Example #1
0
    /// <inheritdoc/>
    public IEnumerable<Pair<int>> GetOverlaps(ISpatialPartition<int> otherPartition)
    {
      if (otherPartition == null)
        throw new ArgumentNullException("otherPartition");

      var otherBasePartition = otherPartition as BasePartition<int>;
      if (otherBasePartition != null)
        otherBasePartition.UpdateInternal();
      else
        otherPartition.Update(false);

      Update(false);


      // Test all leaf nodes that touch the other partition's AABB.
      foreach (var leaf in GetLeafNodes(otherPartition.Aabb))
      {
        var otherCandidates = otherPartition.GetOverlaps(GetAabb(leaf));

        // We return one pair for each candidate vs. otherItem overlap.
        foreach (var otherCandidate in otherCandidates)
        {
          var overlap = new Pair<int>(leaf.Item, otherCandidate);
          if (Filter == null || Filter.Filter(overlap))
            yield return overlap;
        }
      }
#else
      return GetOverlapsWithPartitionWork.Create(this, otherPartition);

    }
Example #2
0
        /// <inheritdoc/>
        public virtual IEnumerable <Pair <T> > GetOverlaps(ISpatialPartition <T> otherPartition)
        {
            if (otherPartition == null)
            {
                throw new ArgumentNullException("otherPartition");
            }

            var otherBasePartition = otherPartition as BasePartition <T>;

            if (otherBasePartition != null)
            {
                otherBasePartition.UpdateInternal();
            }
            else
            {
                otherPartition.Update(false);
            }

            UpdateInternal();

#if !POOL_ENUMERABLES
            // Get all items that touch the other partition's AABB.
            var candidates = GetOverlaps(otherPartition.Aabb);

            // Now, we test each candidate against the other partition.
            foreach (var candidate in candidates)
            {
                Aabb candidateAabb   = GetAabbForItem(candidate);
                var  otherCandidates = otherPartition.GetOverlaps(candidateAabb);

                // We return one pair for each candidate vs. otherItem overlap.
                foreach (var otherCandidate in otherCandidates)
                {
                    var overlap = new Pair <T>(candidate, otherCandidate);
                    if (Filter == null || Filter.Filter(overlap))
                    {
                        yield return(overlap);
                    }
                }
            }
#else
            // Avoiding garbage:
            return(GetOverlapsWithPartitionWork.Create(this, otherPartition));
#endif
        }
    private IEnumerable<Pair<T>> GetOverlapsImpl(ISpatialPartition<T> otherPartition)
    {

      // Test all leaf nodes that touch the other partition's AABB.
      foreach (var leaf in GetLeafNodes(otherPartition.Aabb))
      {
        var otherCandidates = otherPartition.GetOverlaps(leaf.Aabb);

        // We return one pair for each candidate vs. otherItem overlap.
        foreach (var otherCandidate in otherCandidates)
        {
          var overlap = new Pair<T>(leaf.Item, otherCandidate);
          if (Filter == null || Filter.Filter(overlap))
            yield return overlap;
        }
      }
#else
      // Avoiding garbage:
      return GetOverlapsWithPartitionWork.Create(this, otherPartition);

    }