CGAlgorithms.computeOrientation(firstCoord, midCoord, lastCoord);
&& (CGAlgorithms.isPointInRing(testPt, coordList) || (pointInList(testPt, coordList)))) { isContained = true;
if (CGAlgorithms.signedArea(ring.getCoordinateSequence()) > 0.0) holes.add(ring); else
/** * Create a nice Polygon from the given Polygon. Will ensure that shells are clockwise and holes * are counter-clockwise. Capiche? * * @param p The Polygon to make "nice". * @return The "nice" Polygon. */ public static final Polygon makeGoodShapePolygon(Polygon p) { GeometryFactory factory = p.getFactory(); LinearRing outer; LinearRing[] holes = new LinearRing[p.getNumInteriorRing()]; Coordinate[] coords; coords = p.getExteriorRing().getCoordinates(); if (CGAlgorithms.isCCW(coords)) { outer = reverseRing((LinearRing) p.getExteriorRing()); } else { outer = (LinearRing) p.getExteriorRing(); } for (int t = 0, tt = p.getNumInteriorRing(); t < tt; t++) { coords = p.getInteriorRingN(t).getCoordinates(); if (!(CGAlgorithms.isCCW(coords))) { holes[t] = reverseRing((LinearRing) p.getInteriorRingN(t)); } else { holes[t] = (LinearRing) p.getInteriorRingN(t); } } return factory.createPolygon(outer, holes); }
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); }
private int getOrientationIndex(LineString ls) { return CGAlgorithms.orientationIndex( ls.getCoordinateN(0), ls.getCoordinateN(1), ls.getCoordinateN(2)); }
} else if (j == max - 2 && !closed) { double distancePointLine = CGAlgorithms.distancePointLine(c4, c1, c2); if (distancePointLine < abs(offset) / 10) { c2.x = c4.x;
List<?> toList(Polygon p) { BasicDBList l = new BasicDBList(); if (!CGAlgorithms.isCCW(p.getExteriorRing().getCoordinates())) { l.add(toList(p.getExteriorRing().reverse().getCoordinates())); } else { l.add(toList(p.getExteriorRing().getCoordinateSequence())); } for (int i = 0; i < p.getNumInteriorRing(); i++) { l.add(toList(p.getInteriorRingN(i).getCoordinateSequence())); } return l; } }
/** * Computes the orientation of a point q to the directed line segment p1-p2. * The orientation of a point relative to a directed line segment indicates * which way you turn to get to q after travelling from p1 to p2. * * @param p1 the first vertex of the line segment * @param p2 the second vertex of the line segment * @param q the point to compute the relative orientation of * @return 1 if q is counter-clockwise from p1-p2, * or -1 if q is clockwise from p1-p2, * or 0 if q is collinear with p1-p2 */ public static int computeOrientation(Coordinate p1, Coordinate p2, Coordinate q) { return orientationIndex(p1, p2, q); }
/** * 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 = distancePointLine(p, line[i], line[i + 1]); if (dist < minDistance) { minDistance = dist; } } return minDistance; }
/** * INTERNAL: Returns a Rectangle of the JTS {@link Envelope} (bounding box) of the given {@code geom}. This asserts * that {@link Geometry#isRectangle()} is true. This method reacts to the {@link DatelineRule} setting. * @param geom non-null * @return the equivalent Rectangle. */ public Rectangle makeRectFromRectangularPoly(Geometry geom) { // TODO although, might want to never convert if there's a semantic difference (e.g. // geodetically)? Should have a setting for that. assert geom.isRectangle(); Envelope env = geom.getEnvelopeInternal(); boolean crossesDateline = false; if (ctx.isGeo() && getDatelineRule() != DatelineRule.none) { if (getDatelineRule() == DatelineRule.ccwRect) { // If JTS says it is clockwise, then it's actually a dateline crossing rectangle. crossesDateline = !CGAlgorithms.isCCW(geom.getCoordinates()); } else { crossesDateline = env.getWidth() > 180; } } if (crossesDateline) return rect(env.getMaxX(), env.getMinX(), env.getMinY(), env.getMaxY()); else return rect(env.getMinX(), env.getMaxX(), env.getMinY(), env.getMaxY()); }
/** *@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 (CGAlgorithms.computeOrientation(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; }
private boolean triangleContainsPoint(Triangle tri, Coordinate pt) { return CGAlgorithms.isPointInRing(pt, new Coordinate[]{tri.p0, tri.p1, tri.p2, tri.p0}); }
double area = CGAlgorithms.signedArea(r.getCoordinates());
return distancePointLine(A, C, D); if (C.equals(D)) return distancePointLine(D, A, B); distancePointLine(A, C, D), distancePointLine(B, C, D), distancePointLine(C, A, B), distancePointLine(D, A, B));
private boolean isCCW(int idTri) { return CGAlgorithms.isCCW(inputTriangles.getGeometryN(idTri).getCoordinates()); }
double dyq = q.y - o.y; int orient = CGAlgorithms.computeOrientation(o, p, q);
if (!CGAlgorithms.isPointInRing(inputPt, polyPts)) { reducedSet.add(inputPt);
double area = CGAlgorithms.signedArea(r.getCoordinates());
/** * Constructor * @param p0 First vertex * @param p1 Second vertex * @param p2 Third vertex * @param m1 First vertex attribute * @param m2 Second vertex attribute * @param m3 Third vertex attribute */ public TriMarkers(Coordinate p0, Coordinate p1, Coordinate p2, double m1, double m2, double m3) { super(p0, p1, p2); if (!CGAlgorithms.isCCW(this.getRing())) { this.setCoordinates(p2, p1, p0); this.m1 = m3; this.m3 = m1; } else { this.m1 = m1; this.m3 = m3; } this.m2 = m2; }