//method to override the calcuation of the movement speed and position of agent public override Vector2 CalculateMoveSpeed(Life life, List <Transform> context) { //create list of filtered agents List <Transform> filteredContext = Filter == null ? context : Filter.Filter(context, life); if (!filteredContext.Any()) { return(Vector2.zero); } Vector2 move = Vector2.zero; //for each filtered agent in list caluclate disance and move direction foreach (Transform item in filteredContext) { float distance = Vector2.Distance(item.position, life.transform.position); float disancePercent = distance / life.Characteristics.NeighborRadius; float inverseDistancePercent = 1 - disancePercent; float weight = inverseDistancePercent / filteredContext.Count; Vector2 direction = (item.position - life.transform.position) * weight; move += direction; } //return movement as direction return(move); }
//method to override the calcuation of the movement speed and position of agent public override Vector2 CalculateMoveSpeed(Life life, List <Transform> context) { if (context.Count == 0) { return(Vector2.zero); } // getting average Vector2 avoidanceMove = Vector2.zero; List <Transform> filteredContext = Filter == null ? context : Filter.Filter(context, life); int numAvoid = 0; // instead of context, using filter foreach (var item in filteredContext) { if (Vector2.Distance(item.position, life.transform.position) <= life.Characteristics.AvoidanceRadius) { numAvoid++; avoidanceMove += (Vector2)(life.transform.position - item.position); } } if (numAvoid > 0) { avoidanceMove /= numAvoid; } return(avoidanceMove); }
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); }
//method to override the calcuation of the movement speed and position of agent public override Vector2 CalculateMoveSpeed(Life life, List <Transform> context) { // if no neighbours, return no adjustment if (!context.Any()) { return(Vector2.zero); } // all add points together and average Vector2 cohesionMove = Vector2.zero; // if (filter == null) { filteredContext = context} else {filter.Filter(agent,context)} List <Transform> filteredContext = Filter == null ? context : Filter.Filter(context, life); int count = 0; // instead of context foreach (Transform item in filteredContext) { if (Vector2.Distance(item.position, life.transform.position) <= life.Characteristics.SmallRadius) { cohesionMove += (Vector2)item.position; count++; } } if (count != 0) { cohesionMove /= count; } // create offset from agent position cohesionMove -= (Vector2)life.transform.position; cohesionMove = Vector2.SmoothDamp(life.transform.up, cohesionMove, ref currentVelocity, AgentSmoothTime); return(cohesionMove); }
//method to override the calcuation of the movement speed and position of agent public override Vector2 CalculateMoveSpeed(Life life, List <Transform> context) { if (context.Count == 0) { // maintain same direction return(life.transform.up); } // add all directions together and average Vector2 alignmentMove = Vector2.zero; List <Transform> filteredContext = Filter == null ? context : Filter.Filter(context, life); int count = 0; foreach (Transform item in filteredContext) { // instead of context, using filter if (Vector2.Distance(item.position, life.transform.position) <= life.Characteristics.SmallRadius) { alignmentMove += (Vector2)item.transform.up; count++; } } if (count != 0) { alignmentMove /= context.Count; } return(alignmentMove); }
//method to override the calcuation of the movement speed and position of agent public override Vector2 CalculateMoveSpeed(Life life, List <Transform> context) { if (context.Count == 0) { return(Vector2.zero); } // add all points together and get average Vector2 cohesionMove = Vector2.zero; List <Transform> filteredContext = Filter == null ? context : Filter.Filter(context, life); int count = 0; // instead of context, using filter foreach (var item in filteredContext) { if (Vector2.Distance(item.position, life.transform.position) <= life.Characteristics.SmallRadius) { cohesionMove += (Vector2)item.position; count++; } } if (count != 0) { cohesionMove /= count; // create offset from agent position // direction from a to b = b - a cohesionMove -= (Vector2)life.transform.position; } return(cohesionMove); }
private IEnumerable <Pair <T> > GetOverlapsImpl(Vector3F scale, DynamicAabbTree <T> otherTree, Vector3F otherScale, Pose otherPose) { // Compute transformations. Vector3F scaleA = scale; // Rename scales for readability. Vector3F scaleB = otherScale; Pose bToA = otherPose; #if !POOL_ENUMERABLES var stack = DigitalRune.ResourcePools <Pair <Node, Node> > .Stacks.Obtain(); stack.Push(new Pair <Node, Node>(_root, otherTree._root)); while (stack.Count > 0) { var nodePair = stack.Pop(); var nodeA = nodePair.First; var nodeB = nodePair.Second; if (HaveAabbContact(nodeA, scaleA, nodeB, scaleB, bToA)) { if (!nodeA.IsLeaf) { if (!nodeB.IsLeaf) { stack.Push(new Pair <Node, Node>(nodeA.RightChild, nodeB.RightChild)); stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeB.RightChild)); stack.Push(new Pair <Node, Node>(nodeA.RightChild, nodeB.LeftChild)); stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeB.LeftChild)); } else { stack.Push(new Pair <Node, Node>(nodeA.RightChild, nodeB)); stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeB)); } } else { if (!nodeB.IsLeaf) { stack.Push(new Pair <Node, Node>(nodeA, nodeB.RightChild)); stack.Push(new Pair <Node, Node>(nodeA, nodeB.LeftChild)); } else { // Leaf overlap. var overlap = new Pair <T>(nodeA.Item, nodeB.Item); if (Filter == null || Filter.Filter(overlap)) { yield return(overlap); } } } } } DigitalRune.ResourcePools <Pair <Node, Node> > .Stacks.Recycle(stack); #else // Avoiding garbage: return(GetOverlapsWithTransformedTreeWork.Create(this, otherTree, ref scaleA, ref scaleB, ref bToA)); #endif }
public override string Render() { if (Filter != null && Filter.Filter(RowData)) { return(string.Empty); } var a = new TagBuilder("a"); a.AddCssClass(CssClass); a.Attributes["trButton"] = Id; a.SetInnerText(Name); if (!OnClick.IsNullOrEmpty()) { a.Attributes.Add("onclick", FormatAttribute(OnClick)); } if (!Href.IsNullOrEmpty()) { a.Attributes.Add("href", FormatAttribute(Href)); } else { a.Attributes.Add("href", "javascript:void(0);"); } a.Attributes.Add("target", "_{0}".FormatTo(Target.ToString().ToLower())); return(a.ToString()); }
/// <summary> /// This method provides the skeletonID of the skeleton perfoming the defined gesture or which should be reactivated. /// <param name="igsSkelId">SkeletonID stored in the IGS</param> /// <returns>ID of the skeleton which was marked as tracked</returns> /// </summary> public int GetSkeletonId(int igsSkelId) { if (Bodies.Any(s => s.Id == igsSkelId)) { return(igsSkelId); } if (!_bodiesLastFrame.Any(s => s.TrackingId != 0)) { return(NO_BODIES_IN_FRAME); } Bodies = Strategy.Replace(Bodies); HashSet <int> idsSeen = new HashSet <int>(); foreach (TrackedSkeleton s in Bodies) { idsSeen.Add(s.Id); } Bodies = Filter.Filter(_bodiesLastFrame, Bodies, igsSkelId, reader); //see which user was added foreach (TrackedSkeleton s in Bodies.Where(s => !idsSeen.Contains(s.Id))) { return(s.Id); } return(NO_GESTURE_FOUND); }
private void InnerFind() { Result.Clear(); queue.Clear(); var sp = Name.ToLower().Split(new char[] { ' ', ' ' }, StringSplitOptions.RemoveEmptyEntries); if (Name != string.Empty) { queue.Enqueue(SongInformation.Root); while (queue.Count > 0) { var info = queue.Dequeue(); if (info.IsPPDSong) { if (Filter.Filter(info)) { var lower = info.DirectoryName.ToLower(); if (Array.TrueForAll(sp, lower.Contains)) { Result.Add(info); } } } else { foreach (SongInformation child in info.Children) { queue.Enqueue(child); } } } } Finished = true; }
/// <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); }
public void JsonKeyContainingPhoneNumber_IsNotScrubbed() { const string json = @"{""culprit"":""SharpRaven.UnitTests.Helper in FirstLevelException"",""event_id55518231234e2400d82f11c490683c2d2"",""exception"":[],""user"": {""username"":""asbjornu""}}"; var output = Filter.Filter(json); Assert.That(output, Is.StringContaining("event_id55518231234e2400d82f11c490683c2d2")); }
private void OnCollisionStay(Collision other) { if (Filter != null && !Filter.Filter(other.collider)) { return; } EventSource?.Raise(new Collision3DStayEvent(other)); }
private void OnTriggerStay(Collider other) { if (Filter != null && !Filter.Filter(other)) { return; } EventSource?.Raise(new Trigger3DStayEvent(other)); }
// Can only add overlapping pairs. // Sort edge up and add overlapping pairs private void SortMaxEdgeUp(List<Edge> edgeList, int axisIndex, int edgeIndex) { int maxIndex = edgeList.Count - 1; if (edgeIndex == maxIndex) return; var edge = edgeList[edgeIndex]; var itemInfo = edge.Info; int nextEdgeIndex = edgeIndex + 1; var nextEdge = edgeList[nextEdgeIndex]; while (edge.Position >= nextEdge.Position) { var nextItemInfo = nextEdge.Info; if (nextEdge.IsMax == false) { // New overlapping pair! if (_broadPhase != null || EnableSelfOverlaps) { if (AreOverlapping(itemInfo, nextItemInfo, axisIndex)) { var overlap = new Pair<T>(itemInfo.Item, nextItemInfo.Item); if (Filter == null || Filter.Filter(overlap)) { if (_broadPhase != null) _broadPhase.Add(overlap); if (EnableSelfOverlaps) SelfOverlaps.Add(overlap); } } } nextItemInfo.MinEdgeIndices[axisIndex] = edgeIndex; // Min edge was swapped down. } else { nextItemInfo.MaxEdgeIndices[axisIndex] = edgeIndex; // Max edge was swapped down. } itemInfo.MaxEdgeIndices[axisIndex] = nextEdgeIndex; // Max edge was swapped up. // Swap edges in edge list. edgeList[edgeIndex] = nextEdge; edgeList[nextEdgeIndex] = edge; edgeIndex++; if (edgeIndex == maxIndex) return; nextEdgeIndex++; nextEdge = edgeList[nextEdgeIndex]; } }
/// <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 }
// Can only add overlapping pairs. // Sort edge down and add overlapping pairs. private void SortMinEdgeDown(List<Edge> edgeList, int axisIndex, int edgeIndex) { if (edgeIndex == 0) return; var edge = edgeList[edgeIndex]; var itemInfo = edge.Info; int previousEdgeIndex = edgeIndex - 1; Edge previousEdge = edgeList[previousEdgeIndex]; while (edge.Position <= previousEdge.Position) { var previousItemInfo = previousEdge.Info; if (previousEdge.IsMax) { // New overlapping pair! if (_broadPhase != null || EnableSelfOverlaps) { if (AreOverlapping(itemInfo, previousItemInfo, axisIndex)) { var overlap = new Pair<T>(itemInfo.Item, previousItemInfo.Item); if (Filter == null || Filter.Filter(overlap)) { if (_broadPhase != null) _broadPhase.Add(overlap); if (EnableSelfOverlaps) SelfOverlaps.Add(overlap); } } } previousItemInfo.MaxEdgeIndices[axisIndex] = edgeIndex; // Max edge was swapped up. } else { previousItemInfo.MinEdgeIndices[axisIndex] = edgeIndex; // Min edge was swapped up. } itemInfo.MinEdgeIndices[axisIndex] = previousEdgeIndex; // Min edge was swapped down. // Swap edges in edge list. edgeList[edgeIndex] = previousEdge; edgeList[previousEdgeIndex] = edge; edgeIndex--; if (edgeIndex == 0) return; previousEdgeIndex--; previousEdge = edgeList[previousEdgeIndex]; } }
// The entry point of comsumer-side of events, may be recursively called. public void OnEvent(Event e) { if (Status == EventManagerStatus.Paused && this.stepping && (this.stepEvent == EventType.Event || this.stepEvent == e.TypeId)) { Console.WriteLine($"{DateTime.Now} Event : {e}"); this.stepping = false; } EventCount++; // Skip when this event is disabled if (!Enabled[e.TypeId]) { return; } try { if (Filter != null && Filter.Filter(e) == null) { return; } } catch (Exception ex) { OnEvent(new OnException("EventFilter", e, ex)); } try { this.gates[e.TypeId]?.Invoke(e); } catch (Exception ex) { OnEvent(new OnException("EventHandler", e, ex)); } try { Dispatcher?.OnEvent(e); } catch (Exception ex) { OnEvent(new OnException("EventDispatcher", e, ex)); } try { Logger?.OnEvent(e); } catch (Exception ex) { OnEvent(new OnException("EventLogger", e, ex)); } }
/// <summary> /// Extracts a substring /// </summary> /// <param name="offset"></param> /// <param name="length"></param> /// <returns></returns> public String Substring(long offset, int length) { String s = InputString.Substring((int)offset, Math.Min(length, InputString.Length - (int)offset)); if (Filter != null) { s = Filter.Filter(s); } return(s); }
/// <summary> /// Checks if the pair of items is a valid self-overlap. /// </summary> /// <param name="pair">The pair of items.</param> /// <returns> /// <see langword="true"/> if the pair should be accepted; otherwise, <see langword="false"/> if /// the pair should be rejected. /// </returns> /// <remarks> /// This method returns <see langword="false"/> if the given items are identical or if the /// <see cref="Filter"/> returns <see langword="false"/>. This method does NOT check AABB /// overlaps. /// </remarks> private bool FilterSelfOverlap(Pair <int> pair) { // Check for equality. if (pair.First == pair.Second) { return(false); } // Check Filter. return(Filter == null || Filter.Filter(pair)); }
/// <summary> /// Checks if the pair of items is a valid self-overlap. /// </summary> /// <param name="pair">The pair of items.</param> /// <returns> /// <see langword="true"/> if the pair should be accepted; otherwise, <see langword="false"/> if /// the pair should be rejected. /// </returns> /// <remarks> /// This method returns <see langword="false"/> if the given items are identical or if the /// <see cref="Filter"/> returns <see langword="false"/>. This method does NOT check AABB /// overlaps. /// </remarks> internal bool FilterSelfOverlap(Pair <T> pair) { // Check for equality. if (Comparer.Equals(pair.First, pair.Second)) { return(false); } // Check Filter. return(Filter == null || Filter.Filter(pair)); }
//method for agent to find path public void FindPath(Life life, List <Transform> context) { List <Transform> filteredContext = Filter == null ? context : Filter.Filter(context, life); if (filteredContext.Count == 0) { return; } int randomPath = Random.Range(0, filteredContext.Count); path = filteredContext[randomPath].GetComponentInParent <Path>(); }
/// <inheritdoc/> internal override void OnUpdate(bool forceRebuild, HashSet <T> addedItems, HashSet <T> removedItems, HashSet <T> invalidItems) { if (EnableSelfOverlaps) { // Need to find all self-overlaps. SelfOverlaps.Clear(); // Test all items against all items. HashSet <T> .Enumerator outerEnumerator = Items.GetEnumerator(); while (outerEnumerator.MoveNext()) { T item = outerEnumerator.Current; Aabb aabb = GetAabbForItem(item); // Duplicate struct enumerator at current position. HashSet <T> .Enumerator innerEnumerator = outerEnumerator; while (innerEnumerator.MoveNext()) { T otherItem = innerEnumerator.Current; Aabb otherAabb = GetAabbForItem(otherItem); Pair <T> overlap = new Pair <T>(item, otherItem); if (Filter == null || Filter.Filter(overlap)) { if (GeometryHelper.HaveContact(aabb, otherAabb)) { SelfOverlaps.Add(overlap); } } } } // If Items is a IList<T>, which has an indexer, we can use the following code. //for (int i = 0; i < Items.Count; i++) //{ // var itemI = Items[i]; // var aabbI = GetAabbForItem(itemI); // for (int j = i + 1; j < Items.Count; j++) // { // var itemJ = Items[j]; // var aabbJ = GetAabbForItem(itemJ); // var overlap = new Pair<T>(itemI, itemJ); // if (Filter == null || Filter.Filter(overlap)) // if (GeometryHelper.HaveContact(aabbI, aabbJ)) // SelfOverlaps.Add(overlap); // } //} } }
/// <summary> /// Current character /// </summary> /// <returns>character at cursor position</returns> public char Peek() { if (AtEnd) { return('\0'); } if (Filter == null) { return(InputString[(int)Offset]); } else { return(Filter.Filter(InputString[(int)Offset])); } }
private HashSet<T> GetPossibleFilteredItemsWorker(HashSet<T> existingItems, bool applyFilter) { if (applyFilter && Filter != null) existingItems = Filter.Filter(existingItems); if (Children.Count == 0) return existingItems; HashSet<T> results = new HashSet<T>(); foreach (DBNode<T> currSubNode in Children) { foreach (T currItem in currSubNode.GetPossibleFilteredItemsWorker(existingItems, true)) results.Add(currItem); } return results; }
public void Position(ITabletReport report) { if (report.ReportID <= TabletProperties.ActiveReportID) { return; } var difference = DateTime.Now - _lastReceived; if (difference > ResetTime && _lastReceived != DateTime.MinValue) { _lastReport = null; _lastPosition = null; } if (_lastReport != null) { var pos = new Point(report.Position.X - _lastReport.Position.X, report.Position.Y - _lastReport.Position.Y); // Normalize (ratio of 1) pos.X /= TabletProperties.MaxX; pos.Y /= TabletProperties.MaxY; // Scale to tablet dimensions (mm) pos.X *= TabletProperties.Width; pos.Y *= TabletProperties.Height; // Sensitivity setting pos.X *= XSensitivity; pos.Y *= YSensitivity; // Translate by cursor position pos += GetCursorPosition(); // Filter if (Filter != null) { pos = Filter.Filter(pos); } CursorHandler.SetCursorPosition(pos); _lastPosition = pos; } _lastReport = report; _lastReceived = DateTime.Now; }
internal bool RunFilter(TestContext ctx) { if (Filter == null) { return(true); } bool enabled; var matched = Filter.Filter(ctx, out enabled); if (!matched) { enabled = !Filter.MustMatch; } return(enabled); }
//method to override the calcuation of the movement speed and position of agent public override Vector2 CalculateMoveSpeed(Life life, List <Transform> context) { // hide from list List <Transform> filteredContext = Filter == null ? context : Filter.Filter(context, life); // hide behind list List <Transform> obstacleContext = Filter == null ? context : obstaclesFilter.Filter(context, life); if (!filteredContext.Any() || !obstacleContext.Any()) { return(Vector2.zero); } // find nearest obstacle float nearestDistance = float.MaxValue; Transform nearestObstacle = null; foreach (Transform item in obstacleContext) { float distance = Vector2.Distance(item.position, life.transform.position); if (distance < nearestDistance) { nearestDistance = distance; nearestObstacle = item; } } // find best hiding spot Vector2 hidePosition = Vector2.zero; foreach (Transform item in filteredContext) { Vector2 obstacleDirection = nearestObstacle.position - item.position; obstacleDirection = obstacleDirection.normalized * hideBehindObstacleDistance; hidePosition += (Vector2)nearestObstacle.position + obstacleDirection; } hidePosition /= filteredContext.Count; // debug tool to see where AI is hiding Debug.DrawRay(hidePosition, Vector2.up * 1f); return(hidePosition - (Vector2)life.transform.position); }
/// <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); }
/// <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 }