run method

void run()

Run collision detection for the current state of items.

Implementation

void run() {
  broadphase.update();
  final potentials = broadphase.query();
  final hashes = Set.unmodifiable(potentials.map((p) => p.hash));

  for (final potential in potentials) {
    final itemA = potential.a;
    final itemB = potential.b;

    if (itemA.possiblyIntersects(itemB)) {
      final intersectionPoints = intersections(itemA, itemB);
      if (intersectionPoints.isNotEmpty) {
        if (!itemA.collidingWith(itemB)) {
          handleCollisionStart(intersectionPoints, itemA, itemB);
        }
        handleCollision(intersectionPoints, itemA, itemB);
      } else if (itemA.collidingWith(itemB)) {
        handleCollisionEnd(itemA, itemB);
      }
    } else if (itemA.collidingWith(itemB)) {
      handleCollisionEnd(itemA, itemB);
    }
  }

  // Handles callbacks for an ended collision that the broadphase didn't
  // report as a potential collision anymore.
  for (final prospect in _lastPotentials) {
    if (!hashes.contains(prospect.hash) &&
        prospect.a.collidingWith(prospect.b)) {
      handleCollisionEnd(prospect.a, prospect.b);
    }
  }
  _updateLastPotentials(potentials);

  // Let all listeners know that the collision detection step has completed
  collisionsCompletedNotifier.notifyListeners();
}