sortMatrices static method

void sortMatrices(
  1. List<Artifact> list
)

Sorts a list of Artifact objects based on their vertical and horizontal positions.

This method first compares the vertical center positions of artifacts. If two artifacts are approximately on the same line (within 10 pixels vertically), it sorts them from left to right based on their horizontal position. Otherwise, it sorts them from top to bottom.

Parameters: list: The list of Artifact objects to sort.

Implementation

static void sortMatrices(List<Artifact> list) {
  list.sort((Artifact a, Artifact b) {
    final aCenterY = a.rectFound.top + a.rectFound.height / 2;
    final bCenterY = b.rectFound.top + b.rectFound.height / 2;
    if ((aCenterY - bCenterY).abs() < 10) {
      return a.rectFound.left.compareTo(b.rectFound.left);
    }
    return aCenterY.compareTo(bCenterY);
  });
}