expandToQueue method

void expandToQueue(
  1. PriorityQueue priQ,
  2. double minDistance
)

For a pair which is not a leaf (i.e. has at least one composite boundable) computes a list of new pairs from the expansion of the larger boundable with distance less than minDistance and adds them to a priority queue.

Note that expanded pairs may contain the same item/node on both sides. This must be allowed to support distance functions which have non-zero distances between the item and itself (non-zero reflexive distance).

@param priQ the priority queue to add the new pairs to @param minDistance the limit on the distance between added pairs

Implementation

void expandToQueue(PriorityQueue priQ, double minDistance) {
  bool isComp1 = isComposite(boundable1);
  bool isComp2 = isComposite(boundable2);

  /**
   * HEURISTIC: If both boundable are composite,
   * choose the one with largest area to expand.
   * Otherwise, simply expand whichever is composite.
   */
  if (isComp1 && isComp2) {
    if (area(boundable1) > area(boundable2)) {
      expand(boundable1, boundable2, false, priQ, minDistance);
      return;
    } else {
      expand(boundable2, boundable1, true, priQ, minDistance);
      return;
    }
  } else if (isComp1) {
    expand(boundable1, boundable2, false, priQ, minDistance);
    return;
  } else if (isComp2) {
    expand(boundable2, boundable1, true, priQ, minDistance);
    return;
  }

  throw new ArgumentError("neither boundable is composite");
}