The goog.graphics.Path Class

goog.graphics.Path()

Creates a path object. A path is a sequence of segments and may be open or closed. Path uses the EVEN-ODD fill rule for determining the interior of the path. A path must start with a moveTo command. A "simple" path does not contain any arcs and may be transformed using the {@code transform} method.

The goog.graphics.Path.Segment Enum

Path segment types. … more

.appendPath(path)

Appends another path to the end of this path.

path {!goog.graphics.Path}
The path to append.
returns {!goog.graphics.Path}
This path.

.arcTo(rx, ry, fromAngle, extent)

Adds a path command to draw an arc starting at the path's current point, with radius {@code rx} along the x-axis and {@code ry} along the y-axis from {@code startAngle} through {@code extent} degrees. Positive rotation is in the direction from positive x-axis to positive y-axis. This method makes the path non-simple.

rx {number}
Radius of ellipse on x axis.
ry {number}
Radius of ellipse on y axis.
fromAngle {number}
Starting angle measured in degrees from the positive x-axis.
extent {number}
The span of the arc in degrees.
returns {!goog.graphics.Path}
The path itself.

.arcToAsCurves(rx, ry, fromAngle, extent)

Same as {@code arcTo}, but approximates the arc using bezier curves. .* As a result, this method does not affect the simplified status of this path. The algorithm is adapted from {@code java.awt.geom.ArcIterator}.

rx {number}
Radius of ellipse on x axis.
ry {number}
Radius of ellipse on y axis.
fromAngle {number}
Starting angle measured in degrees from the positive x-axis.
extent {number}
The span of the arc in degrees.
returns {!goog.graphics.Path}
The path itself.

.clear()

Clears the path.

returns {!goog.graphics.Path}
The path itself.

.clone()

returns {!goog.graphics.Path}
A copy of this path.

.close()

Adds a path command to close the path by connecting the last point to the first point.

returns {!goog.graphics.Path}
The path itself.

.createSimplifiedPath(src)

Creates a copy of the given path, replacing {@code arcTo} with {@code arcToAsCurves}. The resulting path is simplified and can be transformed.

src {!goog.graphics.Path}
The path to simplify.
returns {!goog.graphics.Path}
A new simplified path.

.createTransformedPath(tx)

Creates a transformed copy of this path. The path is simplified {@see #createSimplifiedPath} prior to transformation.

tx {!goog.graphics.AffineTransform}
The transformation to perform.
returns {!goog.graphics.Path}
A new, transformed path.

.curveTo(var_args)

Adds points to the path by drawing cubic Bezier curves. Each curve is specified using 3 points (6 coordinates) - two control points and the end point of the curve.

var_args {...number}
The coordinates specifiying each curve in sets of 6 points: {@code [x1, y1]} the first control point, {@code [x2, y2]} the second control point and {@code [x, y]} the end point.
returns {!goog.graphics.Path}
The path itself.

.forEachSegment(callback)

Iterates over the path calling the supplied callback once for each path segment. The arguments to the callback function are the segment type and an array of its arguments. The {@code LINETO} and {@code CURVETO} arrays can contain multiple segments of the same type. The number of segments is the length of the array divided by the segment length (2 for lines, 6 for curves). As a convenience the {@code ARCTO} segment also includes the end point as the last two arguments: {@code rx, ry, fromAngle, extent, x, y}.

callback {function(number, Array)}
The function to call with each path segment.

.getCurrentPoint()

Returns the coordinates most recently added to the end of the path.

returns {Array.<number>?}
An array containing the ending coordinates of the path of the form {@code [x, y]}.

.getSegmentCount(segment)

Returns the number of points for a segment type.

segment {number}
The segment type.
returns {number}
The number of points.

.isEmpty()

returns {boolean}
Whether the path is empty.

.isSimple()

Returns true if this path contains no arcs. Simplified paths can be created using {@code createSimplifiedPath}.

returns {boolean}
True if the path contains no arcs.

.lineTo(var_args)

Adds points to the path by drawing a straight line to each point.

var_args {...number}
The coordinates of each destination point as x, y value pairs.
returns {!goog.graphics.Path}
The path itself.

.moveTo(x, y)

Adds a point to the path by moving to the specified point. Repeated moveTo commands are collapsed into a single moveTo.

x {number}
X coordinate of destination point.
y {number}
Y coordinate of destination point.
returns {!goog.graphics.Path}
The path itself.

.transform(tx)

Transforms the path. Only simple paths are transformable. Attempting to transform a non-simple path will throw an error.

tx {!goog.graphics.AffineTransform}
The transformation to perform.
returns {!goog.graphics.Path}
The path itself.