Class BasicSplinePathBuilder


public class BasicSplinePathBuilder extends AbstractSplinePathBuilder<BasicSplinePath2D>
BasicSplinePath2D builder. This class allows a BasicSplinePath2D to be specified via a table - an array of entries, each of which specifies a point along the path (including control points) and the type of line segment. The sequence of points, based on their types, is shown in the following diagram, where a transition corresponds to adding a new point to the BasicSplinePath2D builder:

UML diagram

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 or MOVE_TO_NEXT. Only a single point of this type is allowed.
  • A segment containing only CONTROL points (0, 1, or 2) must end with a SEG_END 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 is MOVETO, SEG_END or SEG_END_PREV.
  • An open spline segment starts with either the end of another segment or a point whose type is either MOVE_TO or MOVE_TO_NEXT. An open spline ends with a point whose type is SEG_END or SEG_END_PREV, and contains points (at least one) whose types are either SPLINE or SPLINE_FUNCTION.
  • A closed subpath is indicated by a point whose type is CLOSE. A BasicSplinePathBUilder allows at most one of these points, and no point may follow a point whose type is CLOSE. If this point is preceded by a point of type SEG_END or SEG_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 is MOVE_TO or MOVE_TO_NEXT. If a sequence of SPLINE or SPLINE_FUNCTION points is terminated by a CLOSE point, the point immediately before the sequence must have a type of MOVE_TO or MOVE_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 is SplinePathBuilder.CPointType.
  • x. The X coordinate of a control point. This is ignored, and may be omitted, when the type is CLOSE.
  • y. The Y coordinate of a control point. This is ignored, and may be omitted, when the type is CLOSE.
This list can also contain sublists, which will be traversed in depth-first order. The sequence of objects that appear must match the constraints shown in the figure above.

For example, with ECMAScript, scrunner the following statements can be used to configure a path:


     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];

     org.bzdev.geom.SplinePathBuilder pb =
        new org.bzdev.geom.SplinePathBuilder(scripting);

     pb.configure("WIND_EVEN_ODD", pathspec);
     var path = pb.getPath();
 
The program epts can generate the path specifications while providing a graphical user interface to aid in constructing the paths.
  • Constructor Details

    • BasicSplinePathBuilder

      public BasicSplinePathBuilder()
      Constructor.
    • BasicSplinePathBuilder

      public BasicSplinePathBuilder(ScriptingContext parent)
      Constructor providing a scripting context.
      Parameters:
      parent - the scripting context used to support scripting
  • Method Details