public DepthSegment(LineSegment seg, int depth) { // input seg is assumed to be normalized upwardSeg = new LineSegment(seg); //upwardSeg.normalize(); this.leftDepth = depth; } /**
/** * Creates a new instance for the given points. * * @param p0 the start point * @param p1 the end point */ public Segment(Coordinate p0, Coordinate p1) { ls = new LineSegment(p0, p1); }
public LocateFailureException(LineSegment seg) { super( "Locate failed to converge (at edge: " + seg + "). Possible causes include invalid Subdivision topology or very close sites"); this.seg = new LineSegment(seg); }
/** * Creates a new instance for the given points, with associated external data. * * @param p0 the start point * @param p1 the end point * @param data an external data object */ public Segment(Coordinate p0, Coordinate p1, Object data) { ls = new LineSegment(p0, p1); this.data = data; }
private void updatePts(Coordinate p, Coordinate seg0, Coordinate seg1) { minPts[0] = p; LineSegment seg = new LineSegment(seg0, seg1); minPts[1] = new Coordinate(seg.closestPoint(p)); }
private void updateClearance(double candidateValue, Coordinate p, Coordinate seg0, Coordinate seg1) { if (candidateValue < minClearance) { minClearance = candidateValue; minClearancePts[0] = new Coordinate(p); LineSegment seg = new LineSegment(seg0, seg1); minClearancePts[1] = new Coordinate(seg.closestPoint(p)); } }
private void addLine(Coordinate[] pts) { for (int i = 1; i < pts.length; i++) { LineSegment seg = new LineSegment(pts[i-1], pts[i]); double min = Math.min(seg.p0.y, seg.p1.y); double max = Math.max(seg.p0.y, seg.p1.y); index.insert(min, max, seg); } }
public LocateFailureException(String msg, LineSegment seg) { super(msgWithSpatial(msg, seg)); this.seg = new LineSegment(seg); }
private static LineSegment computeSegmentForLine(double a, double b, double c) { Coordinate p0; Coordinate p1; /* * Line eqn is ax + by = c * Slope is a/b. * If slope is steep, use y values as the inputs */ if (Math.abs(b) > Math.abs(a)) { p0 = new Coordinate(0.0, c/b); p1 = new Coordinate(1.0, c/b - a/b); } else { p0 = new Coordinate(c/a, 0.0); p1 = new Coordinate(c/a - b/a, 1.0); } return new LineSegment(p0, p1); } }
/** * Compute the width information for a ring of {@link Coordinate}s. * Leaves the width information in the instance variables. * * @param pts */ private void computeConvexRingMinDiameter(Coordinate[] pts) { // for each segment in the ring minWidth = Double.MAX_VALUE; int currMaxIndex = 1; LineSegment seg = new LineSegment(); // compute the max distance for all segments in the ring, and pick the minimum for (int i = 0; i < pts.length - 1; i++) { seg.p0 = pts[i]; seg.p1 = pts[i + 1]; currMaxIndex = findMaxPerpDistance(pts, seg, currMaxIndex); } }
private int findFurthestPoint(Coordinate[] pts, int i, int j, double[] maxDistance) { LineSegment seg = new LineSegment(); seg.p0 = pts[i]; seg.p1 = pts[j]; double maxDist = -1.0; int maxIndex = i; for (int k = i + 1; k < j; k++) { Coordinate midPt = pts[k]; double distance = seg.distance(midPt); if (distance > maxDist) { maxDist = distance; maxIndex = k; } } maxDistance[0] = maxDist; return maxIndex; }
public LineSegment getSquareBaseLine() { double radius = getRadius(); Coordinate centre = getCentre(); Coordinate p0 = new Coordinate(centre.x - radius, centre.y - radius); Coordinate p1 = new Coordinate(centre.x + radius, centre.y - radius); return new LineSegment(p0, p1); }
private LineSegment flatten(int start, int end) { // make a new segment for the simplified geometry Coordinate p0 = linePts[start]; Coordinate p1 = linePts[end]; LineSegment newSeg = new LineSegment(p0, p1); // update the indexes remove(line, start, end); outputIndex.add(newSeg); return newSeg; }
/** * Creates a {@link LineSegment} representing the * geometry of this edge. * * @return a LineSegment */ public LineSegment toLineSegment() { return new LineSegment(vertex.getCoordinate(), dest().getCoordinate()); }
/** * Gets a {@link LineSegment} representing the segment of the * given linear {@link Geometry} which contains this location. * * @param linearGeom a linear geometry * @return the <tt>LineSegment</tt> containing the location */ public LineSegment getSegment(Geometry linearGeom) { LineString lineComp = (LineString) linearGeom.getGeometryN(componentIndex); Coordinate p0 = lineComp.getCoordinateN(segmentIndex); // check for endpoint - return last segment of the line if so if (segmentIndex >= lineComp.getNumPoints() - 1) { Coordinate prev = lineComp.getCoordinateN(lineComp.getNumPoints() - 2); return new LineSegment(prev, p0); } Coordinate p1 = lineComp.getCoordinateN(segmentIndex + 1); return new LineSegment(p0, p1); }
private int findMaxPerpDistance(Coordinate[] pts, LineSegment seg, int startIndex) { double maxPerpDistance = seg.distancePerpendicular(pts[startIndex]); double nextPerpDistance = maxPerpDistance; int maxIndex = startIndex; int nextIndex = maxIndex; while (nextPerpDistance >= maxPerpDistance) { maxPerpDistance = nextPerpDistance; maxIndex = nextIndex; nextIndex = nextIndex(pts, maxIndex); nextPerpDistance = seg.distancePerpendicular(pts[nextIndex]); } // found maximum width for this segment - update global min dist if appropriate if (maxPerpDistance < minWidth) { minPtIndex = maxIndex; minWidth = maxPerpDistance; minWidthPt = pts[minPtIndex]; minBaseSeg = new LineSegment(seg); // System.out.println(minBaseSeg); // System.out.println(minWidth); } return maxIndex; }
private void computeMinDistanceLineLine(LineString line0, LineString line1, boolean flip) { Coordinate[] coord0 = line0.getCoordinates(); Coordinate[] coord1 = line1.getCoordinates(); // brute force approach! for (int i = 0; i < coord0.length - 1; i++) { for (int j = 0; j < coord1.length - 1; j++) { double dist = CGAlgorithms3D.distanceSegmentSegment(coord0[i], coord0[i + 1], coord1[j], coord1[j + 1]); if (dist < minDistance) { minDistance = dist; // TODO: compute closest pts in 3D LineSegment seg0 = new LineSegment(coord0[i], coord0[i + 1]); LineSegment seg1 = new LineSegment(coord1[j], coord1[j + 1]); Coordinate[] closestPt = seg0.closestPoints(seg1); updateDistance(dist, new GeometryLocation(line0, i, closestPt[0]), new GeometryLocation(line1, j, closestPt[1]), flip ); } if (isDone) return; } } }
private void computeMinDistanceLinePoint(LineString line,Point point, boolean flip) { Coordinate[] lineCoord = line.getCoordinates(); Coordinate coord = point.getCoordinate(); // brute force approach! for (int i = 0; i < lineCoord.length - 1; i++) { double dist = CGAlgorithms3D.distancePointSegment(coord, lineCoord[i], lineCoord[i + 1]); if (dist < minDistance) { LineSegment seg = new LineSegment(lineCoord[i], lineCoord[i + 1]); Coordinate segClosestPoint = seg.closestPoint(coord); updateDistance(dist, new GeometryLocation(line, i, segClosestPoint), new GeometryLocation(point, 0, coord), flip); } if (isDone) return; } }
private void computeMinDistance(LineString line, Point pt, GeometryLocation[] locGeom) { if (line.getEnvelopeInternal().distance(pt.getEnvelopeInternal()) > minDistance) return; Coordinate[] coord0 = line.getCoordinates(); Coordinate coord = pt.getCoordinate(); // brute force approach! for (int i = 0; i < coord0.length - 1; i++) { double dist = CGAlgorithms.distancePointLine( coord, coord0[i], coord0[i + 1] ); if (dist < minDistance) { minDistance = dist; LineSegment seg = new LineSegment(coord0[i], coord0[i + 1]); Coordinate segClosestPoint = seg.closestPoint(coord); locGeom[0] = new GeometryLocation(line, i, segClosestPoint); locGeom[1] = new GeometryLocation(pt, 0, coord); } if (minDistance <= terminateDistance) return; } }
private double indexOfFromStart(Coordinate inputPt, double minIndex) { double minDistance = Double.MAX_VALUE; double ptMeasure = minIndex; double segmentStartMeasure = 0.0; LineSegment seg = new LineSegment(); LinearIterator it = new LinearIterator(linearGeom); while (it.hasNext()) { if (! it.isEndOfLine()) { seg.p0 = it.getSegmentStart(); seg.p1 = it.getSegmentEnd(); double segDistance = seg.distance(inputPt); double segMeasureToPt = segmentNearestMeasure(seg, inputPt, segmentStartMeasure); if (segDistance < minDistance && segMeasureToPt > minIndex) { ptMeasure = segMeasureToPt; minDistance = segDistance; } segmentStartMeasure += seg.getLength(); } it.next(); } return ptMeasure; }