public static String toString(Line2D line) { // return line.getP1() + "-" + line.getP2(); return toString(line.getP1()) + "-" + toString(line.getP2()); }
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; } }
public Point2D getFinalPoint() { finalPoint = new Point2D.Double(); finalPoint.setLocation(pathSegments.get(pathSegments.size() - 1).getP2()); return finalPoint; } }
Line2D line1 = new Line2D.Double(x1, y1, x2, y2); HashMap<String, Integer> hashMap = new HashMap<>(); String keyToGetOrPut = line1.getP1().getX() + "" + line1.getP1().getY() + "" + line1.getP2().getX() + "" + line1.getP2().getY(); if(hashMap.get(keyToGetOrPut) != null){ hashMap.put(keyToGetOrPut, hashMap.get(keyToGet)+1); //increment by 1 if points is already in the HashMap } else { hashMap.put(keyToGetOrPut, 1); //put a new record to the HashMap }
/** * Returns: * 0 if it is not the same segment, i.e !equal AND !inverted * 1 if it is equal, i.e. pa0.equals(pb0) && pa1.equals(pb1) * 2 if it is inverted, i.e. pa0.equals(pb1) && pa1.equals(pb0) * @return */ public static int sameSegment(Line2D lineA, Line2D lineB) { return sameSegment(lineA.getP1(), lineA.getP2(), lineB.getP1(), lineB.getP2()); }
/** * Report the baseline defined by the provided sequence of items. * * @param items provided sequence * @return baseline from first to last */ public static Line2D baselineOf (List<? extends TextBasedItem> items) { Point2D first = items.get(0).getBaseline().getP1(); Point2D last = items.get(items.size() - 1).getBaseline().getP2(); return new Line2D.Double(first, last); }
/** * Return the bisector (French: médiatrice) of the provided segment * * @param segment the provided segment * @return (a segment on) the bisector */ public static Line2D bisector (Line2D segment) { return bisector(segment.getP1(), segment.getP2()); }
/** * Report the theoretical black area for the beam item * * @return parallelogram for black pixels */ public Area getCoreArea () { return AreaUtil.horizontalParallelogram(median.getP1(), median.getP2(), height); }
/** * Returns: * 0 if it is not the same segment, i.e !equal AND !inverted * 1 if it is equal, i.e. pa0.equals(pb0) && pa1.equals(pb1) * 2 if it is inverted, i.e. pa0.equals(pb1) && pa1.equals(pb0) * @return */ public static int sameSegment(Line2D line,Point2D pb0, Point2D pb1) { return sameSegment(line.getP1(), line.getP2(), pb0, pb1); }
protected Double getPerimeter(List<Line2D.Double> lineSegmentList) { if (lineSegmentList != null) { double perimeter = 0.0; for (Line2D line : lineSegmentList) { perimeter += line.getP1().distance(line.getP2()); } return perimeter; } return null; }
public static Point2D.Double getPerpendicularPointToLine(Line2D line, Point2D ptC) { if (line == null || ptC == null) { return null; } return getPerpendicularPointToLine(line.getP1(), line.getP2(), ptC); }
protected void updateContactPoints() { Line2D connectionPoints = getConnectionPoints(); contactPoints = new Point2D[]{ connectionPoints.getP1(), connectionPoints.getP2() }; }
Line2DFacade (Line2D line) { Objects.requireNonNull(line, "Cannot create Line2DFacade with a null line"); p1 = new Point2DFacade(line.getP1()); p2 = new Point2DFacade(line.getP2()); }
public static double getAngle2D(Line2D line, Point2D point) { // * p1 // / // / // / // *------>* // (0,0) this return AlgoPoint2D.getAngle2D(AlgoPoint2D.subtract(line.getP2(),line.getP1()), point); } }
public static String toString(Line2D line) { // return line.getP1() + "-" + line.getP2(); return toString(line.getP1()) + "-" + toString(line.getP2()); }
@Override public Point2D getEndVector (boolean reverse) { int dir = reverse ? (-1) : 1; Line2D l = line.toDouble(); double length = l.getP1().distance(l.getP2()); return new Point2D.Double( (dir * (l.getX2() - l.getX1())) / length, (dir * (l.getY2() - l.getY1())) / length); }
public static double orientation(Line2D line,Point2D point) { //(ZA)21.12.04 returns a Value about a Curve-Orientation (clockwise or counterclockwise) return AlgoPoint2D.cross((AlgoPoint2D.subtract(point,line.getP1())), AlgoPoint2D.subtract((line.getP2()),line.getP1())); } /**
/** * */ protected void computeArea () { setArea(AreaUtil.horizontalParallelogram(median.getP1(), median.getP2(), height)); // Define precise bounds based on this path setBounds(getArea().getBounds()); }
/** * Compute bisector vector. * * @param above is the slur above (or below) * @return the unit bisector */ protected Point2D.Double computeBisector (boolean above) { Line2D bisector = LineUtil.bisector(getEnd(above), getEnd(!above)); double length = bisector.getP1().distance(bisector.getP2()); return new Point2D.Double( (bisector.getX2() - bisector.getX1()) / length, (bisector.getY2() - bisector.getY1()) / length); }