/** * 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); }
/** * 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; } /**
/** * 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; }
/** * 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; int comp = 0; 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(); }
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; }
/** * 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; }
/** * 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); }
/** * 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) { CoordinateArrays.reverse(getCoordinates()); } return; } } }
if (p0.compareTo(p1) > 0) { Coordinate tmp = p0; p0 = p1;
/** * 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(); }
protected int compareToSameClass(Object other) { Point point = (Point) other; return getCoordinate().compareTo(point.getCoordinate()); }
/** * 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(); }
public LineString getSelectedLine() { if (getNbSelected() != 2) { return null; } final Coordinate[] cs = new Coordinate[2]; cs[0] = new Coordinate(modele_.getX(getLayerSelection().getMinIndex()), modele_.getY(getLayerSelection() .getMinIndex())); cs[1] = new Coordinate(modele_.getX(getLayerSelection().getMaxIndex()), modele_.getY(getLayerSelection() .getMaxIndex())); if (cs[0].compareTo(cs[1]) > 0) { final Coordinate tmp = cs[0]; cs[0] = cs[1]; cs[1] = tmp; } return GISGeometryFactory.INSTANCE.createLineString(cs); }