@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Edge other = (Edge) obj; if (end == null) { if (other.end != null) { return false; } } else if (!end.equals(other.end)) { return false; } if (start == null) { if (other.start != null) { return false; } } else if (!start.equals(other.start)) { return false; } return true; }
public void findEdge(List dirEdgeList) { /** * Check all forward DirectedEdges only. This is still general, because each edge has a forward * DirectedEdge. */ for (Iterator i = dirEdgeList.iterator(); i.hasNext(); ) { DirectedEdge de = (DirectedEdge) i.next(); if (!de.isForward()) continue; checkForRightmostCoordinate(de); } /** * If the rightmost point is a node, we need to identify which of the incident edges is * rightmost. */ Assert.isTrue( minIndex != 0 || minCoord.equals(minDe.getCoordinate()), "inconsistency in rightmost processing"); if (minIndex == 0) { findRightmostEdgeAtNode(); } else { findRightmostEdgeAtVertex(); } /** now check that the extreme side is the R side. If not, use the sym instead. */ orientedDe = minDe; int rightmostSide = getRightmostSide(minDe, minIndex); if (rightmostSide == Position.LEFT) { orientedDe = minDe.getSym(); } }
public void computeIntersection(Coordinate p, Coordinate p1, Coordinate p2) { isProper = false; // do between check first, since it is faster than the orientation test if (Envelope.intersects(p1, p2, p)) { if ((CGAlgorithms.orientationIndex(p1, p2, p) == 0) && (CGAlgorithms.orientationIndex(p2, p1, p) == 0)) { isProper = true; if (p.equals(p1) || p.equals(p2)) { isProper = false; } result = POINT_INTERSECTION; return; } } result = NO_INTERSECTION; }
@Test public void testGetCoordinateCopy() throws Exception { // geom independance: changing returned coordinate does not change sequence. Coordinate co = testSeq2D.getCoordinateCopy(1); co.x = co.x + 1; assertFalse(co.equals(testSeq2D.getCoordinateCopy(1))); }
@Override public synchronized boolean equals(Object obj) { if (obj == null) return false; if (this == obj) return true; if (getClass() != obj.getClass()) return false; NodeOsm other = (NodeOsm) obj; if (coor == null) { if (other.coor != null) return false; } else if (!coor.equals(other.coor)) return false; return true; }
private int computeCollinearIntersection( Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2) { boolean p1q1p2 = Envelope.intersects(p1, p2, q1); boolean p1q2p2 = Envelope.intersects(p1, p2, q2); boolean q1p1q2 = Envelope.intersects(q1, q2, p1); boolean q1p2q2 = Envelope.intersects(q1, q2, p2); if (p1q1p2 && p1q2p2) { intPt[0] = q1; intPt[1] = q2; return COLLINEAR_INTERSECTION; } if (q1p1q2 && q1p2q2) { intPt[0] = p1; intPt[1] = p2; return COLLINEAR_INTERSECTION; } if (p1q1p2 && q1p1q2) { intPt[0] = q1; intPt[1] = p1; return q1.equals(p1) && !p1q2p2 && !q1p2q2 ? POINT_INTERSECTION : COLLINEAR_INTERSECTION; } if (p1q1p2 && q1p2q2) { intPt[0] = q1; intPt[1] = p2; return q1.equals(p2) && !p1q2p2 && !q1p1q2 ? POINT_INTERSECTION : COLLINEAR_INTERSECTION; } if (p1q2p2 && q1p1q2) { intPt[0] = q2; intPt[1] = p1; return q2.equals(p1) && !p1q1p2 && !q1p2q2 ? POINT_INTERSECTION : COLLINEAR_INTERSECTION; } if (p1q2p2 && q1p2q2) { intPt[0] = q2; intPt[1] = p2; return q2.equals(p2) && !p1q1p2 && !q1p1q2 ? POINT_INTERSECTION : COLLINEAR_INTERSECTION; } return NO_INTERSECTION; }
private void distribute(AddressNodeGroup group) { List<AddressNode> nodes = group.getAddressNodes(); Collections.sort(nodes, addressNodeComparator); Coordinate start = group.getGeometry().getCoordinate(); // center of the building Coordinate center = group.getBuilding().getGeometry().getCentroid().getCoordinate(); double dx; double dy; if (start.equals(center)) { // if the nodes are at the center of the building, use an angle of 45 degrees dx = SQRT2 * DISTANCE; dy = SQRT2 * DISTANCE; } else { double angle = new LineSegment(start, center).angle(); dx = Math.cos(angle) * DISTANCE; dy = Math.sin(angle) * DISTANCE; } double x = group.getGeometry().getX(); double y = group.getGeometry().getY(); // List<Command> cmds = new LinkedList<>(); for (AddressNode node : nodes) { Point point = geoUtil.toPoint(new Coordinate(x, y)); node.setGeometry(point); // Command cmd = node.updateGeometry(point); // if (cmd != null) { // cmds.add(cmd); // } x = x + dx; y = y + dy; } // if (!nodes.isEmpty()) { // final SequenceCommand sequenceCommand = new SequenceCommand( // I18n.tr("Distribute {0} address nodes.", cmds.size()), cmds); // Main.main.undoRedo.add(sequenceCommand); // } }
/** * Split the graph by splitting an Edge at a point into 2 Edges * * @param c coordinates at which to split the graph * @param iSplit split index (the i-th split point, used to create the new edge IDs) */ public void splitGraphAtPoint(Coordinate c, int iSplit) { Edge nearestEdge = null; float nearestDist = kNearestEdgeDistance; while (nearestEdge == null && nearestDist / kNearestEdgeDistance < 20.) { nearestEdge = findNearestEdge(c, nearestDist); if (nearestEdge == null) { nearestDist *= 2.; logger.info("Increasing kNearestEdgeDistance: " + nearestDist); } } // get the projected point on the nearest edge PointPairDistance ppd = new PointPairDistance(); @SuppressWarnings("rawtypes") LineString nearestLineString = (LineString) ((HashMap) nearestEdge.getData()).get("geom"); EuclideanDistanceToPoint.computeDistance(nearestLineString, c, ppd); Coordinate resultcoord = null; for (Coordinate cc : ppd.getCoordinates()) { // System.out.println(cc); if (cc.equals(c) == false) { resultcoord = cc; } } // let us loop through the vertices Coordinate[] nearestLineStringCoordinates = nearestLineString.getCoordinates(); ArrayList<Coordinate> fromVertices = new ArrayList<Coordinate>(); ArrayList<Coordinate> toVertices = new ArrayList<Coordinate>(); fromVertices.add(nearestLineStringCoordinates[0]); boolean isAfter = false; for (int i = 1; i < nearestLineStringCoordinates.length; i++) { Coordinate pt0 = nearestLineStringCoordinates[i - 1]; Coordinate pt1 = nearestLineStringCoordinates[i]; // let us build a segment between 2 nodes Coordinate[] segmentCoords = {pt0, pt1}; LineString segment = fact.createLineString(segmentCoords); // let us check whether the projected point (resultcoord) is on the node if (fact.createPoint(resultcoord).distance(segment) < SPLITSNAPDISTANCE) { // point within, let us split fromVertices.add(resultcoord); toVertices.add(resultcoord); isAfter = true; } else { if (!isAfter) { fromVertices.add(nearestLineStringCoordinates[i]); } else { toVertices.add(nearestLineStringCoordinates[i]); } } } // if (nearestLineStringCoordinates.length==2) { toVertices.add(nearestLineStringCoordinates[nearestLineStringCoordinates.length - 1]); // } // TODO: generate nice edge ids here int id1 = -2 * iSplit - 1; int id2 = -2 * iSplit - 2; // replace straight lines with lines including vertices Coordinate[] fromArray = new Coordinate[fromVertices.size()]; Coordinate[] toArray = new Coordinate[toVertices.size()]; fromVertices.toArray(fromArray); toVertices.toArray(toArray); addLineString(fact.createLineString(fromArray), id1); addLineString(fact.createLineString(toArray), id2); this.removeEdge(nearestEdge); System.out.println("Graph split @ " + resultcoord); }
/** * Tests whether a given point is in an array of points. Uses a value-based test. * * @param pt a {@link Coordinate} for the test point * @param pts an array of {@link Coordinate}s to test * @return <code>true</code> if the point is in the array * @deprecated */ public static boolean isInList(Coordinate pt, Coordinate[] pts) { for (int i = 0; i < pts.length; i++) { if (pt.equals(pts[i])) return true; } return false; }