sortVerticallyThenHorizontally static method
Sorts a list of bands vertically then horizontally with a threshold for vertical alignment.
list The list of bands to sort.
threshold The vertical threshold (in pixels) within which bands are considered to be on the same line.
Implementation
static void sortVerticallyThenHorizontally(
List<Band> list, {
double threshold = 5.0,
}) {
list.sort((a, b) {
// If the vertical difference is within the threshold, treat them as the same row
if ((a.rectangleOriginal.center.y - b.rectangleOriginal.center.y).abs() <=
threshold) {
return a.rectangleOriginal.center.x.compareTo(
b.rectangleOriginal.center.x,
); // Sort by X-axis if on the same line
}
return a.rectangleOriginal.center.y.compareTo(
b.rectangleOriginal.center.y,
); // Otherwise, sort by Y-axis
});
}