findClosetLineVertical method
Finds a Line which is the closets to the line from the bottom.
Implementation
Line findClosetLineVertical(Line line, List<Line> allLines,
{bool fromBot = true}) {
allLines.removeWhere(
(element) => element.cornerList![0].y <= line.cornerList![1].y);
allLines.removeWhere(
(element) => element.cornerList![1].y > line.cornerList![0].y);
if (fromBot) {
allLines.removeWhere(
(element) => element.cornerList![0].x < line.cornerList![0].x);
}
if (allLines.isEmpty) return Line(text: "");
Line result = allLines.reduce((a, b) {
var ax = a.cornerList![0].x - line.cornerList![3].x;
var ay = a.cornerList![0].y - line.cornerList![3].y;
var bx = b.cornerList![0].x - line.cornerList![3].x;
var by = b.cornerList![0].y - line.cornerList![3].y;
return (ax * ax * 4 + ay * ay < bx * bx * 4 + by * by) ? a : b;
});
return result;
}