@Test public void userDataIsPreservedFromInput() throws Exception { PolygonSmoother smoother = new PolygonSmoother(gf); Polygon input = (Polygon) reader.read("POLYGON((0 0, 0 100, 100 100, 100 0, 0 0))"); Object userData = "Some data"; input.setUserData(userData); Polygon output = smoother.smooth(input, 0.0); assertNotNull(output.getUserData()); assertEquals(userData, output.getUserData()); }
public Polygon smooth(Polygon inputPoly, double alpha) { Coordinate[] coords = inputPoly.getExteriorRing().getCoordinates(); final int N = coords.length - 1; final int LAST = N - 1; Coordinate[][] controlPoints = getControlPoints(coords, N, alpha); List<Coordinate> smoothCoords = CollectionFactory.list(); double dist; for (int i = 0; i < N; i++) { int next = (i + 1) % N; dist = coords[i].distance(coords[next]); if (dist < control.getMinLength()) { smoothCoords.add(new Coordinate(coords[i])); if (i == LAST) { smoothCoords.add(new Coordinate(coords[0])); } } else { int smoothN = control.getNumVertices(dist); Coordinate[] segment = cubicBezier( coords[i], coords[next], controlPoints[i][1], controlPoints[next][0], smoothN); int copyN = i == LAST ? segment.length : segment.length - 1; for (int k = 0; k < copyN; k++) { smoothCoords.add(segment[k]); } } } LinearRing shell = geomFactory.createLinearRing(smoothCoords.toArray(new Coordinate[0])); Polygon smoothedPoly = geomFactory.createPolygon(shell, null); smoothedPoly.setUserData(inputPoly.getUserData()); return smoothedPoly; }
PolygonSmoother extends AbstractSmoother { public Polygon smooth(Polygon inputPoly, double alpha) { Coordinate[] coords = inputPoly.getExteriorRing().getCoordinates(); final int N = coords.length - 1; final int LAST = N - 1; Coordinate[][] controlPoints = getControlPoints(coords, N, alpha); List<Coordinate> smoothCoords = CollectionFactory.list(); double dist; for (int i = 0; i < N; i++) { int next = (i + 1) % N; dist = coords[i].distance(coords[next]); if (dist < control.getMinLength()) { smoothCoords.add(new Coordinate(coords[i])); if (i == LAST) { smoothCoords.add(new Coordinate(coords[0])); } } else { int smoothN = control.getNumVertices(dist); Coordinate[] segment = cubicBezier( coords[i], coords[next], controlPoints[i][1], controlPoints[next][0], smoothN); int copyN = i == LAST ? segment.length : segment.length - 1; for (int k = 0; k < copyN; k++) { smoothCoords.add(segment[k]); } } } LinearRing shell = geomFactory.createLinearRing(smoothCoords.toArray(new Coordinate[0])); Polygon smoothedPoly = geomFactory.createPolygon(shell, null); smoothedPoly.setUserData(inputPoly.getUserData()); return smoothedPoly; } }
PolygonSmoother extends AbstractSmoother { public Polygon smooth(Polygon inputPoly, double alpha) { Coordinate[] coords = inputPoly.getExteriorRing().getCoordinates(); final int N = coords.length - 1; final int LAST = N - 1; Coordinate[][] controlPoints = getControlPoints(coords, N, alpha); List<Coordinate> smoothCoords = CollectionFactory.list(); double dist; for (int i = 0; i < N; i++) { int next = (i + 1) % N; dist = coords[i].distance(coords[next]); if (dist < control.getMinLength()) { smoothCoords.add(new Coordinate(coords[i])); if (i == LAST) { smoothCoords.add(new Coordinate(coords[0])); } } else { int smoothN = control.getNumVertices(dist); Coordinate[] segment = cubicBezier( coords[i], coords[next], controlPoints[i][1], controlPoints[next][0], smoothN); int copyN = i == LAST ? segment.length : segment.length - 1; for (int k = 0; k < copyN; k++) { smoothCoords.add(segment[k]); } } } LinearRing shell = geomFactory.createLinearRing(smoothCoords.toArray(new Coordinate[0])); Polygon smoothedPoly = geomFactory.createPolygon(shell, null); smoothedPoly.setUserData(inputPoly.getUserData()); return smoothedPoly; } PolygonSmoother();  PolygonSmoother(GeometryFactory geomFactory); }
PolygonSmoother extends AbstractSmoother { public Polygon smooth(Polygon inputPoly, double alpha) { Coordinate[] coords = inputPoly.getExteriorRing().getCoordinates(); final int N = coords.length - 1; final int LAST = N - 1; Coordinate[][] controlPoints = getControlPoints(coords, N, alpha); List<Coordinate> smoothCoords = CollectionFactory.list(); double dist; for (int i = 0; i < N; i++) { int next = (i + 1) % N; dist = coords[i].distance(coords[next]); if (dist < control.getMinLength()) { smoothCoords.add(new Coordinate(coords[i])); if (i == LAST) { smoothCoords.add(new Coordinate(coords[0])); } } else { int smoothN = control.getNumVertices(dist); Coordinate[] segment = cubicBezier( coords[i], coords[next], controlPoints[i][1], controlPoints[next][0], smoothN); int copyN = i == LAST ? segment.length : segment.length - 1; for (int k = 0; k < copyN; k++) { smoothCoords.add(segment[k]); } } } LinearRing shell = geomFactory.createLinearRing(smoothCoords.toArray(new Coordinate[0])); Polygon smoothedPoly = geomFactory.createPolygon(shell, null); smoothedPoly.setUserData(inputPoly.getUserData()); return smoothedPoly; } PolygonSmoother();  PolygonSmoother(GeometryFactory geomFactory); Polygon smooth(Polygon inputPoly, double alpha); }
PolygonSmoother extends AbstractSmoother { public Polygon smooth(Polygon inputPoly, double alpha) { Coordinate[] coords = inputPoly.getExteriorRing().getCoordinates(); final int N = coords.length - 1; final int LAST = N - 1; Coordinate[][] controlPoints = getControlPoints(coords, N, alpha); List<Coordinate> smoothCoords = CollectionFactory.list(); double dist; for (int i = 0; i < N; i++) { int next = (i + 1) % N; dist = coords[i].distance(coords[next]); if (dist < control.getMinLength()) { smoothCoords.add(new Coordinate(coords[i])); if (i == LAST) { smoothCoords.add(new Coordinate(coords[0])); } } else { int smoothN = control.getNumVertices(dist); Coordinate[] segment = cubicBezier( coords[i], coords[next], controlPoints[i][1], controlPoints[next][0], smoothN); int copyN = i == LAST ? segment.length : segment.length - 1; for (int k = 0; k < copyN; k++) { smoothCoords.add(segment[k]); } } } LinearRing shell = geomFactory.createLinearRing(smoothCoords.toArray(new Coordinate[0])); Polygon smoothedPoly = geomFactory.createPolygon(shell, null); smoothedPoly.setUserData(inputPoly.getUserData()); return smoothedPoly; } PolygonSmoother();  PolygonSmoother(GeometryFactory geomFactory); Polygon smooth(Polygon inputPoly, double alpha);  }