Refine search
private void normalize(LinearRing ring, boolean clockwise) { if (ring.isEmpty()) { return; } Coordinate[] uniqueCoordinates = new Coordinate[ring.getCoordinates().length - 1]; System.arraycopy(ring.getCoordinates(), 0, uniqueCoordinates, 0, uniqueCoordinates.length); Coordinate minCoordinate = CoordinateArrays.minCoordinate(ring.getCoordinates()); CoordinateArrays.scroll(uniqueCoordinates, minCoordinate); System.arraycopy(uniqueCoordinates, 0, ring.getCoordinates(), 0, uniqueCoordinates.length); ring.getCoordinates()[uniqueCoordinates.length] = uniqueCoordinates[0]; if (CGAlgorithms.isCCW(ring.getCoordinates()) == clockwise) { CoordinateArrays.reverse(ring.getCoordinates()); } }
/** * This method will cause the ring to be computed. * It will also check any holes, if they have been assigned. */ public boolean containsPoint(Coordinate p) { LinearRing shell = getLinearRing(); Envelope env = shell.getEnvelopeInternal(); if (! env.contains(p)) return false; if (! CGAlgorithms.isPointInRing(p, shell.getCoordinates()) ) return false; for (Iterator i = holes.iterator(); i.hasNext(); ) { EdgeRing hole = (EdgeRing) i.next(); if (hole.containsPoint(p) ) return false; } return true; }
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; }
private boolean isShallowConcavity(Coordinate p0, Coordinate p1, Coordinate p2, double distanceTol) { int orientation = CGAlgorithms.computeOrientation(p0, p1, p2); boolean isAngleToSimplify = (orientation == angleOrientation); if (! isAngleToSimplify) return false; double dist = CGAlgorithms.distancePointLine(p1, p0, p2); return dist < distanceTol; }
if (! Envelope.intersects(p1, p2, q1, q2)) return NO_INTERSECTION; int Pq1 = CGAlgorithms.orientationIndex(p1, p2, q1); int Pq2 = CGAlgorithms.orientationIndex(p1, p2, q2); int Qp1 = CGAlgorithms.orientationIndex(q1, q2, p1); int Qp2 = CGAlgorithms.orientationIndex(q1, q2, p2); if (p1.equals2D(q1) || p1.equals2D(q2)) { intPt[0] = p1; else if (p2.equals2D(q1) || p2.equals2D(q2)) { intPt[0] = p2;
/** * Determines whether a point lies in a LinearRing, * using the ring envelope to short-circuit if possible. * * @param p the point to test * @param ring a linear ring * @return true if the point lies inside the ring */ private static boolean isPointInRing(Coordinate p, LinearRing ring) { // short-circuit if point is not in ring envelope if (! ring.getEnvelopeInternal().intersects(p)) return false; return CGAlgorithms.isPointInRing(p, ring.getCoordinates()); }
final int nbPt = frRing_.getNumPoints(); final CoordinateSequence seq = frRing_.getCoordinateSequence(); for (int i = nbPt - 1; i > 0; i--) { seq.getCoordinate(i, tmp1_); final Coordinate intersect = line_.getIntersectedPoint(); final double d = CtuluLibGeometrie.getD2(_l1.x, _l1.y, intersect.x, intersect.y); if (CGAlgorithms.orientationIndex(_p1, _p2, intersect) == CGAlgorithms.COUNTERCLOCKWISE) { if (d2 < 0 || d < d2) { d2 = d; resCor_[1] = new Coordinate(intersect); resIdx_[1] = i - 1; if (d1 < 0 || d < d1) { d1 = d; resCor_[0] = new Coordinate(intersect); resIdx_[0] = i - 1; final int trigo = CGAlgorithms.orientationIndex(_p1, _p2, resCor_[1]); if (trigo != CGAlgorithms.COUNTERCLOCKWISE) { final Coordinate tmp = resCor_[0];
private static boolean isCCW( LinearRing c ) { Points ps = c.getControlPoints(); Coordinate[] cs = new Coordinate[ps.size()]; int i = 0; for ( Point p : ps ) { cs[i++] = new Coordinate( p.get0(), p.get1() ); } return CGAlgorithms.isCCW( cs ); }
if (A.equals(B)) return distancePointLine(A, C, D); if (C.equals(D)) return distancePointLine(D, A, B); if (! Envelope.intersects(A, B, C, D)) { noIntersection = true; distancePointLine(A, C, D), distancePointLine(B, C, D), distancePointLine(C, A, B), distancePointLine(D, A, B));
/** * Tests whether this ring is a hole. * Due to the way the edges in the polyongization graph are linked, * a ring is a hole if it is oriented counter-clockwise. * @return <code>true</code> if this ring is a hole */ public boolean isHole() { LinearRing ring = getRing(); return CGAlgorithms.isCCW(ring.getCoordinates()); }
/** * The coordinate pairs match if they define line segments lying in the same direction. * E.g. the segments are parallel and in the same quadrant * (as opposed to parallel and opposite!). */ private boolean matchInSameDirection(Coordinate p0, Coordinate p1, Coordinate ep0, Coordinate ep1) { if (! p0.equals(ep0)) return false; if (CGAlgorithms.computeOrientation(p0, p1, ep1) == CGAlgorithms.COLLINEAR && Quadrant.quadrant(p0, p1) == Quadrant.quadrant(ep0, ep1) ) return true; return false; }
private boolean isHole(Coordinate[] pts) { return CGAlgorithms.isCCW(pts); }
private void checkSegmentDistance(Coordinate seg0, Coordinate seg1) { if (queryPt.equals2D(seg0) || queryPt.equals2D(seg1)) return; double segDist = CGAlgorithms.distancePointLine(queryPt, seg1, seg0); if (segDist > 0) updateClearance(segDist, queryPt, seg1, seg0); }
if (CGAlgorithms.signedArea(ring.getCoordinateSequence()) > 0.0) holes.add(ring); else
Coordinate[] shellPts = shell.getCoordinates(); Coordinate[] holePts = hole.getCoordinates(); boolean insideHole = CGAlgorithms.isPointInRing(shellPt, holePts); if (! insideHole) { return shellPt; boolean insideShell = CGAlgorithms.isPointInRing(holePt, shellPts); if (insideShell) { return holePt;
/** * Computes the distance from a point to a sequence of line segments. * * @param p * a point * @param line * a sequence of contiguous line segments defined by their vertices * @return the minimum distance between the point and the line segments */ public static double distancePointLine(Coordinate p, Coordinate[] line) { if (line.length == 0) throw new IllegalArgumentException( "Line array must contain at least one vertex"); // this handles the case of length = 1 double minDistance = p.distance(line[0]); for (int i = 0; i < line.length - 1; i++) { double dist = CGAlgorithms.distancePointLine(p, line[i], line[i + 1]); if (dist < minDistance) { minDistance = dist; } } return minDistance; }
double area = CGAlgorithms.signedArea(r.getCoordinates()); if (!r.isRing()) { continue; // sanity check, could probably be handled in a isSimple() check
private double fetchZ(Coordinate pt, int idGeom) { Triangle curTri = getTriangle(idGeom); while(!triangleContainsPoint(curTri, pt)) { // Fetch neighbor where pt lies at the other side of triangle segment int bestNeigh = -1; for(int idSeg = 0; idSeg < 3; idSeg++) { LineSegment seg = getTriangleSegment(idGeom, idSeg); int ptPos = CGAlgorithms.orientationIndex(seg.p0, seg.p1, pt); if(CGAlgorithms.isCCW(inputTriangles.getGeometryN(idGeom).getCoordinates())) { ptPos = -ptPos; } if(ptPos == 1) { bestNeigh = idSeg; break; } else if(ptPos == 0 && bestNeigh == -1) { bestNeigh = idSeg; } } if(bestNeigh != -1) { idGeom = triangleNeighbors[idGeom].get(bestNeigh); if(idGeom >= 0) { curTri = getTriangle(idGeom); } else { return Double.NaN; } } } return curTri.interpolateZ(pt); }
if (iPrev < 0) iPrev = nPts; } while (ring[iPrev].equals2D(hiPt) && iPrev != hiIndex); do { iNext = (iNext + 1) % nPts; } while (ring[iNext].equals2D(hiPt) && iNext != hiIndex); if (prev.equals2D(hiPt) || next.equals2D(hiPt) || prev.equals2D(next)) return false; int disc = computeOrientation(prev, hiPt, next);
public boolean isInside(Coordinate pt) { return CGAlgorithms.isPointInRing(pt, pts); } }