java.awt.geom.Line2D#ptSegDist ( )源码实例Demo

下面列出了java.awt.geom.Line2D#ptSegDist ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: AddRemoveControlPointAction.java
/**
 * 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);
}
 
源代码2 项目: workcraft   文件: Polyline.java
@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;
}
 
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;
}
 
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;
}