Java Code Examples for java.awt.geom.Line2D#ptSegDistSq()
The following examples show how to use
java.awt.geom.Line2D#ptSegDistSq() .
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: MultiConnectionWidget.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public boolean isHitAt(Point localLocation) { if (!super.isHitAt(localLocation)) { return false; } for (Route r : routeList) { double dist = Line2D.ptSegDistSq((double) r.from.x, (double) r.from.y, (double) r.to.x, (double) r.to.y, (double) localLocation.x, (double) localLocation.y); if (dist < BORDER * BORDER) { setHoverPosition(localLocation); return true; } } return false; }
Example 2
Source File: MultiConnectionWidget.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public boolean isHitAt(Point localLocation) { if (!super.isHitAt(localLocation)) { return false; } for (Route r : routeList) { double dist = Line2D.ptSegDistSq((double) r.from.x, (double) r.from.y, (double) r.to.x, (double) r.to.y, (double) localLocation.x, (double) localLocation.y); if (dist < BORDER * BORDER) { setHoverPosition(localLocation); return true; } } return false; }
Example 3
Source File: MultiConnectionWidget.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public boolean isHitAt(Point localLocation) { if (!super.isHitAt(localLocation)) { return false; } for (Route r : routeList) { double dist = Line2D.ptSegDistSq((double) r.from.x, (double) r.from.y, (double) r.to.x, (double) r.to.y, (double) localLocation.x, (double) localLocation.y); if (dist < BORDER * BORDER) { setHoverPosition(localLocation); return true; } } return false; }
Example 4
Source File: ConnectionWidget.java From netbeans with Apache License 2.0 | 6 votes |
/** * Returns whether a specified local location is a part of the connection widget. It checks whether the location is * close to the control-points-based path (up to 4px from the line), * close to the anchors (defined by AnchorShape) or * close to the control points (PointShape). * @param localLocation the local locaytion * @return true, if the location is a part of the connection widget */ public boolean isHitAt (Point localLocation) { if (! super.isHitAt (localLocation)) return false; List<Point> controlPoints = getControlPoints (); for (int i = 0; i < controlPoints.size () - 1; i++) { Point point1 = controlPoints.get (i); Point point2 = controlPoints.get (i + 1); double dist = Line2D.ptSegDistSq (point1.x, point1.y, point2.x, point2.y, localLocation.x, localLocation.y); if (dist < HIT_DISTANCE_SQUARE) return true; } return getControlPointHitAt (localLocation) >= 0; }
Example 5
Source File: MultiConnectionWidget.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override public boolean isHitAt(Point localLocation) { if (!super.isHitAt(localLocation)) { return false; } for (Route r : routeList) { double dist = Line2D.ptSegDistSq((double) r.from.x, (double) r.from.y, (double) r.to.x, (double) r.to.y, (double) localLocation.x, (double) localLocation.y); if (dist < BORDER * BORDER) { setHoverPosition(localLocation); return true; } } return false; }
Example 6
Source File: MultiConnectionWidget.java From hottub with GNU General Public License v2.0 | 6 votes |
@Override public boolean isHitAt(Point localLocation) { if (!super.isHitAt(localLocation)) { return false; } for (Route r : routeList) { double dist = Line2D.ptSegDistSq((double) r.from.x, (double) r.from.y, (double) r.to.x, (double) r.to.y, (double) localLocation.x, (double) localLocation.y); if (dist < BORDER * BORDER) { setHoverPosition(localLocation); return true; } } return false; }
Example 7
Source File: MultiConnectionWidget.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
@Override public boolean isHitAt(Point localLocation) { if (!super.isHitAt(localLocation)) { return false; } for (Route r : routeList) { double dist = Line2D.ptSegDistSq((double) r.from.x, (double) r.from.y, (double) r.to.x, (double) r.to.y, (double) localLocation.x, (double) localLocation.y); if (dist < BORDER * BORDER) { setHoverPosition(localLocation); return true; } } return false; }
Example 8
Source File: MultiConnectionWidget.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@Override public boolean isHitAt(Point localLocation) { if (!super.isHitAt(localLocation)) { return false; } for (Route r : routeList) { double dist = Line2D.ptSegDistSq((double) r.from.x, (double) r.from.y, (double) r.to.x, (double) r.to.y, (double) localLocation.x, (double) localLocation.y); if (dist < BORDER * BORDER) { setHoverPosition(localLocation); return true; } } return false; }
Example 9
Source File: mxOrganicLayout.java From consulo with Apache License 2.0 | 6 votes |
/** * This method calculates the energy of the distance between Cells and * Edges. This version of the edge distance cost calculates the energy * cost from a specified <strong>edge</strong>. The distance cost to all * unconnected nodes is calculated and the total returned. * * @param i the index of the edge in the array <code>e</code> * @return the total edge distance energy of the edge */ protected double getEdgeDistanceFromEdge(int i) { double energy = 0.0; // This function is only performed during fine tuning for performance if (isOptimizeEdgeDistance && isFineTuning) { for (int j = 0; j < v.length; j++) { // Don't calculate for connected nodes if (e[i].source != j && e[i].target != j) { double distSquare = Line2D.ptSegDistSq(v[e[i].source].x, v[e[i].source].y, v[e[i].target].x, v[e[i].target].y, v[j].x, v[j].y); distSquare -= v[j].radiusSquared; // prevents from dividing with Zero. No Math.abs() call // for performance if (distSquare < minDistanceLimitSquared) distSquare = minDistanceLimitSquared; // Only bother with the divide if the node and edge are // fairly close together if (distSquare < maxDistanceLimitSquared) { energy += edgeDistanceCostFactor / distSquare; } } } } return energy; }
Example 10
Source File: mxOrganicLayout.java From blog-codes with Apache License 2.0 | 5 votes |
/** * This method calculates the energy of the distance between Cells and * Edges. This version of the edge distance cost calculates the energy * cost from a specified <strong>node</strong>. The distance cost to all * unconnected edges is calculated and the total returned. * * @param i the index of the node in the array <code>v</code> * @return the total edge distance energy of the node */ protected double getEdgeDistanceFromNode(int i) { double energy = 0.0; // This function is only performed during fine tuning for performance if (isOptimizeEdgeDistance && isFineTuning) { int[] edges = v[i].relevantEdges; for (int j = 0; j < edges.length; j++) { // Note that the distance value is squared double distSquare = Line2D.ptSegDistSq(v[e[edges[j]].source].x, v[e[edges[j]].source].y, v[e[edges[j]].target].x, v[e[edges[j]].target].y, v[i].x, v[i].y); distSquare -= v[i].radiusSquared; // prevents from dividing with Zero. No Math.abs() call // for performance if (distSquare < minDistanceLimitSquared) { distSquare = minDistanceLimitSquared; } // Only bother with the divide if the node and edge are // fairly close together if (distSquare < maxDistanceLimitSquared) { energy += edgeDistanceCostFactor / distSquare; } } } return energy; }
Example 11
Source File: mxOrganicLayout.java From blog-codes with Apache License 2.0 | 5 votes |
/** * This method calculates the energy of the distance between Cells and * Edges. This version of the edge distance cost calculates the energy * cost from a specified <strong>edge</strong>. The distance cost to all * unconnected nodes is calculated and the total returned. * * @param i the index of the edge in the array <code>e</code> * @return the total edge distance energy of the edge */ protected double getEdgeDistanceFromEdge(int i) { double energy = 0.0; // This function is only performed during fine tuning for performance if (isOptimizeEdgeDistance && isFineTuning) { for (int j = 0; j < v.length; j++) { // Don't calculate for connected nodes if (e[i].source != j && e[i].target != j) { double distSquare = Line2D.ptSegDistSq(v[e[i].source].x, v[e[i].source].y, v[e[i].target].x, v[e[i].target].y, v[j].x, v[j].y); distSquare -= v[j].radiusSquared; // prevents from dividing with Zero. No Math.abs() call // for performance if (distSquare < minDistanceLimitSquared) distSquare = minDistanceLimitSquared; // Only bother with the divide if the node and edge are // fairly close together if (distSquare < maxDistanceLimitSquared) { energy += edgeDistanceCostFactor / distSquare; } } } } return energy; }
Example 12
Source File: mxOrganicLayout.java From consulo with Apache License 2.0 | 5 votes |
/** * This method calculates the energy of the distance between Cells and * Edges. This version of the edge distance cost calculates the energy * cost from a specified <strong>node</strong>. The distance cost to all * unconnected edges is calculated and the total returned. * * @param i the index of the node in the array <code>v</code> * @return the total edge distance energy of the node */ protected double getEdgeDistanceFromNode(int i) { double energy = 0.0; // This function is only performed during fine tuning for performance if (isOptimizeEdgeDistance && isFineTuning) { int[] edges = v[i].relevantEdges; for (int j = 0; j < edges.length; j++) { // Note that the distance value is squared double distSquare = Line2D .ptSegDistSq(v[e[edges[j]].source].x, v[e[edges[j]].source].y, v[e[edges[j]].target].x, v[e[edges[j]].target].y, v[i].x, v[i].y); distSquare -= v[i].radiusSquared; // prevents from dividing with Zero. No Math.abs() call // for performance if (distSquare < minDistanceLimitSquared) { distSquare = minDistanceLimitSquared; } // Only bother with the divide if the node and edge are // fairly close together if (distSquare < maxDistanceLimitSquared) { energy += edgeDistanceCostFactor / distSquare; } } } return energy; }
Example 13
Source File: Test7047069.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static double getFlatnessSq(float coords[], int offset) { return Line2D.ptSegDistSq(coords[offset + 0], coords[offset + 1], coords[offset + 4], coords[offset + 5], coords[offset + 2], coords[offset + 3]); }
Example 14
Source File: mxGraphView.java From consulo with Apache License 2.0 | 4 votes |
/** * Gets the relative point that describes the given, absolute label * position for the given edge state. */ public mxPoint getRelativePoint(mxCellState edgeState, double x, double y) { mxIGraphModel model = graph.getModel(); mxGeometry geometry = model.getGeometry(edgeState.getCell()); if (geometry != null) { int pointCount = edgeState.getAbsolutePointCount(); if (geometry.isRelative() && pointCount > 1) { double totalLength = edgeState.getLength(); double[] segments = edgeState.getSegments(); // Works which line segment the point of the label is closest to mxPoint p0 = edgeState.getAbsolutePoint(0); mxPoint pe = edgeState.getAbsolutePoint(1); Line2D line = new Line2D.Double(p0.getPoint(), pe.getPoint()); double minDist = line.ptSegDistSq(x, y); int index = 0; double tmp = 0; double length = 0; for (int i = 2; i < pointCount; i++) { tmp += segments[i - 2]; pe = edgeState.getAbsolutePoint(i); line = new Line2D.Double(p0.getPoint(), pe.getPoint()); double dist = line.ptSegDistSq(x, y); if (dist < minDist) { minDist = dist; index = i - 1; length = tmp; } p0 = pe; } double seg = segments[index]; p0 = edgeState.getAbsolutePoint(index); pe = edgeState.getAbsolutePoint(index + 1); double x2 = p0.getX(); double y2 = p0.getY(); double x1 = pe.getX(); double y1 = pe.getY(); double px = x; double py = y; double xSegment = x2 - x1; double ySegment = y2 - y1; px -= x1; py -= y1; double projlenSq = 0; px = xSegment - px; py = ySegment - py; double dotprod = px * xSegment + py * ySegment; if (dotprod <= 0.0) { projlenSq = 0; } else { projlenSq = dotprod * dotprod / (xSegment * xSegment + ySegment * ySegment); } double projlen = Math.sqrt(projlenSq); if (projlen > seg) { projlen = seg; } double yDistance = Line2D.ptLineDist(p0.getX(), p0.getY(), pe.getX(), pe.getY(), x, y); int direction = Line2D.relativeCCW(p0.getX(), p0.getY(), pe.getX(), pe.getY(), x, y); if (direction == -1) { yDistance = -yDistance; } // Constructs the relative point for the label return new mxPoint(Math.round(((totalLength / 2 - length - projlen) / totalLength) * -2), Math.round(yDistance / scale)); } } return new mxPoint(); }