de.lmu.ifi.dbs.elki.visualization.svg
Class SVGPath

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.visualization.svg.SVGPath

public class SVGPath
extends Object

Element used for building an SVG path using a string buffer.


Field Summary
private  StringBuffer buf
          String buffer for building the path.
private  String lastaction
          The last action we did, to not add unnecessary commands
static String PATH_ARC_RELATIVE
          The lower case version (relative) path arc command.
static String PATH_CUBIC_TO_RELATIVE
          The lower case version (relative) cubic line to command.
static String PATH_HORIZONTAL_LINE_TO_RELATIVE
          The lower case version (relative) horizontal line to command.
static String PATH_LINE_TO_RELATIVE
          The lower case version (relative) line to command.
static String PATH_MOVE_RELATIVE
          The lower case version (relative) move command.
static String PATH_QUAD_TO_RELATIVE
          The lower case version (relative) quadratic interpolation to command.
static String PATH_SMOOTH_CUBIC_TO
          The absolute "smooth cubic to" SVG path command (missing from SVGConstants).
static String PATH_SMOOTH_CUBIC_TO_RELATIVE
          The lower case version (relative) smooth cubic to command.
static String PATH_SMOOTH_QUAD_TO_RELATIVE
          The lower case version (relative) smooth quadratic interpolation to command.
static String PATH_VERTICAL_LINE_TO_RELATIVE
          The lower case version (relative) vertical line to command.
 
Constructor Summary
SVGPath()
          Empty path constructor.
SVGPath(double x, double y)
          Constructor with initial point.
SVGPath(Iterable<Vector> vectors)
          Constructor from a vector collection (e.g. a polygon)
 
Method Summary
private  void append(String action, double... ds)
          Append an action to the current path.
 SVGPath close()
          Close the path.
 SVGPath cubicTo(double c1x, double c1y, double c2x, double c2y, double x, double y)
          Cubic Bezier line to the given coordinates.
 SVGPath cubicTo(Vector c1xy, Vector c2xy, Vector xy)
          Cubic Bezier line to the given coordinates.
 SVGPath drawTo(double x, double y)
          Draw a line given a series of coordinates.
 SVGPath drawTo(Vector xy)
          Draw a line given a series of coordinates.
 SVGPath ellipticalArc(double rx, double ry, double ar, double la, double sp, double x, double y)
          Elliptical arc curve to the given coordinates.
 SVGPath ellipticalArc(Vector rxy, double ar, double la, double sp, Vector xy)
          Elliptical arc curve to the given coordinates.
 SVGPath horizontalLineTo(double x)
          Draw a horizontal line to the given x coordinate.
 boolean isStarted()
          Test whether the path drawing has already started.
 SVGPath lineTo(double x, double y)
          Draw a line to the given coordinates.
 SVGPath lineTo(Vector xy)
          Draw a line to the given coordinates.
 Element makeElement(Document document)
          Turn the path buffer into an SVG element.
 Element makeElement(SVGPlot plot)
          Turn the path buffer into an SVG element.
 SVGPath moveTo(double x, double y)
          Move to the given coordinates.
 SVGPath moveTo(Vector xy)
          Move to the given coordinates.
 SVGPath quadTo(double c1x, double c1y, double x, double y)
          Quadratic Bezier line to the given coordinates.
 SVGPath quadTo(Vector c1xy, Vector xy)
          Quadratic Bezier line to the given coordinates.
 SVGPath relativeCubicTo(double c1x, double c1y, double c2x, double c2y, double x, double y)
          Cubic Bezier line to the given relative coordinates.
 SVGPath relativeCubicTo(Vector c1xy, Vector c2xy, Vector xy)
          Cubic Bezier line to the given relative coordinates.
 SVGPath relativeEllipticalArc(double rx, double ry, double ar, double la, double sp, double x, double y)
          Elliptical arc curve to the given relative coordinates.
 SVGPath relativeEllipticalArc(Vector rxy, double ar, double la, double sp, Vector xy)
          Elliptical arc curve to the given relative coordinates.
 SVGPath relativeHorizontalLineTo(double x)
          Draw a horizontal line to the given relative x coordinate.
 SVGPath relativeLineTo(double x, double y)
          Draw a line to the given relative coordinates.
 SVGPath relativeLineTo(Vector xy)
          Draw a line to the given relative coordinates.
 SVGPath relativeMoveTo(double x, double y)
          Move to the given relative coordinates.
 SVGPath relativeMoveTo(Vector xy)
          Move to the given relative coordinates.
 SVGPath relativeQuadTo(double c1x, double c1y, double x, double y)
          Quadratic Bezier line to the given relative coordinates.
 SVGPath relativeQuadTo(Vector c1xy, Vector xy)
          Quadratic Bezier line to the given relative coordinates.
 SVGPath relativeSmoothCubicTo(double c2x, double c2y, double x, double y)
          Smooth Cubic Bezier line to the given relative coordinates.
 SVGPath relativeSmoothCubicTo(Vector c2xy, Vector xy)
          Smooth Cubic Bezier line to the given relative coordinates.
 SVGPath relativeSmoothQuadTo(double x, double y)
          Smooth quadratic Bezier line to the given relative coordinates.
 SVGPath relativeSmoothQuadTo(Vector xy)
          Smooth quadratic Bezier line to the given relative coordinates.
 SVGPath relativeVerticalLineTo(double y)
          Draw a vertical line to the given relative y coordinate.
 SVGPath smoothCubicTo(double c2x, double c2y, double x, double y)
          Smooth Cubic Bezier line to the given coordinates.
 SVGPath smoothCubicTo(Vector c2xy, Vector xy)
          Smooth Cubic Bezier line to the given coordinates.
 SVGPath smoothQuadTo(double x, double y)
          Smooth quadratic Bezier line to the given coordinates.
 SVGPath smoothQuadTo(Vector xy)
          Smooth quadratic Bezier line to the given coordinates.
 String toString()
          Return the SVG serialization of the path.
 SVGPath verticalLineTo(double y)
          Draw a vertical line to the given y coordinate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

