boolean sharedVertex = false; if (((pos = Arrays.binarySearch(edges, 0, intersections, current, INTERSECTION_ORDER)) >= 0) && !(sharedVertex = (edges[pos].intersect.compareTo(current.coordinate) == 0))) {
/** * Tests if the given coordinates form a valid edge (with non-zero length). * * @param orig the start coordinate * @param dest the end coordinate * @return true if the edge formed is valid */ public static boolean isValidEdge(Coordinate orig, Coordinate dest) { int cmp = dest.compareTo(orig); return cmp != 0; }
/** * Compares this object with the specified object for order. * Uses the standard lexicographic ordering for the points in the LineSegment. * *@param o the <code>LineSegment</code> with which this <code>LineSegment</code> * is being compared *@return a negative integer, zero, or a positive integer as this <code>LineSegment</code> * is less than, equal to, or greater than the specified <code>LineSegment</code> */ public int compareTo(Object o) { LineSegment other = (LineSegment) o; int comp0 = p0.compareTo(other.p0); if (comp0 != 0) return comp0; return p1.compareTo(other.p1); }
/** * Compare two collinear segments for left-most ordering. * If segs are vertical, use vertical ordering for comparison. * If segs are equal, return 0. * Segments are assumed to be directed so that the second coordinate is >= to the first * (e.g. up and to the right). * * @param seg0 a segment to compare * @param seg1 a segment to compare * @return */ private int compareX(LineSegment seg0, LineSegment seg1) { int compare0 = seg0.p0.compareTo(seg1.p0); if (compare0 != 0) return compare0; return seg0.p1.compareTo(seg1.p1); }
/** * Determines whether two {@link Coordinate} arrays of equal length * are equal in opposite directions. * * @param pts1 * @param pts2 * @return <code>true</code> if the two arrays are equal in opposite directions. */ private static boolean isEqualReversed(Coordinate[] pts1, Coordinate[] pts2) { for (int i = 0; i < pts1.length; i++) { Coordinate p1 = pts1[i]; Coordinate p2 = pts2[pts1.length - i - 1]; if (p1.compareTo(p2) != 0) return false; } return true; }
/** * Returns the minimum coordinate, using the usual lexicographic comparison. * *@param coordinates the array to search *@return the minimum coordinate in the array, found using <code>compareTo</code> *@see Coordinate#compareTo(Object) */ public static Coordinate minCoordinate(Coordinate[] coordinates) { Coordinate minCoord = null; for (int i = 0; i < coordinates.length; i++) { if (minCoord == null || minCoord.compareTo(coordinates[i]) > 0) { minCoord = coordinates[i]; } } return minCoord; } /**
/** * Compares two {@link Coordinate} arrays * in the forward direction of their coordinates, * using lexicographic ordering. * * @param pts1 * @param pts2 * @return an integer indicating the order */ public static int compare(Coordinate[] pts1, Coordinate[] pts2) { int i = 0; while (i < pts1.length && i < pts2.length) { int compare = pts1[i].compareTo(pts2[i]); if (compare != 0) return compare; i++; } // handle situation when arrays are of different length if (i < pts2.length) return -1; if (i < pts1.length) return 1; return 0; }
private static int compareOriented(Coordinate[] pts1, boolean orientation1, Coordinate[] pts2, boolean orientation2) { int dir1 = orientation1 ? 1 : -1; int dir2 = orientation2 ? 1 : -1; int limit1 = orientation1 ? pts1.length : -1; int limit2 = orientation2 ? pts2.length : -1; int i1 = orientation1 ? 0 : pts1.length - 1; int i2 = orientation2 ? 0 : pts2.length - 1; while (true) { int compPt = pts1[i1].compareTo(pts2[i2]); if (compPt != 0) return compPt; i1 += dir1; i2 += dir2; boolean done1 = i1 == limit1; boolean done2 = i2 == limit2; if (done1 && ! done2) return -1; if (! done1 && done2) return 1; if (done1 && done2) return 0; } }
/** * Determines which orientation of the {@link Coordinate} array * is (overall) increasing. * In other words, determines which end of the array is "smaller" * (using the standard ordering on {@link Coordinate}). * Returns an integer indicating the increasing direction. * If the sequence is a palindrome, it is defined to be * oriented in a positive direction. * * @param pts the array of Coordinates to test * @return <code>1</code> if the array is smaller at the start * or is a palindrome, * <code>-1</code> if smaller at the end */ public static int increasingDirection(Coordinate[] pts) { for (int i = 0; i < pts.length / 2; i++) { int j = pts.length - 1 - i; // skip equal points on both ends int comp = pts[i].compareTo(pts[j]); if (comp != 0) return comp; } // array must be a palindrome - defined to be in positive direction return 1; }
/** * Puts the line segment into a normalized form. * This is useful for using line segments in maps and indexes when * topological equality rather than exact equality is desired. * A segment in normalized form has the first point smaller * than the second (according to the standard ordering on {@link Coordinate}). */ public void normalize() { if (p1.compareTo(p0) < 0) reverse(); }
/** * Compare two collinear segments for left-most ordering. * If segs are vertical, use vertical ordering for comparison. * If segs are equal, return 0. * Segments are assumed to be directed so that the second coordinate is >= to the first * (e.g. up and to the right). * * @param seg0 a segment to compare * @param seg1 a segment to compare * @return */ private int compareX(LineSegment seg0, LineSegment seg1) { int compare0 = seg0.p0.compareTo(seg1.p0); if (compare0 != 0) return compare0; return seg0.p1.compareTo(seg1.p1); } public String toString()
/** * Returns the index of the minimum coordinate of a part of * the coordinate sequence (defined by {@code from} and {@code to}, * using the usual lexicographic comparison. * *@param seq the coordinate sequence to search *@param from the lower search index *@param to the upper search index *@return the index of the minimum coordinate in the sequence, found using <code>compareTo</code> *@see Coordinate#compareTo(Object) */ public static int minCoordinateIndex(CoordinateSequence seq, int from, int to) { int minCoordIndex = -1; Coordinate minCoord = null; for (int i = from; i <= to; i++) { Coordinate testCoord = seq.getCoordinate(i); if (minCoord == null || minCoord.compareTo(testCoord) > 0) { minCoord = testCoord; minCoordIndex = i; } } return minCoordIndex; }
protected int compareToSameClass(Object other) { Point point = (Point) other; return getCoordinate().compareTo(point.getCoordinate()); }
public int OLDcompare(Object o1, Object o2) { Coordinate[] pts1 = (Coordinate[]) o1; Coordinate[] pts2 = (Coordinate[]) o2; if (pts1.length < pts2.length) return -1; if (pts1.length > pts2.length) return 1; if (pts1.length == 0) return 0; int dir1 = increasingDirection(pts1); int dir2 = increasingDirection(pts2); int i1 = dir1 > 0 ? 0 : pts1.length - 1; int i2 = dir2 > 0 ? 0 : pts1.length - 1; for (int i = 0; i < pts1.length; i++) { int comparePt = pts1[i1].compareTo(pts2[i2]); if (comparePt != 0) return comparePt; i1 += dir1; i2 += dir2; } return 0; }
/** * Returns the minimum coordinate, using the usual lexicographic comparison. * *@param seq the coordinate sequence to search *@return the minimum coordinate in the sequence, found using <code>compareTo</code> *@see Coordinate#compareTo(Object) */ public static Coordinate minCoordinate(CoordinateSequence seq) { Coordinate minCoord = null; for (int i = 0; i < seq.size(); i++) { Coordinate testCoord = seq.getCoordinate(i); if (minCoord == null || minCoord.compareTo(testCoord) > 0) { minCoord = testCoord; } } return minCoord; } /**
public void visit(KdNode node) { double dist = p.distance(node.getCoordinate()); boolean isInTolerance = dist <= tolerance; if (! isInTolerance) return; boolean update = false; if (matchNode == null || dist < matchDist // if distances are the same, record the lesser coordinate || (matchNode != null && dist == matchDist && node.getCoordinate().compareTo(matchNode.getCoordinate()) < 1)) update = true; if (update) { matchNode = node; matchDist = dist; } } }
public void testCompareTo() { Coordinate lowest = new Coordinate(10.0, 100.0, 50.0); Coordinate highest = new Coordinate(20.0, 100.0, 50.0); Coordinate equalToHighest = new Coordinate(20.0, 100.0, 50.0); Coordinate higherStill = new Coordinate(20.0, 200.0, 50.0); assertEquals(-1, lowest.compareTo(highest)); assertEquals(1, highest.compareTo(lowest)); assertEquals(-1, highest.compareTo(higherStill)); assertEquals(0, highest.compareTo(equalToHighest)); } public void testToString()
/** * Gets the primary edge of this quadedge and its <tt>sym</tt>. * The primary edge is the one for which the origin * and destination coordinates are ordered * according to the standard {@link Coordinate} ordering * * @return the primary quadedge */ public QuadEdge getPrimary() { if (orig().getCoordinate().compareTo(dest().getCoordinate()) <= 0) return this; else return sym(); }
protected int compareToSameClass(Object o) { LineString line = (LineString) o; // MD - optimized implementation int i = 0; int j = 0; while (i < points.size() && j < line.points.size()) { int comparison = points.getCoordinate(i).compareTo(line.points.getCoordinate(j)); if (comparison != 0) { return comparison; } i++; j++; } if (i < points.size()) { return 1; } if (j < line.points.size()) { return -1; } return 0; }
/** * Normalizes a LineString. A normalized linestring * has the first point which is not equal to it's reflected point * less than the reflected point. */ public void normalize() { for (int i = 0; i < points.size() / 2; i++) { int j = points.size() - 1 - i; // skip equal points on both ends if (!points.getCoordinate(i).equals(points.getCoordinate(j))) { if (points.getCoordinate(i).compareTo(points.getCoordinate(j)) > 0) { CoordinateSequence copy = points.copy(); CoordinateSequences.reverse(copy); points = copy; } return; } } }