makePairsUnique method

void makePairsUnique(
  1. List<Body> pairs1,
  2. List<Body> pairs2
)

Removes duplicate pairs from the pair arrays.

Implementation

void makePairsUnique(List<Body> pairs1,List<Body> pairs2) {
  final t = _broadphaseMakePairsUniqueTemp;
  final p1 = _broadphaseMakePairsUniqueP1;
  final p2 = _broadphaseMakePairsUniqueP2;
  final N = pairs1.length;

  for (int i = 0; i != N; i++) {
    p1[i] = pairs1[i];
    p2[i] = pairs2[i];
  }

  pairs1.clear();
  pairs2.clear();

  for (int i = 0; i != N; i++) {
    final id1 = p1[i].id;
    final id2 = p2[i].id;
    final key = id1 < id2 ? '$id1,$id2' : '$id2,$id1';
    t[key] = i;
    //t.keys.add(key);
  }

  for (int i = 0; i != t.keys.length; i++) {
    final key = t.keys;
    final pairIndex = t[key];
    pairs1.add(p1[pairIndex]);
    pairs2.add(p2[pairIndex]);
    t.remove(key);//delete t[key];
  }
}