TinyLine
v2.0

com.tinyline.tiny2d
Class TinyPath

java.lang.Object
  extended bycom.tinyline.tiny2d.TinyPath

public final class TinyPath
extends java.lang.Object

The TinyPath class represents a geometric path constructed from straight lines, and quadratic and cubic (Bézier) curves. Paths are used to represent lines, curves and regions. A path consists of a series of path segments. Path segments may be staright lines or quadratic and cubic(Bézier) curves. It can contain multiple subpaths.

Path operators and segments

Path segments operators are: moveTo, lineTo, curveTo, curveToCubic, closePath. As a result of an applying these segments operators the correspondent segments are created. The segments types are: TYPE_MOVETO, TYPE_LINETO, TYPE_CURVETO, TYPE CURVETO_CUBIC and TYPE_CLOSE.

Multiple subpaths can be expressed by using a "moveTo" segment operator to create a discontinuity in the geometry to move from the end of one subpath to the beginning of the next.

Version:
1.11

Author:
Andrew Girow

Field Summary
static byte TYPE_CLOSE
          The segment type constant for a closePath.
static byte TYPE_CURVETO
          The segment type constant for a curveTo.
static byte TYPE_CURVETO_CUBIC
          The segment type constant for a curveTo.
static byte TYPE_LINETO
          The segment type constant for a lineTo.
static byte TYPE_MOVETO
          The segment type constant for a moveTo.
 
Constructor Summary
TinyPath(int i)
          Constructs a new TinyPath object with the specified initial capacity to store path coordinates.
TinyPath(TinyPath tinypath)
          Constructs a new TinyPath object as a copy of the given source 'tinypath' object.
 
Method Summary
 void addPoint(int x, int y, byte t)
          Adds a segment to the TinyPath.
 void closePath()
          Closes the current subpath by drawing a straight line back to the coordinates of the last moveTo.
 void compact()
          Compacts the TinyPath object data storage.
 void curveTo(int x2, int y2, int x3, int y3)
          Adds a Bézier curve to the TinyPath between the current point to (x3,y3) using the current point and (x2,y2) as Bézier control point.
 void curveToCubic(int x1, int y1, int x2, int y2, int x3, int y3)
          Adds a Bézier curve to the TinyPath between the current point to (x3,y3) using the current point and (x1,y1), (x2,y2) as Bézier control points.
 TinyRect getBBox()
          Returns the bounding box of the TinyPath.
 TinyPoint getCurrentPoint()
          Returns the coordinates most recently added to the end of the path as a TinyPoint object.
 byte getType(int i)
          Returns the type of the path segment at the specified index.
 int getX(int i)
          Returns the X coordinate of the path segment at the specified index.
 int getY(int i)
          Returns the Y coordinate of the path segment at the specified index.
 void lineTo(int x, int y)
          Adds a straight line segment from the current point to (x,y).
 void moveTo(int x, int y)
          Moves the current point to (x,y)
 int numPoints()
          Returns the number of points in the path.
 void reset()
          Resets the path to empty.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_MOVETO

public static final byte TYPE_MOVETO
The segment type constant for a moveTo.

See Also:
Constant Field Values

TYPE_LINETO

public static final byte TYPE_LINETO
The segment type constant for a lineTo.

See Also:
Constant Field Values

TYPE_CURVETO

public static final byte TYPE_CURVETO
The segment type constant for a curveTo.

See Also:
Constant Field Values

TYPE_CURVETO_CUBIC

public static final byte TYPE_CURVETO_CUBIC
The segment type constant for a curveTo.

See Also:
Constant Field Values

TYPE_CLOSE

public static final byte TYPE_CLOSE
The segment type constant for a closePath.

See Also:
Constant Field Values
Constructor Detail

TinyPath

public TinyPath(int i)
Constructs a new TinyPath object with the specified initial capacity to store path coordinates. The storage is expanded as needed to store whatever path segments are added to this path.

Parameters:
i - initial capacity

TinyPath

public TinyPath(TinyPath tinypath)
Constructs a new TinyPath object as a copy of the given source 'tinypath' object.

Parameters:
tinypath - the source TinyPath object.
Since:
1.5
Method Detail

compact

public void compact()
Compacts the TinyPath object data storage.

Since:
1.9

lineTo

public void lineTo(int x,
                   int y)
Adds a straight line segment from the current point to (x,y). The new current point is (x,y).

Parameters:
x - The specified X coordinate.
y - The specified Y coordinate.

moveTo

public void moveTo(int x,
                   int y)
Moves the current point to (x,y)

Parameters:
x - The specified X coordinate.
y - The specified Y coordinate.

numPoints

public int numPoints()
Returns the number of points in the path.


reset

public void reset()
Resets the path to empty.


closePath

public void closePath()
Closes the current subpath by drawing a straight line back to the coordinates of the last moveTo. If the TinyPath is already closed then this method has no effect.


curveTo

public void curveTo(int x2,
                    int y2,
                    int x3,
                    int y3)
Adds a Bézier curve to the TinyPath between the current point to (x3,y3) using the current point and (x2,y2) as Bézier control point. The new current point is (x3,y3).

Parameters:
x2 - the Bézier control point X coord.
y2 - the Bézier control point Y coord.
x3 - the final endpoint X coord.
y3 - the final endpoint Y coord.

curveToCubic

public void curveToCubic(int x1,
                         int y1,
                         int x2,
                         int y2,
                         int x3,
                         int y3)
Adds a Bézier curve to the TinyPath between the current point to (x3,y3) using the current point and (x1,y1), (x2,y2) as Bézier control points. The new current point is (x3,y3).

Parameters:
x1 - the first Bézier control point X coord.
y1 - the first Bézier control point Y coord.
x2 - the second Bézier control point X coord.
y2 - the second Bézier control point Y coord.
x3 - the final endpoint X coord.
y3 - the final endpoint Y coord.

getBBox

public TinyRect getBBox()
Returns the bounding box of the TinyPath.

Returns:
a TinyRect object that bounds this TinyPath.

addPoint

public void addPoint(int x,
                     int y,
                     byte t)
Adds a segment to the TinyPath.

Parameters:
x - the specified X coordinate.
y - the specified Y coordinate.
t - the segment type

getCurrentPoint

public TinyPoint getCurrentPoint()
Returns the coordinates most recently added to the end of the path as a TinyPoint object.

Returns:
a TinyPoint object containing the ending coordinates of the path or null if there are no points in the path.

getX

public int getX(int i)
Returns the X coordinate of the path segment at the specified index.

Parameters:
i - an index into this path.
Returns:
the X coordinate value.

getY

public int getY(int i)
Returns the Y coordinate of the path segment at the specified index.

Parameters:
i - an index into this path.
Returns:
the Y coordinate value.

getType

public byte getType(int i)
Returns the type of the path segment at the specified index.

Parameters:
i - an index into this path.
Returns:
the return value is the path-segment type: TYPE_MOVETO, TYPE_LINETO, TYPE_CURVETO, TYPE_CURVETO_CUBIC or TYPE_CLOSE.

TinyLine
v2.0

Provided under the terms of the TinyLine License Agreement that has been included with this distribution