public static LineString removeRepeatedPoints(final LineString points) { final int axisCount = points.getAxisCount(); final List<Double> coordinates = new ArrayList<>(); double x = points.getX(0); double y = points.getY(0); coordinates.add(x); coordinates.add(y); for (int axisIndex = 2; axisIndex < axisCount; axisIndex++) { coordinates.add(points.getCoordinate(0, axisIndex)); } for (int i = 0; i < points.getVertexCount(); i++) { final double x1 = points.getX(i); final double y1 = points.getY(i); if (x != x1 || y != y1) { coordinates.add(x1); coordinates.add(y1); for (int axisIndex = 2; axisIndex < axisCount; axisIndex++) { coordinates.add(points.getCoordinate(i, axisIndex)); } x = x1; y = y1; } } return new LineStringDouble(axisCount, coordinates); }
public static int orientationIndex( final LineString ring, final int index1, final int index2, final int index) { return orientationIndex( ring.getX(index1), ring.getY(index1), ring.getX(index2), ring.getY(index2), ring.getX(index), ring.getY(index)); }
public static double angleToNext(final LineString points, final int i) { final double x1 = points.getX(i); final double y1 = points.getY(i); double x2; double y2; int j = i + 1; do { x2 = points.getX(j); y2 = points.getY(j); j++; } while (x1 == x2 && y1 == y2 && j < points.getVertexCount()); final double angle = Angle.angle2d(x1, y1, x2, y2); return angle; }
public static double angleToPrevious(final LineString points, final int i) { if (i > 0) { final double x1 = points.getX(i); final double y1 = points.getY(i); double x2; double y2; int j = i - 1; do { x2 = points.getX(j); y2 = points.getY(j); j--; } while (x1 == x2 && y1 == y2 && j > -1); final double angle = Angle.angle2d(x1, y1, x2, y2); return angle; } else { throw new IllegalArgumentException("Index must be > 0 to calculate previous angle"); } }
public static int appendReverse( final int axisCount, final LineString source, final int sourceStartIndex, final double[] targetCoordinates, final int targetStartIndex, final int vertexCount) { int coordIndex = targetStartIndex; final int sourceVertexCount = source.getVertexCount(); double previousX; double previousY; if (targetStartIndex == 0) { previousX = Double.NaN; previousY = Double.NaN; } else { previousX = targetCoordinates[(targetStartIndex - 1) * axisCount]; previousY = targetCoordinates[(targetStartIndex - 1) * axisCount + 1]; } int coordinateIndex = coordIndex * axisCount; int sourceIndex = sourceVertexCount - 1 - sourceStartIndex; for (int i = 0; i < vertexCount; i++) { final double x = source.getX(sourceIndex); final double y = source.getY(sourceIndex); if (x != previousX || y != previousY) { targetCoordinates[coordinateIndex++] = x; targetCoordinates[coordinateIndex++] = y; for (int axisIndex = 2; axisIndex < axisCount; axisIndex++) { final double coordinate = source.getCoordinate(sourceIndex, axisIndex); targetCoordinates[coordinateIndex++] = coordinate; } coordIndex++; } sourceIndex--; previousX = x; previousY = y; } return coordIndex; }