@@ -68,6 +68,37 @@ public static Geometry bezierCurve(Geometry geom, double alpha, double skew) {
6868 return curve .getResult ();
6969 }
7070
71+ /**
72+ * Gets a linear geometry containing the generated control points
73+ * for the Bezier curve defined by the segments of the input and a parameter
74+ * controlling how curved the result should be, with a skew factor
75+ * affecting the curve shape at each vertex.
76+ *
77+ * @param geom the geometry defining the curve
78+ * @param alpha curvedness parameter (0 is linear, 1 is round, >1 is increasingly curved)
79+ * @return the line(s) containing the control points
80+ */
81+ public static Geometry controlPoints (Geometry geom , double alpha ) {
82+ CubicBezierCurve curve = new CubicBezierCurve (geom , alpha );
83+ return curve .getControlPoints ();
84+ }
85+
86+ /**
87+ * Gets a linear geometry containing the generated control points
88+ * for the Bezier curve defined by the segments of the input and a parameter
89+ * controlling how curved the result should be, with a skew factor
90+ * affecting the curve shape at each vertex.
91+ *
92+ * @param geom the geometry defining the curve
93+ * @param alpha curvedness parameter (0 is linear, 1 is round, >1 is increasingly curved)
94+ * @param skew the skew parameter (0 is none, positive skews towards longer side, negative towards shorter
95+ * @return the line(s) containing the control points
96+ */
97+ public static Geometry controlPoints (Geometry geom , double alpha , double skew ) {
98+ CubicBezierCurve curve = new CubicBezierCurve (geom , alpha , skew );
99+ return curve .getControlPoints ();
100+ }
101+
71102 /**
72103 * Creates a geometry of linearized Cubic Bezier Curves
73104 * defined by the segments of the input
@@ -157,7 +188,7 @@ public static Geometry bezierCurve(Geometry geom, Geometry controlPoints) {
157188 */
158189 public Geometry getResult () {
159190 bezierCurvePts = new Coordinate [numVerticesPerSegment ];
160- interpolationParam = computeIterpolationParameters (numVerticesPerSegment );
191+ interpolationParam = computeInterpolationParameters (numVerticesPerSegment );
161192
162193 return GeometryMapper .flatMap (inputGeom , 1 , new GeometryMapper .MapOp () {
163194
@@ -175,6 +206,35 @@ public Geometry map(Geometry geom) {
175206 });
176207 }
177208
209+ /**
210+ * Gets the computed control points for the Bezier curve.
211+ *
212+ * @return a linear geometry holding the control points
213+ */
214+ public Geometry getControlPoints () {
215+ bezierCurvePts = new Coordinate [numVerticesPerSegment ];
216+ interpolationParam = computeInterpolationParameters (numVerticesPerSegment );
217+
218+ return GeometryMapper .flatMap (inputGeom , 1 , new GeometryMapper .MapOp () {
219+
220+ @ Override
221+ public Geometry map (Geometry geom ) {
222+ if (geom instanceof LineString ) {
223+ Coordinate [] control = controlPoints (geom .getCoordinates (), false );
224+ return geom .getFactory ().createLineString (control );
225+ }
226+ if (geom instanceof Polygon ) {
227+ Polygon poly = (Polygon ) geom ;
228+ Coordinate [] control = controlPoints (poly .getExteriorRing ().getCoordinates (), true );
229+ //TODO: include holes as well
230+ return geom .getFactory ().createLineString (control );
231+ }
232+ //-- Points
233+ return geom .copy ();
234+ }
235+ });
236+ }
237+
178238 private LineString bezierLine (LineString ls ) {
179239 //-- can't curve a single segment
180240 if (ls .getNumPoints () <= 2 )
@@ -278,7 +338,7 @@ private void addCurve(Coordinate p0, Coordinate p1,
278338 * @param alpha determines the curviness
279339 * @return the control point array
280340 */
281- private Coordinate [] controlPoints (Coordinate [] coords , boolean isRing , double alpha , double skew ) {
341+ private static Coordinate [] controlPoints (Coordinate [] coords , boolean isRing , double alpha , double skew ) {
282342 int N = coords .length ;
283343 int start = 1 ;
284344 int end = N - 1 ;
@@ -351,7 +411,7 @@ private Coordinate[] controlPoints(Coordinate[] coords, boolean isRing, double a
351411 * @param coords
352412 * @param ctrl
353413 */
354- private void setLineEndControlPoints (Coordinate [] coords , Coordinate [] ctrl ) {
414+ private static void setLineEndControlPoints (Coordinate [] coords , Coordinate [] ctrl ) {
355415 int N = ctrl .length ;
356416 ctrl [0 ] = mirrorControlPoint (ctrl [1 ], coords [1 ], coords [0 ]);
357417 ctrl [N - 1 ] = mirrorControlPoint (ctrl [N - 2 ],
@@ -436,7 +496,7 @@ private void cubicBezier(final Coordinate p0,
436496 * @param n number of vertices
437497 * @return array of double[4] holding the parameter values
438498 */
439- private static double [][] computeIterpolationParameters (int n ) {
499+ private static double [][] computeInterpolationParameters (int n ) {
440500 double [][] param = new double [n ][4 ];
441501 for (int i = 0 ; i < n ; i ++) {
442502 double t = (double ) i / (n - 1 );
0 commit comments