private static boolean isClosed(Coordinate[] pts) { if (pts.length <= 1) return false; return pts[0].equals2D(pts[pts.length - 1]); } /**
/** * @return true if the coordinate sequences of the Edges are identical */ public boolean isPointwiseEqual(Edge e) { if (pts.length != e.pts.length) return false; for (int i = 0; i < pts.length; i++) { if (! pts[i].equals2D(e.pts[i])) { return false; } } return true; }
/** * Tests whether an array of {@link Coordinate}s forms a ring, * by checking length and closure. * Self-intersection is not checked. * * @param pts an array of Coordinates * @return true if the coordinate form a ring. */ public static boolean isRing(Coordinate[] pts) { if (pts.length < 4) return false; if (! pts[0].equals2D(pts[pts.length -1])) return false; return true; }
/** * Returns <code>true</code> if <code>other</code> has the same values for * the x and y ordinates. * Since Coordinates are 2.5D, this routine ignores the z value when making the comparison. * *@param other a <code>Coordinate</code> with which to do the comparison. *@return <code>true</code> if <code>other</code> is a <code>Coordinate</code> * with the same values for the x and y ordinates. */ public boolean equals(Object other) { if (!(other instanceof Coordinate)) { return false; } return equals2D((Coordinate) other); }
/** * Tests whether either intersection point is an interior point of the specified input segment. * * @return <code>true</code> if either intersection point is in the interior of the input segment */ public boolean isInteriorIntersection(int inputLineIndex) { for (int i = 0; i < result; i++) { if (! ( intPt[i].equals2D(inputLines[inputLineIndex][0]) || intPt[i].equals2D(inputLines[inputLineIndex][1]) )) { return true; } } return false; }
/** * Test whether a point is a intersection point of two line segments. * Note that if the intersection is a line segment, this method only tests for * equality with the endpoints of the intersection segment. * It does <b>not</b> return true if * the input point is internal to the intersection segment. * * @return true if the input point is one of the intersection points. */ public boolean isIntersection(Coordinate pt) { for (int i = 0; i < result; i++) { if (intPt[i].equals2D(pt)) { return true; } } return false; }
private void rescale(Coordinate[] pts) { Coordinate p0 = null; Coordinate p1 = null; if (pts.length == 2) { p0 = new Coordinate(pts[0]); p1 = new Coordinate(pts[1]); } for (int i = 0; i < pts.length; i++) { pts[i].x = pts[i].x / scaleFactor + offsetX; pts[i].y = pts[i].y / scaleFactor + offsetY; } if (pts.length == 2 && pts[0].equals2D(pts[1])) { System.out.println(pts); } }
private Coordinate findSnapForVertex(Coordinate pt, Coordinate[] snapPts) { for (int i = 0; i < snapPts.length; i++) { // if point is already equal to a src pt, don't snap if (pt.equals2D(snapPts[i])) return null; if (pt.distance(snapPts[i]) < snapTolerance) return snapPts[i]; } return null; }
private int locate(Coordinate p, Point pt) { // no point in doing envelope test, since equality test is just as fast Coordinate ptCoord = pt.getCoordinate(); if (ptCoord.equals2D(p)) return Location.INTERIOR; return Location.EXTERIOR; }
public SegmentNode(NodedSegmentString segString, Coordinate coord, int segmentIndex, int segmentOctant) { this.segString = segString; this.coord = new Coordinate(coord); this.segmentIndex = segmentIndex; this.segmentOctant = segmentOctant; isInterior = ! coord.equals2D(segString.getCoordinate(segmentIndex)); }
private int safeOctant(Coordinate p0, Coordinate p1) { if (p0.equals2D(p1)) return 0; return Octant.octant(p0, p1); }
/** * @return -1 this SegmentNode is located before the argument location; * 0 this SegmentNode is at the argument location; * 1 this SegmentNode is located after the argument location */ public int compareTo(Object obj) { SegmentNode other = (SegmentNode) obj; if (segmentIndex < other.segmentIndex) return -1; if (segmentIndex > other.segmentIndex) return 1; if (coord.equals2D(other.coord)) return 0; return SegmentPointComparator.compare(segmentOctant, coord, other.coord); //return segment.compareNodePosition(this, other); }
private boolean findCollapseIndex(SegmentNode ei0, SegmentNode ei1, int[] collapsedVertexIndex) { // only looking for equal nodes if (! ei0.coord.equals2D(ei1.coord)) return false; int numVerticesBetween = ei1.segmentIndex - ei0.segmentIndex; if (! ei1.isInterior()) { numVerticesBetween--; } // if there is a single vertex between the two equal nodes, this is a collapse if (numVerticesBetween == 1) { collapsedVertexIndex[0] = ei0.segmentIndex + 1; return true; } return false; }
/** * Adds a coordinate to the end of the list. * * @param coord The coordinates * @param allowRepeated if set to false, repeated coordinates are collapsed */ public void add(Coordinate coord, boolean allowRepeated) { // don't add duplicate coordinates if (! allowRepeated) { if (size() >= 1) { Coordinate last = (Coordinate) get(size() - 1); if (last.equals2D(coord)) return; } } super.add(coord); }
public void splitAt(double length, Coordinate endPt) { double actualLen = getConstrainedLength(length); double frac = actualLen / segLen; if (endPt.equals2D(seg.p0)) splitPt = seg.pointAlong(frac); else splitPt = pointAlongReverse(seg, frac); }
/** * Adds nodes for any collapsed edge pairs * which are pre-existing in the vertex list. */ private void findCollapsesFromExistingVertices(List collapsedVertexIndexes) { for (int i = 0; i < edge.size() - 2; i++) { Coordinate p0 = edge.getCoordinate(i); Coordinate p1 = edge.getCoordinate(i + 1); Coordinate p2 = edge.getCoordinate(i + 2); if (p0.equals2D(p2)) { // add base of collapse as node collapsedVertexIndexes.add(new Integer(i + 1)); } } }
public boolean isClosed() { if (isEmpty()) { return false; } return getCoordinateN(0).equals2D(getCoordinateN(getNumPoints() - 1)); }
/** * Tests if this quadedge and another have the same line segment geometry * with the same orientation. * * @param qe a quadege * @return true if the quadedges are based on the same line segment */ public boolean equalsOriented(QuadEdge qe) { if (orig().getCoordinate().equals2D(qe.orig().getCoordinate()) && dest().getCoordinate().equals2D(qe.dest().getCoordinate())) return true; return false; }