buf

private StringBuffer buf
String buffer for building the path.


lastaction

private String lastaction
The last action we did, to not add unnecessary commands


PATH_SMOOTH_CUBIC_TO

public static final String PATH_SMOOTH_CUBIC_TO
The absolute "smooth cubic to" SVG path command (missing from SVGConstants).

See Also:
Constant Field Values

PATH_LINE_TO_RELATIVE

public static final String PATH_LINE_TO_RELATIVE
The lower case version (relative) line to command.


PATH_MOVE_RELATIVE

public static final String PATH_MOVE_RELATIVE
The lower case version (relative) move command.


PATH_HORIZONTAL_LINE_TO_RELATIVE

public static final String PATH_HORIZONTAL_LINE_TO_RELATIVE
The lower case version (relative) horizontal line to command.


PATH_VERTICAL_LINE_TO_RELATIVE

public static final String PATH_VERTICAL_LINE_TO_RELATIVE
The lower case version (relative) vertical line to command.


PATH_CUBIC_TO_RELATIVE

public static final String PATH_CUBIC_TO_RELATIVE
The lower case version (relative) cubic line to command.


PATH_SMOOTH_CUBIC_TO_RELATIVE

public static final String PATH_SMOOTH_CUBIC_TO_RELATIVE
The lower case version (relative) smooth cubic to command.


PATH_QUAD_TO_RELATIVE

public static final String PATH_QUAD_TO_RELATIVE
The lower case version (relative) quadratic interpolation to command.


PATH_SMOOTH_QUAD_TO_RELATIVE

public static final String PATH_SMOOTH_QUAD_TO_RELATIVE
The lower case version (relative) smooth quadratic interpolation to command.


PATH_ARC_RELATIVE

public static final String PATH_ARC_RELATIVE
The lower case version (relative) path arc command.

Constructor Detail

SVGPath

public SVGPath()
Empty path constructor.


SVGPath

public SVGPath(double x,
               double y)
Constructor with initial point.

Parameters:
x - initial coordinates
y - initial coordinates

SVGPath

public SVGPath(Iterable<Vector> vectors)
Constructor from a vector collection (e.g. a polygon)

Parameters:
vectors - vectors
Method Detail

drawTo

public SVGPath drawTo(double x,
                      double y)
Draw a line given a series of coordinates. Helper function that will use "move" for the first point, "lineto" for the remaining.

Parameters:
x - new coordinates
y - new coordinates
Returns:
path object, for compact syntax.

drawTo

public SVGPath drawTo(Vector xy)
Draw a line given a series of coordinates. Helper function that will use "move" for the first point, "lineto" for the remaining.

Parameters:
xy - new coordinates
Returns:
path object, for compact syntax.

isStarted

public boolean isStarted()
Test whether the path drawing has already started.

Returns:
Path freshness

lineTo

public SVGPath lineTo(double x,
                      double y)
Draw a line to the given coordinates.

Parameters:
x - new coordinates
y - new coordinates
Returns:
path object, for compact syntax.

lineTo

public SVGPath lineTo(Vector xy)
Draw a line to the given coordinates.

