use of org.twak.utils.collections.ItComb in project chordatlas by twak.
the class Concarnie method findSupporting.
private Line findSupporting(Loopable<Point2d> pt, int dir) {
double totalDist = 0;
Point2d ptg = pt.get();
Loopable<Point2d> current = pt;
int count = 0;
do {
Point2d a = current.get(), b = current.move(dir).get();
if (dir < 0) {
Point2d tmp = a;
a = b;
b = tmp;
}
Line hull = new Line(a, b);
double bestDist = Double.MAX_VALUE;
Line bestLine = null;
for (Line l : new ItComb<>(in.getNear(hull.start, 0.5), in.getNear(hull.end, 0.5))) if (Anglez.dist(l.aTan2(), hull.aTan2()) < 0.2 && maxPerpDistance(l, hull) < 0.2) {
double dist = l.distance(ptg, true);
if (dist < bestDist) {
bestDist = dist;
bestLine = l;
}
}
if (bestLine != null)
return bestLine;
totalDist += hull.length();
current = current.move(dir);
} while (totalDist < 1 && count++ < 30);
return null;
}