final double getMindist(Point2D.Double pt) { double result = Double.MAX_VALUE; for (Point2D p : points.keySet()) { if (pt.equals(p)) { continue; } final double v = p.distance(pt); if (v < 1E-4) { throw new IllegalStateException(); } result = Math.min(result, v); } for (Line2D line : lines) { if (line.getP1().equals(pt) || line.getP2().equals(pt)) { continue; } final double v = line.ptSegDist(pt); if (result < 1E-4) { throw new IllegalStateException("pt=" + pt + " line=" + GeomUtils.toString(line)); } result = Math.min(result, v); } if (result == 0) { throw new IllegalStateException(); } // Log.println("getMindist=" + result); return result; } }
@Override public boolean contains(int x, int y) { return line.ptSegDist(x, y) <= LINE_SELECTION_WIDTH; }
public int getIndexOfClosestSegment(Point2D aPoint) { int indexOfClosestSegment = 0; double minMatric = Double.MAX_VALUE; double curMatric = minMatric; for (int i = 0; i < pathSegments.size(); i++) { curMatric = pathSegments.get(i).ptSegDist(aPoint); if (curMatric < minMatric) { minMatric = curMatric; indexOfClosestSegment = i; } } return indexOfClosestSegment; }
/** * @see prefuse.util.force.Force#getForce(prefuse.util.force.ForceItem) */ public void getForce(ForceItem item) { float[] n = item.location; int ccw = Line2D.relativeCCW(x1,y1,x2,y2,n[0],n[1]); float r = (float)Line2D.ptSegDist(x1,y1,x2,y2,n[0],n[1]); if ( r == 0.0 ) r = (float)Math.random() / 100.0f; float v = params[GRAVITATIONAL_CONST]*item.mass / (r*r*r); if ( n[0] >= Math.min(x1,x2) && n[0] <= Math.max(x1,x2) ) item.force[1] += ccw*v*dx; if ( n[1] >= Math.min(y1,y2) && n[1] <= Math.max(y1,y2) ) item.force[0] += -1*ccw*v*dy; }
/** * 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); }
if (lineToTest.ptSegDist(this.newTransitionPointLocation) <= MAX_DIST)
final double getMindist(Point2D.Double pt) { double result = Double.MAX_VALUE; for (Point2D p : points.keySet()) { if (pt.equals(p)) { continue; } final double v = p.distance(pt); if (v < 1E-4) { throw new IllegalStateException(); } result = Math.min(result, v); } for (Line2D line : lines) { if (line.getP1().equals(pt) || line.getP2().equals(pt)) { continue; } final double v = line.ptSegDist(pt); if (result < 1E-4) { throw new IllegalStateException("pt=" + pt + " line=" + GeomUtils.toString(line)); } result = Math.min(result, v); } if (result == 0) { throw new IllegalStateException(); } // Log.println("getMindist=" + result); return result; } }
/** * Build proper SlurHeadRelation object. * * @param slurEnd slur ending point * @param slurSide slur horizontal side * @param chord head chord * @param head head to be connected * @return proper SlurHeadRelation instance, ready to be inserted in SIG */ public static SlurHeadLink create (Point slurEnd, HorizontalSide slurSide, AbstractChordInter chord, HeadInter head) { SlurHeadRelation rel = new SlurHeadRelation(slurSide); // Define middle vertical line of chord box Rectangle box = chord.getBounds(); Line2D vert = new Line2D.Double(box.x + (box.width / 2), box.y, box.x + (box.width / 2), box.y + box.height); rel.setEuclidean(vert.ptSegDist(slurEnd)); return new SlurHeadLink(head, rel); } }
double distance = line.ptSegDist(mp); if (distance <= 4) { offset = new Rectangle(mp, new Dimension(1, 1));
double dist = line.ptSegDist(x, y);
private Point2D getLocationOfClosestPointOnSegment(int indexOfSegment, Point2D aPoint) { Point2D ret = new Point2D.Double(); Line2D aSegment = pathSegments.get(indexOfSegment); double paramA = aSegment.getY2() - aSegment.getY1(); double paramB = -aSegment.getX2() + aSegment.getX1(); double paramC = -aSegment.getX1() * aSegment.getY2() + aSegment.getX2() * aSegment.getY1(); ret.setLocation((paramB * (paramB * aPoint.getX() - paramA * aPoint.getY()) - paramA * paramC) / (paramA * paramA + paramB * paramB), (paramA * (-paramB * aPoint.getX() + paramA * aPoint.getY()) - paramB * paramC) / (paramA * paramA + paramB * paramB)); if (aSegment.ptSegDist(ret) > 0.0001) { if (aSegment.getP1().distance(ret) > aSegment.getP2().distance(ret)) { ret = aSegment.getP2(); } else { ret = aSegment.getP1(); } } return ret; }
double d2 = stem.getMedian().ptSegDist(refPt);