/** * Ensure Ring of Coordinates are in a counter Orientationwise order. * * <p>If the Coordinate need to be reversed a copy will be returned. * * @param factory Factory to used to reverse CoordinateSequence * @param ring Ring of Coordinates * @return coords in a CCW order */ public static CoordinateSequence counterClockWise( CoordinateSequenceFactory factory, CoordinateSequence ring) { if (Orientation.isCCW(ring.toCoordinateArray())) { return ring; } return Coordinates.reverse(factory, ring); }
/** * Ensure Ring of Coordinates are in a Orientationwise order. * * <p>If the Coordinate need to be reversed a copy will be returned. * * @param factory Factory used to reverse CoordinateSequence * @param ring Ring of Coordinates * @return coords in a CW order */ private static CoordinateSequence clockWise( CoordinateSequenceFactory factory, CoordinateSequence ring) { if (!Orientation.isCCW(ring.toCoordinateArray())) { return ring; } return Coordinates.reverse(factory, ring); }
private boolean isConcave(Coordinate p0, Coordinate p1, Coordinate p2) { int orientation = Orientation.index(p0, p1, p2); boolean isConcave = (orientation == angleOrientation); return isConcave; } }
/** * Determines the orientation index of a {@link Coordinate} relative to this segment. * The orientation index is as defined in {@link Orientation#computeOrientation}. * * @param p the coordinate to compare * * @return 1 (LEFT) if <code>p</code> is to the left of this segment * @return -1 (RIGHT) if <code>p</code> is to the right of this segment * @return 0 (COLLINEAR) if <code>p</code> is collinear with this segment * * @see Orientation#computeOrientation(Coordinate, Coordinate, Coordinate) */ public int orientationIndex(Coordinate p) { return Orientation.index(p0, p1, p); }
private boolean isHole(Coordinate[] pts) { return Orientation.isCCW(pts); }
/** * Returns an array of pts such that p0 - p[0] - [p1] is CW. * * @param p0 * @param p1 * @param p2 * @return */ private static Coordinate[] orientCorner(Coordinate p0, Coordinate p1, Coordinate p2) { Coordinate[] orient; // TODO: not sure if determining orientation is necessary? if (Orientation.CLOCKWISE == Orientation.index(p0, p1, p2)) { orient = new Coordinate[] {p1, p2 }; } else { orient = new Coordinate[] { p2, p1 }; } return orient; }
if (Orientation.isCCW(ring.getCoordinates())) { // it is an Interior Hole rings.add(ring); i++;
/** * Returns 1 if this DirectedEdge has a greater angle with the * positive x-axis than b", 0 if the DirectedEdges are collinear, and -1 otherwise. * <p> * Using the obvious algorithm of simply computing the angle is not robust, * since the angle calculation is susceptible to roundoff. A robust algorithm * is: * <ul> * <li>first compare the quadrants. If the quadrants are different, it it * trivial to determine which vector is "greater". * <li>if the vectors lie in the same quadrant, the robust * {@link Orientation#computeOrientation(Coordinate, Coordinate, Coordinate)} * function can be used to decide the relative orientation of the vectors. * </ul> */ public int compareDirection(DirectedEdge e) { // if the rays are in different quadrants, determining the ordering is trivial if (quadrant > e.quadrant) return 1; if (quadrant < e.quadrant) return -1; // vectors are in the same quadrant - check relative orientation of direction vectors // this is > e if it is CCW of e return Orientation.index(e.p0, e.p1, p1); }
public static boolean isCCW(Geometry g) { Coordinate[] ptsRing = OrientationFunctions.getRing(g); if (ptsRing == null) return false; return Orientation.isCCW(ptsRing); }
/** * * @param pt * @param cornerBase the two vertices defining the * @param corner the two vertices defining the arms of the corner, oriented CW * @return the quadrant the pt lies in */ private static int quadrant(Coordinate pt, Coordinate cornerBase, Coordinate[] corner) { if (Orientation.index(cornerBase, corner[0], pt) == Orientation.CLOCKWISE) { if (Orientation.index(cornerBase, corner[1], pt) == Orientation.COUNTERCLOCKWISE) { return 0; } else return 3; } else { if (Orientation.index(cornerBase, corner[1], pt) == Orientation.COUNTERCLOCKWISE) { return 1; } else return 2; } }
/** * Compute a LinearRing from the point list previously collected. * Test if the ring is a hole (i.e. if it is CCW) and set the hole flag * accordingly. */ public void computeRing() { if (ring != null) return; // don't compute more than once Coordinate[] coord = new Coordinate[pts.size()]; for (int i = 0; i < pts.size(); i++) { coord[i] = (Coordinate) pts.get(i); } ring = geometryFactory.createLinearRing(coord); isHole = Orientation.isCCW(ring.getCoordinates()); //Debug.println( (isHole ? "hole - " : "shell - ") + WKTWriter.toLineString(new CoordinateArraySequence(ring.getCoordinates()))); } abstract public DirectedEdge getNext(DirectedEdge de);
/** * Implements the total order relation: * <p> * a has a greater angle with the positive x-axis than b * <p> * Using the obvious algorithm of simply computing the angle is not robust, * since the angle calculation is obviously susceptible to roundoff. * A robust algorithm is: * - first compare the quadrant. If the quadrants * are different, it it trivial to determine which vector is "greater". * - if the vectors lie in the same quadrant, the computeOrientation function * can be used to decide the relative orientation of the vectors. */ public int compareDirection(EdgeEnd e) { if (dx == e.dx && dy == e.dy) return 0; // if the rays are in different quadrants, determining the ordering is trivial if (quadrant > e.quadrant) return 1; if (quadrant < e.quadrant) return -1; // vectors are in the same quadrant - check relative orientation of direction vectors // this is > e if it is CCW of e return Orientation.index(e.p0, e.p1, p1); }
private void addHole(Coordinate[] pts) { boolean isPositiveArea = Orientation.isCCW(pts); for (int i = 0; i < pts.length - 1; i++) { addTriangle(areaBasePt, pts[i], pts[i+1], isPositiveArea); } addLineSegments(pts); } private void addTriangle(Coordinate p0, Coordinate p1, Coordinate p2, boolean isPositiveArea)
/** *@return whether the three coordinates are collinear and c2 lies between * c1 and c3 inclusive */ private boolean isBetween(Coordinate c1, Coordinate c2, Coordinate c3) { if (Orientation.index(c1, c2, c3) != 0) { return false; } if (c1.x != c3.x) { if (c1.x <= c2.x && c2.x <= c3.x) { return true; } if (c3.x <= c2.x && c2.x <= c1.x) { return true; } } if (c1.y != c3.y) { if (c1.y <= c2.y && c2.y <= c3.y) { return true; } if (c3.y <= c2.y && c2.y <= c1.y) { return true; } } return false; }
/** * Computes whether this ring is a hole. * Due to the way the edges in the polygonization graph are linked, * a ring is a hole if it is oriented counter-clockwise. */ public void computeHole() { LinearRing ring = getRing(); isHole = Orientation.isCCW(ring.getCoordinates()); }
int orient = Orientation.index(o, p, q);