isInTheSameLine method
Same line Check! //So important and useful strictness can be hard or medium //the first is more accurate and second one is more sensitive
Implementation
bool isInTheSameLine(Line l1, Line l2, Strictness strictness) {
bool isInSameLines = true;
//this is more accurate
if (strictness == Strictness.hard) {
var i1 = (l1.cornerList![0].x + l1.cornerList![2].x) / 2;
var i2 = (l2.cornerList![0].x + l2.cornerList![2].x) / 2;
if (i1 < l2.cornerList![0].x ||
i1 > l2.cornerList![2].x ||
i2 < l1.cornerList![0].x ||
i2 > l1.cornerList![2].x) isInSameLines = false;
} else if (l1.cornerList![0].x >
l2.cornerList![2].x -
10 || //strictness == Strictness.medium, more sensitive
l1.cornerList![2].x < l2.cornerList![0].x + 10) {
//this is the first and the most important layer of filter
isInSameLines = false;
}
if (l1.cornerList![0].y < l2.cornerList![2].y &&
l1.cornerList![2].y > l2.cornerList![0].y) {
//if they have any horizontal sharing in space they must not be in the same line
isInSameLines = false;
}
if ((l1.cornerList![2].x - l1.cornerList![0].x) >
3 * (l2.cornerList![2].x - l2.cornerList![0].x) ||
(l2.cornerList![2].x - l2.cornerList![0].x) >
3 * (l1.cornerList![2].x - l1.cornerList![0].x)) {
//sometimes a really big font is near a small font which doesn't mean they meant to be in the same line
isInSameLines = false;
}
return isInSameLines;
}