((XYNode) node3).getCoordinate().y); Point2D.Double point2D = new Point2D.Double(n.getCoordinate().x, n.getCoordinate().y); if ((line12.ptSegDist(point2D) <= TOLERANCE) || (line13.ptSegDist(point2D) <= TOLERANCE) || (line23.ptSegDist(point2D) <= TOLERANCE)) { ret = ON_EDGE; } else if (poly.contains(nPoint)) {
private void getPaintedPixel(Line2D.Double line, double lineWidth) { // get the corner coordinates of the line shape bound Rectangle2D bound2D = line.getBounds2D(); double yTop = bound2D.getY() - lineWidth; double yBottom = bound2D.getY() + bound2D.getHeight() + lineWidth; double xLeft = bound2D.getX() - lineWidth; double xRight = bound2D.getX() + bound2D.getWidth() + lineWidth; // iterate over every single pixel in the line shape bound for (double y = yTop; y < yBottom; y++) { for (double x = xLeft; x < xRight; x++) { // calculate the distance between a particular pixel and the // painted line double distanceToLine = line.ptSegDist(x, y); // if the distance between line and pixel is less then the half // of the line width, it means, that the pixel is a part of the // line if (distanceToLine < lineWidth / 2) { // pixel belongs to the line } } } }
((XYNode) node3).getCoordinate().y); Point2D.Double point2D = new Point2D.Double(n.getCoordinate().x, n.getCoordinate().y); if ((line12.ptSegDist(point2D) <= TOLERANCE) || (line13.ptSegDist(point2D) <= TOLERANCE) || (line23.ptSegDist(point2D) <= TOLERANCE)) { ret = ON_EDGE; } else if (poly.contains(nPoint)) {
public DiagramGraph getClosestGraph(int x, int y) { double minDist = Double.MAX_VALUE; Point2D.Double a = new Point2D.Double(); Point2D.Double b1 = new Point2D.Double(); Point2D.Double b2 = new Point2D.Double(); DiagramGraph closestGraph = null; for (DiagramGraph graph : getGraphs()) { double minDistGraph = Double.MAX_VALUE; int n = graph.getNumValues(); for (int i = 0; i < n; i++) { a.setLocation(graph.getXValueAt(i), graph.getYValueAt(i)); b1.setLocation(b2); transform.transformA2B(a, b2); if (i > 0) { Line2D.Double segment = new Line2D.Double(b1, b2); double v = segment.ptSegDist(x, y); if (v < minDistGraph) { minDistGraph = v; } } } if (minDistGraph < minDist) { minDist = minDistGraph; closestGraph = graph; } } return closestGraph; }
public DiagramGraph getClosestGraph(int x, int y) { double minDist = Double.MAX_VALUE; Point2D.Double a = new Point2D.Double(); Point2D.Double b1 = new Point2D.Double(); Point2D.Double b2 = new Point2D.Double(); DiagramGraph closestGraph = null; for (DiagramGraph graph : getGraphs()) { double minDistGraph = Double.MAX_VALUE; int n = graph.getNumValues(); for (int i = 0; i < n; i++) { a.setLocation(graph.getXValueAt(i), graph.getYValueAt(i)); b1.setLocation(b2); transform.transformA2B(a, b2); if (i > 0) { Line2D.Double segment = new Line2D.Double(b1, b2); double v = segment.ptSegDist(x, y); if (v < minDistGraph) { minDistGraph = v; } } } if (minDistGraph < minDist) { minDist = minDistGraph; closestGraph = graph; } } return closestGraph; }
private double getRadius() { final double[] COORDINATES = new double[6]; final Point2D.Double P = new Point2D.Double(); double minDistance = Double.MAX_VALUE; final double FLATNESS = 0.005; final java.awt.geom.PathIterator PATH_ITERATOR = ELLIPSE.getPathIterator(null, FLATNESS); while (!PATH_ITERATOR.isDone()) { int segment = PATH_ITERATOR.currentSegment(COORDINATES); switch (segment) { case java.awt.geom.PathIterator.SEG_CLOSE: case java.awt.geom.PathIterator.SEG_MOVETO: case java.awt.geom.PathIterator.SEG_LINETO: break; default: break; } final double DISTANCE = LINE.ptSegDist(COORDINATES[0], COORDINATES[1]); if (DISTANCE < minDistance) { minDistance = DISTANCE; P.x = COORDINATES[0]; P.y = COORDINATES[1]; } PATH_ITERATOR.next(); } return CENTER.distance(P); } }
private double getRadius() { final double[] COORDINATES = new double[6]; final Point2D.Double P = new Point2D.Double(); double minDistance = Double.MAX_VALUE; final double FLATNESS = 0.005; final java.awt.geom.PathIterator PATH_ITERATOR = ELLIPSE.getPathIterator(null, FLATNESS); while (!PATH_ITERATOR.isDone()) { int segment = PATH_ITERATOR.currentSegment(COORDINATES); switch (segment) { case java.awt.geom.PathIterator.SEG_CLOSE: case java.awt.geom.PathIterator.SEG_MOVETO: case java.awt.geom.PathIterator.SEG_LINETO: break; default: break; } final double DISTANCE = LINE.ptSegDist(COORDINATES[0], COORDINATES[1]); if (DISTANCE < minDistance) { minDistance = DISTANCE; P.x = COORDINATES[0]; P.y = COORDINATES[1]; } PATH_ITERATOR.next(); } return CENTER.distance(P); } }