Class SplinePather
Path2
objects from a Spline2
.
In order to draw a cubic spline, we must first convert it to a Path2
object. All of our rendering tools are designed around the basic Path2 class.
In addition to generating a Path2 for the spline path, this class can also
generate Poly2
objects for UI elements such as handles and anchors.
As with many of our factories, the methods are broken up into three phases: initialization, calculation, and materialization. To use the factory, you first set the data (in this case a pointer to a Spline2) with the initialization methods. You then call the calculation method. Finally, you use the materialization methods to access the data in several different ways. This division allows us to support multithreaded calculation if the data generation takes too long. However, not that this factory keeps a pointer to the spline, and it is unsafe to modify the spline while the calculation is ongoing. If you do multithread the calculation, you should force the user to copy the spline first.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a spline approximator with no spline data.SplinePather
(Spline2 spline) Creates a spline approximator with the given spline as its initial data. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Performs an approximation of the current splinevoid
clear()
Clears all internal data, including the spline data.getAnchors
(float radius) Returns aPoly2
representing handles for the anchor pointsgetAnchors
(float radius, int segments) Returns aPoly2
representing handles for the anchor pointsgetHandle
(float radius) Returns a Poly2 representing handles for the tangent pointsgetHandle
(float radius, int segments) Returns aPoly2
representing handles for the tangent pointscom.badlogic.gdx.utils.FloatArray
Returns a list of normals for a polygon approximationfloat[]
Returns a list of parameters for a path approximationgetPath()
Returns a new path approximating this spline.Returns an expanded version of this splinecom.badlogic.gdx.utils.FloatArray
Returns a list of tangents for a path approximationvoid
reset()
Clears all internal data, but still maintains a reference to the spline.void
Sets the given spline as the data for this spline approximator.
-
Constructor Details
-
SplinePather
public SplinePather()Creates a spline approximator with no spline data. -
SplinePather
Creates a spline approximator with the given spline as its initial data.- Parameters:
spline
- The spline to approximate
-
-
Method Details
-
set
Sets the given spline as the data for this spline approximator.This method resets all interal data. You will need to reperform the calculation before accessing data.
- Parameters:
spline
- The spline to approximate
-
reset
public void reset()Clears all internal data, but still maintains a reference to the spline.Use this method when you want to reperform the approximation at a different resolution.
-
clear
public void clear()Clears all internal data, including the spline data.When this method is called, you will need to set a new spline before calling calculate.
-
calculate
public void calculate()Performs an approximation of the current splineA polygon approximation is creating by recursively calling de Castlejau's until we reach a stopping condition.
Hence this method is not thread-safe. If you are using this method in a task thread, you should copy the spline first before starting the calculation.
-
getPath
Returns a new path approximating this spline.The
Path2
indices will define a path traversing the vertices of the spline. The indices will define a closed path if the spline is itself closed, and an open path otherwise.The resolution of the path is determined by the
calculate()
method. See the description of that method for the various options. If calculate has not been called, this method will create a path from the control points on the original spline.- Returns:
- a new polygon approximating this spline.
-
getParameters
public float[] getParameters()Returns a list of parameters for a path approximationThe parameters correspond to the generating values in the spline polynomial. That is, if you evaluate the polynomial on the parameters, {via
Spline2.getPoint(float)
, you will get the points in the approximating polygon.The resolution of the path is determined by the
calculate()
method. See the description of that method for the various options. If calculate has not been called, this method will choose parameters for the control points on the original spline.- Returns:
- a list of parameters for a polygon approximation
-
getTangents
public com.badlogic.gdx.utils.FloatArray getTangents()Returns a list of tangents for a path approximationThese tangent vectors are presented in control point order. First, we have the right tangent of the first point, then the left tangent of the second point, then the right, and so on. Hence if the polygon contains n points, this method will return 2(n-1) tangents.
The resolution of the path is determined by the
calculate()
method. See the description of that method for the various options. If calculate has not been called, this method will choose tangents for the control points on the original spline. This latter option is useful when you want to draw a UI for the control point tangents.- Returns:
- a list of tangents for a polygon approximation
-
getNormals
public com.badlogic.gdx.utils.FloatArray getNormals()Returns a list of normals for a polygon approximationThere is one normal per control point. If polygon contains n points, this method will also return n normals. The normals are determined by the right tangents. If the spline is open, then the normal of the last point is determined by its left tangent.
The resolution of the path is determined by the
calculate()
method. See the description of that method for the various options. If calculate has not been called, this method will choose normals for the control points on the original spline. This latter option is useful when you want to draw a UI for the control point normals.- Returns:
- a list of normals for a polygon approximation
-
getAnchors
Returns aPoly2
representing handles for the anchor pointsThis method returns a collection of vertex information for handles at the anchor points. Handles are circular shapes of a given radius. This information may be drawn to provide a visual representation of the anchor points (as seen in Adobe Illustrator).
The resolution of the path is determined by the
calculate()
method. See the description of that method for the various options. If calculate has not been called, this method will choose anchors for the control points on the original spline. This latter option is useful when you want to draw a UI for the original control points.- Parameters:
radius
- the radius of each handlesegments
- the number of segments in the handle "circle"- Returns:
- a Poly2 representing handles for the anchor points
-
getAnchors
Returns aPoly2
representing handles for the anchor pointsThis method returns a collection of vertex information for handles at the anchor points. Handles are circular shapes of a given radius. This information may be drawn to provide a visual representation of the anchor points (as seen in Adobe Illustrator).
The resolution of the path is determined by the
calculate()
method. See the description of that method for the various options. If calculate has not been called, this method will choose anchors for the control points on the original spline. This latter option is useful when you want to draw a UI for the original control points.- Parameters:
radius
- the radius of each handle- Returns:
- a Poly2 representing handles for the anchor points
-
getHandle
Returns aPoly2
representing handles for the tangent pointsThis method returns vertex information for handles at the tangent points. Handles are circular shapes of a given radius. This information may be passed to a PolygonNode to provide a visual representation of the tangent points (as seen in Adobe Illustrator).
The resolution of the path is determined by the
calculate()
method. See the description of that method for the various options. If calculate has not been called, this method will choose the tangents from the control points on the original spline. This latter option is useful when you want to draw a UI for the original tangent points.- Parameters:
radius
- the radius of each handlesegments
- the number of segments in the handle "circle"- Returns:
- a Poly2 representing handles for the tangent points
-
getHandle
Returns a Poly2 representing handles for the tangent pointsThis method returns vertex information for handles at the tangent points. Handles are circular shapes of a given radius. This information may be passed to a PolygonNode to provide a visual representation of the tangent points (as seen in Adobe Illustrator).
The resolution of the path is determined by the
calculate()
method. See the description of that method for the various options. If calculate has not been called, this method will choose the tangents from the control points on the original spline. This latter option is useful when you want to draw a UI for the original tangent points.- Parameters:
radius
- the radius of each handle- Returns:
- a Poly2 representing handles for the tangent points
-
getRefinement
Returns an expanded version of this splineWhen we use de Castlejau's to approximate the spline, it produces a list of control points that are geometrically equal to this spline (e.g. ignoring parameterization). Instead of flattening this information to a polygon, this method presents this data as a new spline.
The resolution of the path is determined by the
calculate()
method. See the description of that method for the various options. If calculate has not been called, this method will copy the original spline.- Returns:
- an expanded version of this spline
-