Parameters:
xy - new coordinates
Returns:
path object, for compact syntax.

relativeLineTo

public SVGPath relativeLineTo(double x,
                              double y)
Draw a line to the given relative coordinates.

Parameters:
x - relative coordinates
y - relative coordinates
Returns:
path object, for compact syntax.

relativeLineTo

public SVGPath relativeLineTo(Vector xy)
Draw a line to the given relative coordinates.

Parameters:
xy - new coordinates
Returns:
path object, for compact syntax.

horizontalLineTo

public SVGPath horizontalLineTo(double x)
Draw a horizontal line to the given x coordinate.

Parameters:
x - new coordinates
Returns:
path object, for compact syntax.

relativeHorizontalLineTo

public SVGPath relativeHorizontalLineTo(double x)
Draw a horizontal line to the given relative x coordinate.

Parameters:
x - new coordinates
Returns:
path object, for compact syntax.

verticalLineTo

public SVGPath verticalLineTo(double y)
Draw a vertical line to the given y coordinate.

Parameters:
y - new coordinate
Returns:
path object, for compact syntax.

relativeVerticalLineTo

public SVGPath relativeVerticalLineTo(double y)
Draw a vertical line to the given relative y coordinate.

Parameters:
y - new coordinate
Returns:
path object, for compact syntax.

moveTo

public SVGPath moveTo(double x,
                      double y)
Move to the given coordinates.

Parameters:
x - new coordinates
y - new coordinates
Returns:
path object, for compact syntax.

moveTo

public SVGPath moveTo(Vector xy)
Move to the given coordinates.

Parameters:
xy - new coordinates
Returns:
path object, for compact syntax.

relativeMoveTo

public SVGPath relativeMoveTo(double x,
                              double y)
Move to the given relative coordinates.

Parameters:
x - new coordinates
y - new coordinates
Returns:
path object, for compact syntax.

relativeMoveTo

public SVGPath relativeMoveTo(Vector xy)
Move to the given relative coordinates.

Parameters:
xy - new coordinates
Returns:
path object, for compact syntax.

cubicTo

public SVGPath cubicTo(double c1x,
                       double c1y,
                       double c2x,
                       double c2y,
                       double x,
                       double y)
Cubic Bezier line to the given coordinates.

Parameters:
c1x - first control point x
c1y - first control point y
c2x - second control point x
c2y - second control point y
x - new coordinates
y - new coordinates
Returns:
path object, for compact syntax.

cubicTo

public SVGPath cubicTo(Vector c1xy,
                       Vector c2xy,
                       Vector xy)
Cubic Bezier line to the given coordinates.

Parameters:
c1xy - first control point
c2xy - second control point
xy - new coordinates
Returns:
path object, for compact syntax.

relativeCubicTo

public SVGPath relativeCubicTo(double c1x,
                               double c1y,
                               double c2x,
                               double c2y,
                               double x,
                               double y)
Cubic Bezier line to the given relative coordinates.

Parameters:
c1x - first control point x
c1y - first control point y
c2x - second control point x
c2y - second control point y
x - new coordinates
y - new coordinates
Returns:
path object, for compact syntax.

relativeCubicTo

public SVGPath relativeCubicTo(Vector c1xy,
                               Vector c2xy,
                               Vector xy)
Cubic Bezier line to the given relative coordinates.

Parameters:
c1xy - first control point
c2xy - second control point
xy - new coordinates
Returns:
path object, for compact syntax.

smoothCubicTo

public SVGPath smoothCubicTo(double c2x,
                             double c2y,
                             double x,
                             double y)
Smooth Cubic Bezier line to the given coordinates.

Parameters:
c2x - second control point x
c2y - second control point y
x - new coordinates
y - new coordinates
Returns:
path object, for compact syntax.

smoothCubicTo

public SVGPath smoothCubicTo(Vector c2xy,
                             Vector xy)
Smooth Cubic Bezier line to the given coordinates.

Parameters:
c2xy - second control point
xy - new coordinates
Returns:
path object, for compact syntax.

relativeSmoothCubicTo

public SVGPath relativeSmoothCubicTo(double c2x,
                                     double c2y,
                                     double x,
                                     double y)
Smooth Cubic Bezier line to the given relative coordinates.

Parameters:
c2x - second control point x
c2y - second control point y
x - new coordinates
y - new coordinates
Returns:
path object, for compact syntax.

relativeSmoothCubicTo

public SVGPath relativeSmoothCubicTo(Vector c2xy,
                                     Vector xy)
Smooth Cubic Bezier line to the given relative coordinates.

