The line colors are not significant - they are just used to make it obvious that lines cross rather than join. Bidirectional arrows denote pairs of transitions (essentially two unidirectional lines that overlap).
The sequence of allowed transitions and their effects are as follows:
- The first point's type is either
MOVE_TO
orMOVE_TO_NEXT
. Only a single point of this type is allowed. - A segment containing only
CONTROL
points (0, 1, or 2) must end with aSEG_END
point or aCLOSE
point. These represent straight lines, quadratic Bézier curves, and cubic Bézier curves respectively. The control points must be preceded by a point whose type isMOVETO
,SEG_END
orSEG_END_PREV
. - An open spline segment starts with either the end of another
segment or a point whose type is either
MOVE_TO
orMOVE_TO_NEXT
. An open spline ends with a point whose type isSEG_END
orSEG_END_PREV
, and contains points (at least one) whose types are eitherSPLINE
orSPLINE_FUNCTION
. The sequence ofSPLINE
and/orSPLINE_FUNCTION
points may be followed by aCONTROL
or preceded by aCONTROL
in order to set the first and last control point on the segment to specific values. - A closed subpath is indicated by a point whose type is
CLOSE
. ABasicSplinePathBUilder
allows at most one of these points, and no point may follow a point whose type isCLOSE
. If this point is preceded by a point of typeSEG_END
orSEG_END_PREV
, a straight line (unless the line will have a length of zero) will connect the previous point to the point specified by the last point whose type isMOVE_TO
orMOVE_TO_NEXT
. If a sequence ofSPLINE
orSPLINE_FUNCTION
points is terminated by aCLOSE
point, the point immediately before the sequence must have a type ofMOVE_TO
orMOVE_TO_NEXT
, and a closed spline will be generated consisting of this initial point and the spline points.
There more more constraints on the sequence of points than for
the class SplinePathBuilder
because a
BasicSplinePath2D
does not allow discontinuous paths, and closed
paths must be cyclic so that the path parameter is unbounded both from
above and below. These paths are provided to support cases where one
uses a path to describe the motion of an object, not just for drawing.
An instance of SplinePathBuilder can be constructed by passing it
an instance of ScriptingContext
such
as the variable scripting
provided by the
scrunner
command. When this is done, one can use
the methods AbstractSplinePathBuilder.configure(Object)
or
AbstractSplinePathBuilder.configure(Object,Object)
to configure a
spline-path builder. For the two-argument case, the first argument
is a winding rule. This can be the string "WIND_EVEN_ODD"
or "WIND_NON_ZERO"
. Alternatively it can be a constant
whose type is SplinePathBuilder.WindingRule
.
The last argument (the only one for the one-argument case) will be
a specification for the path. This specification is an array or list
of objects that have the following attributes:
type
. This can be the string"CLOSE"
,"MOVE_TO"
,"SEG_END"
,"CONTROL"
, or"SPLINE"
. Alternatively it can a constant whose type isSplinePathBuilder.CPointType
.x
. The X coordinate of a control point. This is ignored, and may be omitted, when the type isCLOSE
.y
. The Y coordinate of a control point. This is ignored, and may be omitted, when the type isCLOSE
.
For example, with ESP, implemented by scrunner
, the following
statements can be used to configure a path:
The programimport (org.bzdev.geom.SplinePathBuilder); var path1 = [ {type: "MOVE_TO", x: 20.0, y: 30.0}, {type: "SEG_END", x: 50.0, y: 60.0}]; var path2 = [ {type: "MOVE_TO", x: 120.0, y: 130.0}, {type: "SEG_END", x: 150.0, y: 160.0}]; var pathspec = [path1, path2]; var pb = new SplinePathBuilder(scripting); pb.configure("WIND_EVEN_ODD", pathspec); var path = pb.getPath();
epts
can generate the path specifications while
providing a graphical user interface to aid in constructing the
paths.-
Nested Class Summary
Nested classes/interfaces inherited from class org.bzdev.scripting.ScriptingContext
ScriptingContext.BindingSwapper
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.Constructor providing a scripting context. -
Method Summary
Methods inherited from class org.bzdev.geom.AbstractSplinePathBuilder
append, append, append, configure, configure, constantCLOSE, constantCONTROL, constantMOVE_TO, constantMOVE_TO_NEXT, constantSEG_END, constantSEG_END_NEXT, constantSEG_END_PREV, constantSPLINE, constantSPLINE_FUNCTION, constantWIND_EVEN_ODD, constantWIND_NON_ZERO, createCPointClose, createCPointControl, createCPointMoveTo, createCPointMoveToNext, createCPointSegEnd, createCPointSegEndNext, createCPointSegEndPrev, createCPointSpline, createCPointSplineFunction, getCPoints, getNumericalLimit, initPath, initPath, initPath, initPath, modifyCPoints, modifyCPoints, setNumericalLimit
Methods inherited from class org.bzdev.scripting.ScriptingContext
callScriptFunction, callScriptFunction, callScriptMethod, callScriptMethod, containsScriptObject, createBindings, createBindingSwapper, createScriptEngine, doGetDefaultBindings, doGetScriptEngine, doGetScriptLanguage, doScriptPrivileged, evalScript, evalScript, evalScript, evalScript, getErrorWriter, getNames, getReader, getScriptLanguage, getScriptObject, getWriter, hasScriptEngine, invokePrivateFunction, invokePrivateFunction, putScriptObject, setErrorWriter, setReader, setWriter, usingGraalVM
-
Constructor Details
-
BasicSplinePathBuilder
public BasicSplinePathBuilder()Constructor. -
BasicSplinePathBuilder
Constructor providing a scripting context.- Parameters:
parent
- the scripting context used to support scripting
-
-
Method Details
-
getPath
Get the path that was build.- Overrides:
getPath
in classAbstractSplinePathBuilder<BasicSplinePath2D>
- Returns:
- the path
-