areBandAlmostOnTheSameHorizontalRow method
Determines if two bands are approximately on the same horizontal row.
This method checks if two bands should be considered part of the same horizontal line by evaluating two criteria:
- The bands must have some vertical overlap
- The vertical distance between their centers must be less than 40% of their average height
a The first band to compare
b The second band to compare
Returns true if the bands are considered to be on the same horizontal row, false otherwise.
Implementation
bool areBandAlmostOnTheSameHorizontalRow(Band a, Band b) {
// They have to at least overlap
if (a.rectangleAdjusted.intersectVertically(b.rectangleAdjusted)) {
//
// the two bands are relative on the same horizontal row
//
//
// Step 2 - How much vertically, should we consider it aligned?
//
int verticalDistance =
(a.rectangleAdjusted.center.y - b.rectangleAdjusted.center.y).abs();
int avgHeightOfBothBands =
(a.rectangleAdjusted.height + b.rectangleAdjusted.height) ~/ 2;
// The bands needs an vertical overlapping of least 50% of the average height
if (verticalDistance < avgHeightOfBothBands * 0.4) {
return true;
}
}
return false;
}