/// <summary> /// Synchronizes the contact set collections with self-overlaps in the spatial partition. /// </summary> private void Synchronize() { var overlaps = SpatialPartition.GetOverlaps(); // We know that SAP uses a HashSet. If possible use a HashSet in foreach to // avoid allocating an enumerator on the heap. var overlapsHashSet = overlaps as HashSet <Pair <CollisionObject> >; if (overlapsHashSet != null) { // Use struct Enumerator of HashSet. foreach (var overlap in overlapsHashSet) { CandidatePairs.AddOrMarkAsUsed(overlap); } } else { // Use IEnumerator<T>. foreach (var overlap in overlaps) { CandidatePairs.AddOrMarkAsUsed(overlap); } } CandidatePairs.RemoveUnused(_obsoleteContactSetList); Debug.Assert(overlaps.Count() == CandidatePairs.Count); }
void IBroadPhase <CollisionObject> .RemoveUnused() { CandidatePairs.RemoveUnused(_obsoleteContactSetList); }