private IEnumerable<Pair<T>> GetOverlapsImpl(Vector3 scale, ISpatialPartition<T> otherPartition, Vector3 otherScale, Pose otherPose)
    {
      // Compute transformations.
      Vector3 scaleInverse = Vector3.One / scale;
      Vector3 otherScaleInverse = Vector3.One / otherScale;
      Pose toLocal = otherPose;
      Pose toOther = otherPose.Inverse;

      // Transform the AABB of the other partition into space of the this partition.
      var otherAabb = otherPartition.Aabb;
      otherAabb = otherAabb.GetAabb(otherScale, toLocal); // Apply local scale and transform to scaled local space of this partition.
      otherAabb.Scale(scaleInverse);                      // Transform to unscaled local space of this partition.

      var leafNodes = GetLeafNodes(otherAabb);


      foreach (var leaf in leafNodes)
      {
        // Transform AABB of this partition into space of the other partition.
        Aabb aabb = leaf.Aabb.GetAabb(scale, toOther);    // Apply local scale and transform to scaled local space of other partition.
        aabb.Scale(otherScaleInverse);                    // Transform to unscaled local space of other partition.

        foreach (var otherCandidate in otherPartition.GetOverlaps(aabb))
        {
          var overlap = new Pair<T>(leaf.Item, otherCandidate);
          if (Filter == null || Filter.Filter(overlap))
            yield return overlap;
        }
      }
#else
      // Avoiding garbage:
      return GetOverlapsWithTransformedPartitionWork.Create(this, otherPartition, leafNodes, ref scale, ref otherScaleInverse, ref toOther);

    }
Beispiel #2
0
        /// <inheritdoc/>
        public virtual IEnumerable <Pair <T> > GetOverlaps(Vector3F scale, Pose pose, ISpatialPartition <T> otherPartition, Vector3F otherScale, Pose otherPose)
        {
            if (otherPartition == null)
            {
                throw new ArgumentNullException("otherPartition");
            }

            var otherBasePartition = otherPartition as BasePartition <T>;

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

            UpdateInternal();

            // Compute transformations.
            Vector3F scaleInverse      = Vector3F.One / scale;
            Vector3F otherScaleInverse = Vector3F.One / otherScale;
            Pose     toLocal           = pose.Inverse * otherPose;
            Pose     toOther           = toLocal.Inverse;

            // Transform the AABB of the other partition into space of the this partition.
            var otherAabb = otherPartition.Aabb;

            otherAabb = otherAabb.GetAabb(otherScale, toLocal); // Apply local scale and transform to scaled local space of this partition.
            otherAabb.Scale(scaleInverse);                      // Transform to unscaled local space of this partition.

            var candidates = GetOverlaps(otherAabb);

#if !POOL_ENUMERABLES
            foreach (var candidate in candidates)
            {
                // Transform AABB of this partition into space of the other partition.
                var aabb = GetAabbForItem(candidate);
                aabb = aabb.GetAabb(scale, toOther); // Apply local scale and transform to scaled local space of other partition.
                aabb.Scale(otherScaleInverse);       // Transform to unscaled local space of other partition.

                foreach (var otherCandidate in otherPartition.GetOverlaps(aabb))
                {
                    var overlap = new Pair <T>(candidate, otherCandidate);
                    if (Filter == null || Filter.Filter(overlap))
                    {
                        yield return(overlap);
                    }
                }
            }
#else
            // Avoiding garbage:
            return(GetOverlapsWithTransformedPartitionWork.Create(this, otherPartition, candidates, ref scale, ref otherScaleInverse, ref toOther));
#endif
        }
Beispiel #3
0
    /// <inheritdoc/>
    public IEnumerable<Pair<int>> GetOverlaps(Vector3 scale, Pose pose, ISpatialPartition<int> otherPartition, Vector3 otherScale, Pose otherPose)
    {
      if (otherPartition == null)
        throw new ArgumentNullException("otherPartition");

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

      Update(false);

      // Compute transformations.
      Vector3 scaleInverse = Vector3.One / scale;
      Vector3 otherScaleInverse = Vector3.One / otherScale;
      Pose toLocal = pose.Inverse * otherPose;
      Pose toOther = toLocal.Inverse;

      // Transform the AABB of the other partition into space of the this partition.
      var otherAabb = otherPartition.Aabb;
      otherAabb = otherAabb.GetAabb(otherScale, toLocal); // Apply local scale and transform to scaled local space of this partition.
      otherAabb.Scale(scaleInverse);                      // Transform to unscaled local space of this partition.

      var leafNodes = GetLeafNodes(otherAabb);


      foreach (var leaf in leafNodes)
      {
        // Transform AABB of this partition into space of the other partition.
        var aabb = GetAabb(leaf);
        aabb = aabb.GetAabb(scale, toOther);  // Apply local scale and transform to scaled local space of other partition.
        aabb.Scale(otherScaleInverse);        // Transform to unscaled local space of other partition.

        foreach (var otherCandidate in otherPartition.GetOverlaps(aabb))
        {
          var overlap = new Pair<int>(leaf.Item, otherCandidate);
          if (Filter == null || Filter.Filter(overlap))
            yield return overlap;
        }
      }
#else
      return GetOverlapsWithTransformedPartitionWork.Create(this, otherPartition, leafNodes, ref scale, ref otherScaleInverse, ref toOther);

    }