Parameters:
c2xy - second control point
xy - new coordinates
Returns:
path object, for compact syntax.

quadTo

public SVGPath quadTo(double c1x,
                      double c1y,
                      double x,
                      double y)
Quadratic Bezier line to the given coordinates.

Parameters:
c1x - first control point x
c1y - first control point y
x - new coordinates
y - new coordinates
Returns:
path object, for compact syntax.

quadTo

public SVGPath quadTo(Vector c1xy,
                      Vector xy)
Quadratic Bezier line to the given coordinates.

Parameters:
c1xy - first control point
xy - new coordinates
Returns:
path object, for compact syntax.

relativeQuadTo

public SVGPath relativeQuadTo(double c1x,
                              double c1y,
                              double x,
                              double y)
Quadratic Bezier line to the given relative coordinates.

Parameters:
c1x - first control point x
c1y - first control point y
x - new coordinates
y - new coordinates
Returns:
path object, for compact syntax.

relativeQuadTo

public SVGPath relativeQuadTo(Vector c1xy,
                              Vector xy)
Quadratic Bezier line to the given relative coordinates.

Parameters:
c1xy - first control point
xy - new coordinates
Returns:
path object, for compact syntax.

smoothQuadTo

public SVGPath smoothQuadTo(double x,
                            double y)
Smooth quadratic Bezier line to the given coordinates.

Parameters:
x - new coordinates
y - new coordinates
Returns:
path object, for compact syntax.

smoothQuadTo

public SVGPath smoothQuadTo(Vector xy)
Smooth quadratic Bezier line to the given coordinates.

Parameters:
xy - new coordinates
Returns:
path object, for compact syntax.

relativeSmoothQuadTo

public SVGPath relativeSmoothQuadTo(double x,
                                    double y)
Smooth quadratic Bezier line to the given relative coordinates.

Parameters:
x - new coordinates
y - new coordinates
Returns:
path object, for compact syntax.

relativeSmoothQuadTo

public SVGPath relativeSmoothQuadTo(Vector xy)
Smooth quadratic Bezier line to the given relative coordinates.

Parameters:
xy - new coordinates
Returns:
path object, for compact syntax.

ellipticalArc

public SVGPath ellipticalArc(double rx,
                             double ry,
                             double ar,
                             double la,
                             double sp,
                             double x,
                             double y)
Elliptical arc curve to the given coordinates.

Parameters:
rx - x radius
ry - y radius
ar - x-axis-rotation
la - large arc flag, if angle >= 180°
sp - sweep flag, if arc will be drawn in positive-angle direction
x - new coordinates
y - new coordinates

ellipticalArc

public SVGPath ellipticalArc(Vector rxy,
                             double ar,
                             double la,
                             double sp,
                             Vector xy)
Elliptical arc curve to the given coordinates.

Parameters:
rxy - radius
ar - x-axis-rotation
la - large arc flag, if angle >= 180°
sp - sweep flag, if arc will be drawn in positive-angle direction
xy - new coordinates

relativeEllipticalArc

public SVGPath relativeEllipticalArc(double rx,
                                     double ry,
                                     double ar,
                                     double la,
                                     double sp,
                                     double x,
                                     double y)
Elliptical arc curve to the given relative coordinates.

Parameters:
rx - x radius
ry - y radius
ar - x-axis-rotation
la - large arc flag, if angle >= 180°
sp - sweep flag, if arc will be drawn in positive-angle direction
x - new coordinates
y - new coordinates

relativeEllipticalArc

public SVGPath relativeEllipticalArc(Vector rxy,
                                     double ar,
                                     double la,
                                     double sp,
                                     Vector xy)
Elliptical arc curve to the given relative coordinates.

Parameters:
rxy - radius
ar - x-axis-rotation
la - large arc flag, if angle >= 180°
sp - sweep flag, if arc will be drawn in positive-angle direction
xy - new coordinates

append

private void append(String action,
                    double... ds)
Append an action to the current path.

Parameters:
action - Current action
ds - coordinates.

close

public SVGPath close()
Close the path.

Returns:
path object, for compact syntax.

makeElement

public Element makeElement(Document document)
Turn the path buffer into an SVG element.

Parameters:
document - Document context (= element factory)
Returns:
SVG Element

makeElement

public Element makeElement(SVGPlot plot)
Turn the path buffer into an SVG element.

Parameters:
plot - Plot context (= element factory)
Returns:
SVG Element

toString

public String toString()
Return the SVG serialization of the path.

Overrides:
toString in class Object

Release 0.4.0 (2011-09-20_1324)