Search in sources :

Example 1 with ItComb

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;
}
Also used : Line(org.twak.utils.Line) Point2d(javax.vecmath.Point2d) ItComb(org.twak.utils.collections.ItComb) Paint(java.awt.Paint)

Aggregations

Paint (java.awt.Paint)1 Point2d (javax.vecmath.Point2d)1 Line (org.twak.utils.Line)1 ItComb (org.twak.utils.collections.ItComb)1