Java Code Examples for java.awt.geom.Line2D#ptSegDist()

The following examples show how to use java.awt.geom.Line2D#ptSegDist() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddRemoveControlPointAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Adds or removes a control point on a specified location
 * @param widget the connection widget
 * @param localLocation the local location
 */
private void addRemoveControlPoint (ConnectionWidget widget, Point localLocation) {
    ArrayList<Point> list = new ArrayList<Point> (widget.getControlPoints ());
    if (!removeControlPoint (localLocation, list, deleteSensitivity)) {
        Point exPoint = null;
        int index = 0;
        for (Point elem : list) {
            if (exPoint != null) {
                Line2D l2d = new Line2D.Double (exPoint, elem);
                if (l2d.ptSegDist (localLocation) < createSensitivity) {
                    list.add (index, localLocation);
                    break;
                }
            }
            exPoint = elem;
            index++;
        }
    }
    if (routingPolicy != null)
        widget.setRoutingPolicy (routingPolicy);
    widget.setControlPoints (list, false);
}
 
Example 2
Source File: Polyline.java    From workcraft with MIT License 5 votes vote down vote up
@Override
public double getDistanceToCurve(Point2D pt) {
    double min = Double.MAX_VALUE;
    for (int i = 0; i < getSegmentCount(); i++) {
        Line2D segment = getSegment(i);
        double dist = segment.ptSegDist(pt);
        if (dist < min) {
            min = dist;
        }
    }
    return min;
}
 
Example 3
Source File: NerveDetectionWorker.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public boolean isCrossing(Polygon poly, Polygon junction, double minDist, Point[] preAlloc) {
    //Point[] nearest = nearestPoints(poly, junction, preAlloc);
    //return (nearest[0].distance(nearest[1])<=minDist);
    for (int i = 0; i < junction.npoints - 1; i++) {
        for (int j = 0; j < poly.npoints; j++) {
            double dist = Line2D.ptSegDist(junction.xpoints[i], junction.ypoints[i], junction.xpoints[i + 1], junction.ypoints[i + 1], poly.xpoints[j], poly.ypoints[j]);
            if (dist <= minDist) return true;
        }
    }
    return false;
}
 
Example 4
Source File: NerveDetectionWorkerMultiCore.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public boolean isCrossing(Polygon poly, Polygon junction, double minDist, Point[] preAlloc) {
    //Point[] nearest = nearestPoints(poly, junction, preAlloc);
    //return (nearest[0].distance(nearest[1])<=minDist);
    for (int i = 0; i < junction.npoints - 1; i++) {
        for (int j = 0; j < poly.npoints; j++) {
            double dist = Line2D.ptSegDist(junction.xpoints[i], junction.ypoints[i], junction.xpoints[i + 1], junction.ypoints[i + 1], poly.xpoints[j], poly.ypoints[j]);
            if (dist < minDist) return true;
        }
    }
    return false;
}