SkPath Reference
===
# Path
Path contains Lines and Curves which can be stroked or filled. Contour is
composed of a series of connected Lines and Curves. Path may contain zero,
one, or more Contours.
Each Line and Curve are described by Verb, Points, and optional Conic Weight.
Each pair of connected Lines and Curves share common Point; for instance, Path
containing two connected Lines are described the Verb sequence:
SkPath::kMove Verb, SkPath::kLine Verb, SkPath::kLine Verb; and a Point sequence
with three entries, sharing
the middle entry as the end of the first Line and the start of the second Line.
Path components Arc, Rect, Round Rect, Circle, and Oval are composed of
Lines and Curves with as many Verbs and Points required
for an exact description. Once added to Path, these components may lose their
identity; although Path can be inspected to determine if it describes a single
Rect, Oval, Round Rect, and so on.
### Example
Path contains a Fill Type which determines whether overlapping Contours
form fills or holes. Fill Type also determines whether area inside or outside
Lines and Curves is filled.
### Example
Path is drawn filled, then stroked, then stroked and filled.
Path contents are never shared. Copying Path by value effectively creates
a new Path independent of the original. Internally, the copy does not duplicate
its contents until it is edited, to reduce memory use and improve performance.
## Subtopics
| topics | description |
| --- | --- |
## Contour
Contour contains one or more Verbs, and as many Points as
are required to satisfy Verb Array. First Verb in Path is always
SkPath::kMove Verb; each SkPath::kMove Verb that follows starts a new Contour.
### Example
If final Verb in Contour is SkPath::kClose Verb, Line connects Last Point in
Contour with first Point. A closed Contour, stroked, draws
Paint Stroke Join at Last Point and first Point. Without SkPath::kClose Verb
as final Verb, Last Point and first Point are not connected; Contour
remains open. An open Contour, stroked, draws Paint Stroke Cap at
Last Point and first Point.
### Example
## Zero Length
Contour length is distance traveled from first Point to Last Point,
plus, if Contour is closed, distance from Last Point to first Point.
Even if Contour length is zero, stroked Lines are drawn if Paint Stroke Cap
makes them visible.
### Example
# Class SkPath
Paths contain geometry. Paths may be empty, or contain one or more Verbs that
outline a figure. Path always starts with a move verb to a Cartesian
coordinate, and may be followed by additional verbs that add lines or curves.
Adding a close verb makes the geometry into a continuous loop, a closed contour.
Paths may contain any number of contours, each beginning with a move verb.
Path contours may contain only a move verb, or may also contain lines,
Quadratic Beziers, Conics, and Cubic Beziers. Path contours may be open or
closed.
When used to draw a filled area, Path describes whether the fill is inside or
outside the geometry. Path also describes the winding rule used to fill
overlapping contours.
Internally, Path lazily computes metrics likes bounds and convexity. Call
SkPath::updateBoundsCache to make Path thread safe.
# Overview
## Constants
| constants | description |
| --- | --- |
| AddPathMode | Sets addPath options. |
| ArcSize | Used by arcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc, Direction sweep, SkScalar x, SkScalar y). |
| Convexity | Returns if Path is convex or concave. |
| Direction | Sets Contour clockwise or counterclockwise. |
| FillType | Sets winding rule and inverse fill. |
| SegmentMask | Returns Verb types in Path. |
| Verb | Controls how Path Points are interpreted. |
## Classes and Structs
| class or struct | description |
| --- | --- |
| Iter | Iterates through lines and curves, skipping degenerates. |
| RawIter | Iterates through lines and curves, including degenerates. |
## Constructors
| | description |
| --- | --- |
| SkPath() | Constructs with default values. |
| SkPath(const SkPath& path) | Makes a shallow copy. |
| | Decreases Reference Count of owned objects. |
## Operators
| operator | description |
| --- | --- |
| operator=(const SkPath& path) | Makes a shallow copy. |
| operator==(const SkPath& a, const SkPath& b) | Compares paths for equality. |
| operator!=(const SkPath& a, const SkPath& b) | Compares paths for inequality. |
## Member Functions
| function | description |
| --- | --- |
| ConvertConicToQuads | Approximates Conic with Quad array. |
| ConvertToNonInverseFillType | Returns Fill Type representing inside geometry. |
| IsCubicDegenerate | Returns if Cubic is very small. |
| IsInverseFillType | Returns if Fill Type represents outside geometry. |
| IsLineDegenerate | Returns if Line is very small. |
| IsQuadDegenerate | Returns if Quad is very small. |
| addArc | Adds one Contour containing Arc. |
| addCircle | Adds one Contour containing Circle. |
| addOval | Adds one Contour containing Oval. |
| addPath | Adds contents of Path. |
| addPoly | Adds one Contour containing connected lines. |
| addRRect | Adds one Contour containing Round Rect. |
| addRect | Adds one Contour containing Rect. |
| addRoundRect | Adds one Contour containing Round Rect with common corner radii. |
| arcTo | Appends Arc. |
| close | Makes last Contour a loop. |
| computeTightBounds | Returns extent of geometry. |
| conicTo | Appends Conic. |
| conservativelyContainsRect | Returns true if Rect may be inside. |
| contains | Returns if Point is in fill area. |
| countPoints | Returns Point Array length. |
| countVerbs | Returns Verb Array length. |
| cubicTo | Appends Cubic. |
| dump | Sends text representation using floats to standard output. |
| dumpHex | Sends text representation using hexadecimal to standard output. |
| getBounds | Returns maximum and minimum of Point Array. |
| getConvexity | Returns geometry convexity, computing if necessary. |
| getConvexityOrUnknown | Returns geometry convexity if known. |
| getFillType | Returns Fill Type: winding, even-odd, inverse. |
| getGenerationID | Returns unique ID. |
| getLastPt | Returns Last Point. |
| getPoint | Returns entry from Point Array. |
| getPoints | Returns Point Array. |
| getSegmentMasks | Returns types in Verb Array. |
| getVerbs | Returns Verb Array. |
| incReserve | Hint to reserve space for additional data. |
| interpolate | Interpolates between Path pair. |
| isConvex | Returns if geometry is convex. |
| isEmpty | Returns if verb count is zero. |
| isFinite | Returns if all Point values are finite. |
| isInterpolatable | Returns if pair contains equal counts of Verb Array and Weights. |
| isInverseFillType | Returns if Fill Type fills outside geometry. |
| isLastContourClosed | Returns if final Contour forms a loop. |
| isLine | Returns if describes Line. |
| isNestedFillRects | Returns if describes Rect pair, one inside the other. |
| isOval | Returns if describes Oval. |
| isRRect | Returns if describes Round Rect. |
| isRect | Returns if describes Rect. |
| isValid | Returns if data is internally consistent. |
| isVolatile | Returns if Device should not cache. |
| lineTo | Appends Line. |
| moveTo | Starts Contour. |
| offset | Translates Point Array. |
| quadTo | Appends Quad. |
| rArcTo | Appends Arc relative to Last Point. |
| rConicTo | Appends Conic relative to Last Point. |
| rCubicTo | Appends Cubic relative to Last Point. |
| rLineTo | Appends Line relative to Last Point. |
| rMoveTo | Starts Contour relative to Last Point. |
| rQuadTo | Appends Quad relative to Last Point. |
| readFromMemory | Initializes from buffer. |
| reset | Removes Verb Array, Point Array, and Weights; frees memory. |
| reverseAddPath | Adds contents of Path back to front. |
| rewind | Removes Verb Array, Point Array, and Weights; leaves memory allocated. |
| serialize | Copies data to buffer. |
| setConvexity | Sets if geometry is convex to avoid future computation. |
| setFillType | Sets Fill Type: winding, even-odd, inverse. |
| setIsConvex | Deprecated. |
| setIsVolatile | Sets if Device should not cache. |
| setLastPt | Replaces Last Point. |
| swap | Exchanges Path pair. |
| toggleInverseFillType | Toggles Fill Type between inside and outside geometry. |
| transform | Applies Matrix to Point Array and Weights. |
| unique | Returns if data has single owner. |
| updateBoundsCache | Refreshes result of getBounds. |
| writeToMemory | Copies data to buffer. |
## Verb
## Enum SkPath::Verb
enum Verb {
kMove Verb,
kLine Verb,
kQuad Verb,
kConic Verb,
kCubic Verb,
kClose Verb,
kDone Verb,
};
Verb instructs Path how to interpret one or more Point and optional Conic Weight;
manage Contour, and terminate Path.
### Constants
SkPath::kMove_Verb | 0 | Starts new Contour at next Point. |
SkPath::kLine_Verb | 1 | Adds Line from Last Point to next Point.
Line is a straight segment from Point to Point. |
SkPath::kQuad_Verb | 2 | Adds Quad from Last Point, using control Point, and end Point.
Quad is a parabolic section within tangents from Last Point to control Point,
and control Point to end Point. |
SkPath::kConic_Verb | 3 | Adds Conic from Last Point, using control Point, end Point, and Conic Weight.
Conic is a elliptical, parabolic, or hyperbolic section within tangents
from Last Point to control Point, and control Point to end Point, constrained
by Conic Weight. Conic Weight less than one is elliptical; equal to one is
parabolic (and identical to Quad); greater than one hyperbolic. |
SkPath::kCubic_Verb | 4 | Adds Cubic from Last Point, using two control Points, and end Point.
Cubic is a third-order Bezier section within tangents from Last Point to
first control Point, and from second control Point to end Point. |
SkPath::kClose_Verb | 5 | Closes Contour, connecting Last Point to kMove Verb Point. |
SkPath::kDone_Verb | 6 | Terminates Path. Not in Verb Array, but returned by Path iterator. |
Each Verb has zero or more Points stored in Path.
Path iterator returns complete curve descriptions, duplicating shared Points
for consecutive entries.
| Verb | Allocated Points | Iterated Points | Weights |
| --- | --- | --- | --- |
| kMove Verb | 1 | 1 | 0 |
| kLine Verb | 1 | 2 | 0 |
| kQuad Verb | 2 | 3 | 0 |
| kConic Verb | 2 | 3 | 1 |
| kCubic Verb | 3 | 4 | 0 |
| kClose Verb | 0 | 1 | 0 |
| kDone Verb | -- | 0 | 0 |
### Example
#### Example Output
~~~~
verb count: 7
verbs: kMove_Verb kLine_Verb kQuad_Verb kClose_Verb kMove_Verb kCubic_Verb kConic_Verb
~~~~
## Direction
## Enum SkPath::Direction
enum Direction {
kCW Direction,
kCCW Direction,
};
Direction describes whether Contour is clockwise or counterclockwise.
When Path contains multiple overlapping Contours, Direction together with
Fill Type determines whether overlaps are filled or form holes.
Direction also determines how Contour is measured. For instance, dashing
measures along Path to determine where to start and stop stroke; Direction
will change dashed results as it steps clockwise or counterclockwise.
Closed Contours like Rect, Round Rect, Circle, and Oval added with
kCW Direction travel clockwise; the same added with kCCW Direction
travel counterclockwise.
### Constants
### Example
### See Also
arcTo rArcTo isRect isNestedFillRects addRect addOval
## SkPath
SkPath()
By default, Path has no Verbs, no Points, and no Weights.
Fill Type is set to kWinding FillType.
### Return Value
empty Path
### Example
#### Example Output
~~~~
path is empty
~~~~
### See Also
reset rewind
---
## SkPath
SkPath(const SkPath& path)
Copy constructor makes two paths identical by value. Internally, path and
the returned result share pointer values. The underlying Verb Array, Point Array
and Weights are copied when modified.
Creating a Path copy is very efficient and never allocates memory.
Paths are always copied by value from the interface; the underlying shared
pointers are not exposed.
### Parameters
### Return Value
copy of Path
### Example
Modifying one
path does not effect another, even if they started as copies
of each other.
#### Example Output
~~~~
path verbs: 2
path2 verbs: 3
after reset
path verbs: 0
path2 verbs: 3
~~~~
### See Also
operator=(const SkPath& path)
---
## ~SkPath
~SkPath()
Releases ownership of any shared data and deletes data if Path is sole owner.
### Example
delete calls
Path Destructor, but copy of original in path2 is unaffected.
### See Also
SkPath() SkPath(const SkPath& path) operator=(const SkPath& path)
---
## operator=
SkPath& operator=(const SkPath& path)
Path assignment makes two paths identical by value. Internally, assignment
shares pointer values. The underlying Verb Array, Point Array and Weights
are copied when modified.
Copying Paths by assignment is very efficient and never allocates memory.
Paths are always copied by value from the interface; the underlying shared
pointers are not exposed.
### Parameters
### Return Value
Path copied by value
### Example
#### Example Output
~~~~
path1 bounds = 10, 20, 30, 40
path2 bounds = 10, 20, 30, 40
~~~~
### See Also
swap SkPath(const SkPath& path)
---
## operator==
bool operator==(const SkPath& a, const SkPath& b)
Compares a and b; returns true if Fill Type, Verb Array, Point Array, and Weights
are equivalent.
### Parameters
### Return Value
true if Path pair are equivalent
### Example
Rewind removes
Verb Array but leaves storage; since storage is not compared,
Path pair are equivalent.
#### Example Output
~~~~
empty one == two
moveTo one != two
rewind one == two
reset one == two
~~~~
---
## operator!=
bool operator!=(const SkPath& a, const SkPath& b)
Compares a and b; returns true if Fill Type, Verb Array, Point Array, and Weights
are not equivalent.
### Parameters
### Return Value
true if Path pair are not equivalent
### Example
Path pair are equal though their convexity is not equal.
#### Example Output
~~~~
empty one == two
addRect one == two
setConvexity one == two
convexity !=
~~~~
---
## isInterpolatable
bool isInterpolatable(const SkPath& compare) const
Return true if Paths contain equal Verbs and equal Weights.
If Paths contain one or more Conics, the Weights must match.
conicTo may add different Verbs depending on Conic Weight, so it is not
trivial to interpolate a pair of Paths containing Conics with different
Conic Weight values.
### Parameters
### Return Value
true if Paths Verb Array and Weights are equivalent
### Example
#### Example Output
~~~~
paths are interpolatable
~~~~
### See Also
isInterpolatable
---
## interpolate
bool interpolate(const SkPath& ending, SkScalar weight, SkPath* out) const
Interpolate between Paths with equal sized Point Arrays.
Copy Verb Array and Weights to out,
and set out Point Array to a weighted average of this Point Array and ending
Point Array, using the formula:
(this->points * weight) + ending->points * (1 - weight).
weight is most useful when between zero (ending Point Array) and
one (this Point Array); will work with values outside of this
range.
interpolate returns false and leaves out unchanged if Point Array is not
the same size as ending Point Array. Call isInterpolatable to check Path
compatibility prior to calling interpolate.
### Parameters
### Return Value
true if Paths contain same number of Points
### Example
### See Also
isInterpolatable
---
## unique
bool unique() const
### Return Value
true if Path has one owner
---
## Fill Type
## Enum SkPath::FillType
enum FillType {
kWinding FillType,
kEvenOdd FillType,
kInverseWinding FillType,
kInverseEvenOdd FillType,
};
Fill Type selects the rule used to fill Path. Path set to kWinding FillType
fills if the sum of Contour edges is not zero, where clockwise edges add one, and
counterclockwise edges subtract one. Path set to kEvenOdd FillType fills if the
number of Contour edges is odd. Each Fill Type has an inverse variant that
reverses the rule:
kInverseWinding FillType fills where the sum of Contour edges is zero;
kInverseEvenOdd FillType fills where the number of Contour edges is even.
### Example
The top row has two clockwise rectangles. The second row has one clockwise and
one counterclockwise rectangle. The even-odd variants draw the same. The
winding variants draw the top rectangle overlap, which has a winding of 2, the
same as the outer parts of the top rectangles, which have a winding of 1.
### Constants
### Example
### See Also
SkPaint::Style Direction getFillType setFillType
## getFillType
FillType getFillType() const
Returns FillType, the rule used to fill Path. FillType of a new Path is
kWinding FillType.
### Return Value
one of: kWinding FillType, kEvenOdd FillType, kInverseWinding FillType,
kInverseEvenOdd FillType
### Example
#### Example Output
~~~~
default path fill type is kWinding_FillType
~~~~
### See Also
FillType setFillType isInverseFillType
---
## setFillType
void setFillType(FillType ft)
Sets FillType, the rule used to fill Path. While there is no check
that ft is legal, values outside of FillType are not supported.
### Parameters
### Example
If empty
Path is set to inverse
FillType, it fills all pixels.
### See Also
FillType getFillType toggleInverseFillType
---
## isInverseFillType
bool isInverseFillType() const
Returns if FillType describes area outside Path geometry. The inverse fill area
extends indefinitely.
### Return Value
true if FillType is kInverseWinding FillType or kInverseEvenOdd FillType
### Example
#### Example Output
~~~~
default path fill type is inverse: false
~~~~
### See Also
FillType getFillType setFillType toggleInverseFillType
---
## toggleInverseFillType
void toggleInverseFillType()
Replace FillType with its inverse. The inverse of FillType describes the area
unmodified by the original FillType.
| FillType | toggled FillType |
| --- | --- |
| kWinding FillType | kInverseWinding FillType |
| kEvenOdd FillType | kInverseEvenOdd FillType |
| kInverseWinding FillType | kWinding FillType |
| kInverseEvenOdd FillType | kEvenOdd FillType |
### Example
Path drawn normally and through its inverse touches every pixel once.
### See Also
FillType getFillType setFillType isInverseFillType
---
## Convexity
## Enum SkPath::Convexity
enum Convexity : uint8_t {
kUnknown Convexity,
kConvex Convexity,
kConcave Convexity,
};
Path is convex if it contains one Contour and Contour loops no more than
360 degrees, and Contour angles all have same Direction. Convex Path
may have better performance and require fewer resources on GPU Surface.
Path is concave when either at least one Direction change is clockwise and
another is counterclockwise, or the sum of the changes in Direction is not 360
degrees.
Initially Path Convexity is kUnknown Convexity. Path Convexity is computed
if needed by destination Surface.
### Constants
### Example
### See Also
Contour Direction getConvexity getConvexityOrUnknown setConvexity isConvex
## getConvexity
Convexity getConvexity() const
Computes Convexity if required, and returns stored value.
Convexity is computed if stored value is kUnknown Convexity,
or if Path has been altered since Convexity was computed or set.
### Return Value
computed or stored Convexity
### Example
### See Also
Convexity Contour Direction getConvexityOrUnknown setConvexity isConvex
---
## getConvexityOrUnknown
Convexity getConvexityOrUnknown() const
Returns last computed Convexity, or kUnknown Convexity if
Path has been altered since Convexity was computed or set.
### Return Value
stored Convexity
### Example
### See Also
Convexity Contour Direction getConvexity setConvexity isConvex
---
## setConvexity
void setConvexity(Convexity convexity)
Stores convexity so that it is later returned by getConvexity or getConvexityOrUnknown.
convexity may differ from getConvexity, although setting an incorrect value may
cause incorrect or inefficient drawing.
If convexity is kUnknown Convexity: getConvexity will
compute Convexity, and getConvexityOrUnknown will return kUnknown Convexity.
If convexity is kConvex Convexity or kConcave Convexity, getConvexity
and getConvexityOrUnknown will return convexity until the path is
altered.
### Parameters
### Example
### See Also
Convexity Contour Direction getConvexity getConvexityOrUnknown isConvex
---
## isConvex
bool isConvex() const
Computes Convexity if required, and returns true if value is kConvex Convexity.
If setConvexity was called with kConvex Convexity or kConcave Convexity, and
the path has not been altered, Convexity is not recomputed.
### Return Value
true if Convexity stored or computed is kConvex Convexity
### Example
Concave shape is erroneously considered convex after a forced call to
setConvexity.
### See Also
Convexity Contour Direction getConvexity getConvexityOrUnknown setConvexity
---
## setIsConvex
void setIsConvex(bool isConvex)
Deprecated. Use setConvexity.
### See Also
Convexity setConvexity getConvexity
---
## isOval
bool isOval(SkRect* rect, Direction* dir = nullptr, unsigned* start = nullptr) const
Returns true if constructed by addCircle, addOval; and in some cases,
addRoundRect, addRRect. Path constructed with conicTo or rConicTo will not
return true though Path draws Oval.
rect receives bounds of Oval.
dir receives Direction of Oval: kCW Direction if clockwise, kCCW Direction if
counterclockwise.
start receives start of Oval: 0 for top, 1 for right, 2 for bottom, 3 for left.
rect, dir, and start are unmodified if Oval is not found.
Triggers performance optimizations on some GPU Surface implementations.
### Parameters
### Return Value
true if Path was constructed by method that reduces to Oval
### Example
### See Also
Oval addCircle addOval
---
## isRRect
bool isRRect(SkRRect* rrect, Direction* dir = nullptr, unsigned* start = nullptr) const
Returns true if constructed by addRoundRect, addRRect; and if construction
is not empty, not Rect, and not Oval. Path constructed with other calls
will not return true though Path draws Round Rect.
rrect receives bounds of Round Rect.
dir receives Direction of Oval: kCW Direction if clockwise, kCCW Direction if
counterclockwise.
start receives start of Round Rect: 0 for top, 1 for right, 2 for bottom, 3 for left.
rrect, dir, and start are unmodified if Round Rect is not found.
Triggers performance optimizations on some GPU Surface implementations.
### Parameters
### Return Value
true if Path contains only Round Rect
### Example
Draw rounded rectangle and its bounds. Draw an arc indicating where the rounded
rectangle starts and its direction.
### See Also
Round Rect addRoundRect addRRect
---
## reset
void reset()
Sets Path to its initial state.
Removes Verb Array, Point Array, and Weights, and sets FillType to kWinding FillType.
Internal storage associated with Path is released.
### Example
### See Also
rewind
---
## rewind
void rewind()
Sets Path to its initial state, preserving internal storage.
Removes Verb Array, Point Array, and Weights, and sets FillType to kWinding FillType.
Internal storage associated with Path is retained.
Use rewind instead of reset if Path storage will be reused and performance
is critical.
### Example
Although path1 retains its internal storage, it is indistinguishable from
a newly initialized path.
### See Also
reset
---
## isEmpty
bool isEmpty() const
Empty Path may have FillType but has no SkPoint, Verb, or Conic Weight.
SkPath() constructs empty Path; reset and (rewind) make Path empty.
### Return Value
true if the path contains no Verb array
### Example
#### Example Output
~~~~
initial path is empty
after moveTo path is not empty
after rewind path is empty
after lineTo path is not empty
after reset path is empty
~~~~
### See Also
SkPath() reset rewind
---
## isLastContourClosed
bool isLastContourClosed() const
Contour is closed if Path Verb array was last modified by close. When stroked,
closed Contour draws Paint Stroke Join instead of Paint Stroke Cap at first and last Point.
### Return Value
true if the last Contour ends with a kClose Verb
### Example
#### Example Output
~~~~
initial last contour is not closed
after close last contour is not closed
after lineTo last contour is not closed
after close last contour is closed
~~~~
### See Also
close
---
## isFinite
bool isFinite() const
Returns true for finite Point array values between negative SK ScalarMax and
positive SK ScalarMax. Returns false for any Point array value of
SK ScalarInfinity, SK ScalarNegativeInfinity, or SK ScalarNaN.
### Return Value
true if all Point values are finite
### Example
#### Example Output
~~~~
initial path is finite
after line path is finite
after scale path is not finite
~~~~
### See Also
SkScalar
---
## isVolatile
bool isVolatile() const
Returns true if the path is volatile; it will not be altered or discarded
by the caller after it is drawn. Paths by default have volatile set false, allowing
Surface to attach a cache of data which speeds repeated drawing. If true, Surface
may not speed repeated drawing.
### Return Value
true if caller will alter Path after drawing
### Example
#### Example Output
~~~~
volatile by default is false
~~~~
### See Also
setIsVolatile
---
## setIsVolatile
void setIsVolatile(bool isVolatile)
Specify whether Path is volatile; whether it will be altered or discarded
by the caller after it is drawn. Paths by default have volatile set false, allowing
Device to attach a cache of data which speeds repeated drawing.
Mark temporary paths, discarded or modified after use, as volatile
to inform Device that the path need not be cached.
Mark animating Path volatile to improve performance.
Mark unchanging Path non-volatile to improve repeated rendering.
Raster Surface Path draws are affected by volatile for some shadows.
GPU Surface Path draws are affected by volatile for some shadows and concave geometries.
### Parameters
### Example
### See Also
isVolatile
---
## IsLineDegenerate
static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2, bool exact)
Test if Line between Point pair is degenerate.
Line with no length or that moves a very short distance is degenerate; it is
treated as a point.
exact changes the equality test. If true, returns true only if p1 equals p2.
If false, returns true if p1 equals or nearly equals p2.
### Parameters
p1 |
line start point |
p2 |
line end point |
exact |
if false, allow nearly equals |
### Return Value
true if Line is degenerate; its length is effectively zero
### Example
As single precision floats, 100 and 100.000001 have the same bit representation,
and are exactly equal. 100 and 100.0001 have different bit representations, and
are not exactly equal, but are nearly equal.
#### Example Output
~~~~
line from (100,100) to (100,100) is degenerate, nearly
line from (100,100) to (100,100) is degenerate, exactly
line from (100,100) to (100.0001,100.0001) is degenerate, nearly
line from (100,100) to (100.0001,100.0001) is not degenerate, exactly
~~~~
### See Also
IsQuadDegenerate IsCubicDegenerate SkPoint::equalsWithinTolerance
---
## IsQuadDegenerate
static bool IsQuadDegenerate(const SkPoint& p1, const SkPoint& p2,
const SkPoint& p3, bool exact)
Test if Quad is degenerate.
Quad with no length or that moves a very short distance is degenerate; it is
treated as a point.
### Parameters
p1 |
Quad start point |
p2 |
Quad control point |
p3 |
Quad end point |
exact |
if true, returns true only if p1, p2, and p3 are equal;
if false, returns true if p1, p2, and p3 are equal or nearly equal |
### Return Value
true if Quad is degenerate; its length is effectively zero
### Example
As single precision floats: 100, 100.00001, and 100.00002 have different bit representations
but nearly the same value. Translating all three by 1000 gives them the same bit representation;
the fractional portion of the number can not be represented by the float and is lost.
#### Example Output
~~~~
quad (100,100), (100.00001,100.00001), (100.00002,100.00002) is degenerate, nearly
quad (1100,1100), (1100,1100), (1100,1100) is degenerate, nearly
quad (100,100), (100.00001,100.00001), (100.00002,100.00002) is not degenerate, exactly
quad (1100,1100), (1100,1100), (1100,1100) is degenerate, exactly
~~~~
### See Also
IsLineDegenerate IsCubicDegenerate SkPoint::equalsWithinTolerance
---
## IsCubicDegenerate
static bool IsCubicDegenerate(const SkPoint& p1, const SkPoint& p2,
const SkPoint& p3, const SkPoint& p4, bool exact)
Test if Cubic is degenerate.
Cubic with no length or that moves a very short distance is degenerate; it is
treated as a point.
### Parameters
### Return Value
true if Cubic is degenerate; its length is effectively zero
### Example
#### Example Output
~~~~
0.00024414062 is degenerate
0.00024414065 is length
~~~~
---
## isLine
bool isLine(SkPoint line[2]) const
Returns true if Path contains only one Line;
Path Verb array has two entries: kMove Verb, kLine Verb.
If Path contains one Line and line is not nullptr, line is set to
Line start point and Line end point.
Returns false if Path is not one Line; line is unaltered.
### Parameters
### Return Value
true if Path contains exactly one Line
### Example
#### Example Output
~~~~
empty is not line
zero line is line (0,0) (0,0)
line is line (10,10) (20,20)
second move is not line
~~~~
---
## Point Array
Point Array contains Points satisfying the allocated Points for
each Verb in Verb Array. For instance, Path containing one Contour with Line
and Quad is described by Verb Array: Verb::kMoveTo, Verb::kLineTo, Verb::kQuadTo; and
one Point for move, one Point for Line, two Points for Quad; totaling four Points.
Point Array may be read directly from Path with getPoints, or inspected with
getPoint, with Iter, or with RawIter.
## getPoints
int getPoints(SkPoint points[], int max) const
Returns number of points in Path. Up to max points are copied.
points may be nullptr; then, max must be zero.
If max is greater than number of points, excess points storage is unaltered.
### Parameters
points |
storage for Path Point array. May be nullptr |
max |
maximum to copy; must be greater than or equal to zero |
### Return Value
Path Point array length
### Example
#### Example Output
~~~~
no points point count: 3
zero max point count: 3
too small point count: 3 (0,0) (20,20)
just right point count: 3 (0,0) (20,20) (-10,-10)
~~~~
### See Also
countPoints getPoint
---
## countPoints
int countPoints() const
Returns the number of points in Path.
Point count is initially zero.
### Return Value
Path Point array length
### Example
#### Example Output
~~~~
empty point count: 0
zero line point count: 2
line point count: 2
second move point count: 3
~~~~
### See Also
getPoints
---
## getPoint
SkPoint getPoint(int index) const
Returns Point at index in Point Array. Valid range for index is
0 to countPoints - 1.
Returns (0, 0) if index is out of range.
### Parameters
### Return Value
Point array value or (0, 0)
### Example
#### Example Output
~~~~
point 0: (-10,-10)
point 1: (10,10)
~~~~
### See Also
countPoints getPoints
---
## Verb Array
Verb Array always starts with kMove Verb.
If kClose Verb is not the last entry, it is always followed by kMove Verb;
the quantity of kMove Verb equals the Contour count.
Verb Array does not include or count kDone Verb; it is a convenience
returned when iterating through Verb Array.
Verb Array may be read directly from Path with getVerbs, or inspected with Iter,
or with RawIter.
## countVerbs
int countVerbs() const
Returns the number of Verbs: kMove Verb, kLine Verb, kQuad Verb, kConic Verb,
kCubic Verb, and kClose Verb; added to Path.
### Return Value
length of Verb Array
### Example
#### Example Output
~~~~
empty verb count: 0
round rect verb count: 10
~~~~
### See Also
getVerbs Iter RawIter
---
## getVerbs
int getVerbs(uint8_t verbs[], int max) const
Returns the number of verbs in the path. Up to max verbs are copied. The
verbs are copied as one byte per verb.
### Parameters
### Return Value
the actual number of verbs in the path
### Example
#### Example Output
~~~~
no verbs verb count: 3
zero max verb count: 3
too small verb count: 3 move line
just right verb count: 3 move line line
~~~~
### See Also
countVerbs getPoints Iter RawIter
---
## swap
void swap(SkPath& other)
Exchanges the Verb Array, Point Array, Weights, and Fill Type with other.
Cached state is also exchanged. swap internally exchanges pointers, so
it is lightweight and does not allocate memory.
swap usage has largely been replaced by operator=(const SkPath& path).
Paths do not copy their content on assignment until they are written to,
making assignment as efficient as swap.
### Parameters
### Example
#### Example Output
~~~~
path1 bounds = 0, 0, 0, 0
path2 bounds = 10, 20, 30, 40
~~~~
### See Also
operator=(const SkPath& path)
---
## getBounds
const SkRect& getBounds() const
Returns minimum and maximum x and y values of Point Array.
Returns (0, 0, 0, 0) if Path contains no points. Returned bounds width and height may
be larger or smaller than area affected when Path is drawn.
Rect returned includes all Points added to Path, including Points associated with
kMove Verb that define empty Contours.
### Return Value
bounds of all Points in Point Array
### Example
Bounds of upright
Circle can be predicted from center and radius.
Bounds of rotated
Circle includes control
Points outside of filled area.
#### Example Output
~~~~
empty bounds = 0, 0, 0, 0
circle bounds = 25, 20, 75, 70
rotated circle bounds = 14.6447, 9.64466, 85.3553, 80.3553
~~~~
### See Also
computeTightBounds updateBoundsCache
---
## updateBoundsCache
void updateBoundsCache() const
Update internal bounds so that subsequent calls to getBounds are instantaneous.
Unaltered copies of Path may also access cached bounds through getBounds.
For now, identical to calling getBounds and ignoring the returned value.
Call to prepare Path subsequently drawn from multiple threads,
to avoid a race condition where each draw separately computes the bounds.
### Example
#### Example Output
~~~~
#Volatile
uncached avg: 0.18048 ms
cached avg: 0.182784 ms
~~~~
### See Also
getBounds
---
## computeTightBounds
SkRect computeTightBounds() const
Returns minimum and maximum x and y values of the lines and curves in Path.
Returns (0, 0, 0, 0) if Path contains no points.
Returned bounds width and height may be larger or smaller than area affected
when Path is drawn.
Includes Points associated with kMove Verb that define empty
Contours.
Behaves identically to getBounds when Path contains
only lines. If Path contains curves, computed bounds includes
the maximum extent of the Quad, Conic, or Cubic; is slower than getBounds;
and unlike getBounds, does not cache the result.
### Return Value
tight bounds of curves in Path
### Example
#### Example Output
~~~~
empty bounds = 0, 0, 0, 0
circle bounds = 25, 20, 75, 70
rotated circle bounds = 25, 20, 75, 70
~~~~
### See Also
getBounds
---
## conservativelyContainsRect
bool conservativelyContainsRect(const SkRect& rect) const
Returns true if rect is contained by Path.
May return false when rect is contained by Path.
For now, only returns true if Path has one Contour and is convex.
rect may share points and edges with Path and be contained.
Returns true if rect is empty, that is, it has zero width or height; and
the Point or Line described by rect is contained by Path.
### Parameters
### Return Value
true if rect is contained
### Example
Rect is drawn in blue if it is contained by red
Path.
### See Also
contains Op Rect Convexity
---
## incReserve
void incReserve(unsigned extraPtCount)
grows Path Verb Array and Point Array to contain extraPtCount additional Points.
May improve performance and use less memory by
reducing the number and size of allocations when creating Path.
### Parameters
### Example
### See Also
Point Array
---
## moveTo
void moveTo(SkScalar x, SkScalar y)
Adds beginning of Contour at Point (x, y).
### Parameters
### Example
### See Also
Contour lineTo rMoveTo quadTo conicTo cubicTo close
---
void moveTo(const SkPoint& p)
Adds beginning of Contour at Point p.
### Parameters
### Example
### See Also
Contour lineTo rMoveTo quadTo conicTo cubicTo close
---
## rMoveTo
void rMoveTo(SkScalar dx, SkScalar dy)
Adds beginning of Contour relative to Last Point.
If Path is empty, starts Contour at (dx, dy).
Otherwise, start Contour at Last Point offset by (dx, dy).
Function name stands for "relative move to".
### Parameters
### Example
### See Also
Contour lineTo moveTo quadTo conicTo cubicTo close
---
## lineTo
void lineTo(SkScalar x, SkScalar y)
Adds Line from Last Point to (x, y). If Path is empty, or last Verb is
kClose Verb, Last Point is set to (0, 0) before adding Line.
lineTo appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed.
lineTo then appends kLine Verb to Verb Array and (x, y) to Point Array.
### Parameters
### Example
### See Also
Contour moveTo rLineTo addRect
---
void lineTo(const SkPoint& p)
Adds Line from Last Point to Point p. If Path is empty, or last Verb is
kClose Verb, Last Point is set to (0, 0) before adding Line.
lineTo first appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed.
lineTo then appends kLine Verb to Verb Array and Point p to Point Array.
### Parameters
### Example
### See Also
Contour moveTo rLineTo addRect
---
## rLineTo
void rLineTo(SkScalar dx, SkScalar dy)
Adds Line from Last Point to Vector (dx, dy). If Path is empty, or last Verb is
kClose Verb, Last Point is set to (0, 0) before adding Line.
Appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed;
then appends kLine Verb to Verb Array and Line end to Point Array.
Line end is Last Point plus Vector (dx, dy).
Function name stands for "relative line to".
### Parameters
### Example
### See Also
Contour moveTo lineTo addRect
---
# Quad
Quad describes a quadratic Bezier, a second-order curve identical to a section
of a parabola. Quad begins at a start Point, curves towards a control Point,
and then curves to an end Point.
### Example
Quad is a special case of Conic where Conic Weight is set to one.
Quad is always contained by the triangle connecting its three Points. Quad
begins tangent to the line between start Point and control Point, and ends
tangent to the line between control Point and end Point.
### Example
## quadTo
void quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2)
Adds Quad from Last Point towards (x1, y1), to (x2, y2).
If Path is empty, or last Verb is kClose Verb, Last Point is set to (0, 0)
before adding Quad.
Appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed;
then appends kQuad Verb to Verb Array; and (x1, y1), (x2, y2)
to Point Array.
### Parameters
### Example
### See Also
Contour moveTo conicTo rQuadTo
---
void quadTo(const SkPoint& p1, const SkPoint& p2)
Adds Quad from Last Point towards Point p1, to Point p2.
If Path is empty, or last Verb is kClose Verb, Last Point is set to (0, 0)
before adding Quad.
Appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed;
then appends kQuad Verb to Verb Array; and Points p1, p2
to Point Array.
### Parameters
### Example
### See Also
Contour moveTo conicTo rQuadTo
---
## rQuadTo
void rQuadTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2)
Adds Quad from Last Point towards Vector (dx1, dy1), to Vector (dx2, dy2).
If Path is empty, or last Verb
is kClose Verb, Last Point is set to (0, 0) before adding Quad.
Appends kMove Verb to Verb Array and (0, 0) to Point Array,
if needed; then appends kQuad Verb to Verb Array; and appends Quad
control and Quad end to Point Array.
Quad control is Last Point plus Vector (dx1, dy1).
Quad end is Last Point plus Vector (dx2, dy2).
Function name stands for "relative quad to".
### Parameters
### Example
### See Also
Contour moveTo conicTo quadTo
---
# Conic
Conic describes a conical section: a piece of an ellipse, or a piece of a
parabola, or a piece of a hyperbola. Conic begins at a start Point,
curves towards a control Point, and then curves to an end Point. The influence
of the control Point is determined by Conic Weight.
Each Conic in Path adds two Points and one Conic Weight. Conic Weights in Path
may be inspected with Iter, or with RawIter.
## Weight
Weight determines both the strength of the control Point and the type of Conic.
If Weight is exactly one, then Conic is identical to Quad; it is always a
parabolic segment.
### Example
#### Example Output
~~~~
move {0, 0},
quad {0, 0}, {20, 30}, {50, 60},
done
~~~~
If weight is less than one, Conic is an elliptical segment.
### Example
A 90 degree circular arc has the weight1 / sqrt(2).
#### Example Output
~~~~
move {0, 0},
conic {0, 0}, {20, 0}, {20, 20}, weight = 0.707107
done
~~~~
If weight is greater than one, Conic is a hyperbolic segment. As weight gets large,
a hyperbolic segment can be approximated by straight lines connecting the
control Point with the end Points.
### Example
#### Example Output
~~~~
move {0, 0},
line {0, 0}, {20, 0},
line {20, 0}, {20, 20},
done
~~~~
## conicTo
void conicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar w)
Adds Conic from Last Point towards (x1, y1), to (x2, y2), weighted by w.
If Path is empty, or last Verb is kClose Verb, Last Point is set to (0, 0)
before adding Conic.
Appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed.
If w is finite and not one, appends kConic Verb to Verb Array;
and (x1, y1), (x2, y2) to Point Array; and w to Conic Weights.
If w is one, appends kQuad Verb to Verb Array, and
(x1, y1), (x2, y2) to Point Array.
If w is not finite, appends kLine Verb twice to Verb Array, and
(x1, y1), (x2, y2) to Point Array.
### Parameters
### Example
As weight increases, curve is pulled towards control point.
The bottom two curves are elliptical; the next is parabolic; the
top curve is hyperbolic.
### See Also
rConicTo arcTo addArc quadTo
---
void conicTo(const SkPoint& p1, const SkPoint& p2, SkScalar w)
Adds Conic from Last Point towards Point p1, to Point p2, weighted by w.
If Path is empty, or last Verb is kClose Verb, Last Point is set to (0, 0)
before adding Conic.
Appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed.
If w is finite and not one, appends kConic Verb to Verb Array;
and Points p1, p2 to Point Array; and w to Conic Weights.
If w is one, appends kQuad Verb to Verb Array, and Points p1, p2
to Point Array.
If w is not finite, appends kLine Verb twice to Verb Array, and
Points p1, p2 to Point Array.
### Parameters
### Example
Conics and arcs use identical representations. As the arc sweep increases
the
Conic Weight also increases, but remains smaller than one.
### See Also
rConicTo arcTo addArc quadTo
---
## rConicTo
void rConicTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2, SkScalar w)
Adds Conic from Last Point towards Vector (dx1, dy1), to Vector (dx2, dy2),
weighted by w. If Path is empty, or last Verb
is kClose Verb, Last Point is set to (0, 0) before adding Conic.
Appends kMove Verb to Verb Array and (0, 0) to Point Array,
if needed.
If w is finite and not one, next appends kConic Verb to Verb Array,
and w is recorded as Conic Weight; otherwise, if w is one, appends
kQuad Verb to Verb Array; or if w is not finite, appends kLine Verb
twice to Verb Array.
In all cases appends Points control and end to Point Array.
control is Last Point plus Vector (dx1, dy1).
end is Last Point plus Vector (dx2, dy2).
Function name stands for "relative conic to".
### Parameters
### Example
### See Also
conicTo arcTo addArc quadTo
---
# Cubic
Cubic describes a Bezier curve segment described by a third-order polynomial.
Cubic begins at a start Point, curving towards the first control Point;
and curves from the end Point towards the second control Point.
### Example
## cubicTo
void cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3,
SkScalar y3)
Adds Cubic from Last Point towards (x1, y1), then towards (x2, y2), ending at
(x3, y3). If Path is empty, or last Verb is kClose Verb, Last Point is set to
(0, 0) before adding Cubic.
Appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed;
then appends kCubic Verb to Verb Array; and (x1, y1), (x2, y2), (x3, y3)
to Point Array.
### Parameters
### Example
### See Also
Contour moveTo rCubicTo quadTo
---
void cubicTo(const SkPoint& p1, const SkPoint& p2, const SkPoint& p3)
Adds Cubic from Last Point towards Point p1, then towards Point p2, ending at
Point p3. If Path is empty, or last Verb is kClose Verb, Last Point is set to
(0, 0) before adding Cubic.
Appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed;
then appends kCubic Verb to Verb Array; and Points p1, p2, p3
to Point Array.
### Parameters
### Example
### See Also
Contour moveTo rCubicTo quadTo
---
## rCubicTo
void rCubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3,
SkScalar y3)
Adds Cubic from Last Point towards Vector (dx1, dy1), then towards
Vector (dx2, dy2), to Vector (dx3, dy3).
If Path is empty, or last Verb
is kClose Verb, Last Point is set to (0, 0) before adding Cubic.
Appends kMove Verb to Verb Array and (0, 0) to Point Array,
if needed; then appends kCubic Verb to Verb Array; and appends Cubic
control and Cubic end to Point Array.
Cubic control is Last Point plus Vector (dx1, dy1).
Cubic end is Last Point plus Vector (dx2, dy2).
Function name stands for "relative cubic to".
### Parameters
### Example
### See Also
Contour moveTo cubicTo quadTo
---
# Arc
Arc can be constructed in a number of ways. Arc may be described by part of Oval and angles,
by start point and end point, and by radius and tangent lines. Each construction has advantages,
and some constructions correspond to Arc drawing in graphics standards.
All Arc draws are implemented by one or more Conic draws. When Conic Weight is less than one,
Conic describes an Arc of some Oval or Circle.
arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo)
describes Arc as a piece of Oval, beginning at start angle, sweeping clockwise or counterclockwise,
which may continue Contour or start a new one. This construction is similar to PostScript and
HTML Canvas arcs. Variation addArc always starts new Contour. Canvas::drawArc draws without
requiring Path.
arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius)
describes Arc as tangent to the line (x0, y0), (x1, y1) and tangent to the line (x1, y1), (x2, y2)
where (x0, y0) is the last Point added to Path. This construction is similar to PostScript and
HTML Canvas arcs.
arcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc, Direction sweep,
SkScalar x, SkScalar y)
describes Arc as part of Oval with radii (rx, ry), beginning at
last Point added to Path and ending at (x, y). More than one Arc satisfies this criteria,
so additional values choose a single solution. This construction is similar to SVG arcs.
conicTo describes Arc of less than 180 degrees as a pair of tangent lines and Conic Weight.
conicTo can represent any Arc with a sweep less than 180 degrees at any rotation. All arcTo
constructions are converted to Conic data when added to Path.
### Example
1 arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo) |
2 parameter sets force MoveTo |
3 start angle must be multiple of 90 degrees. |
4 arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius) |
5 arcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc,
Direction sweep, SkScalar x, SkScalar y) |
### Example
1 describes an arc from an oval, a starting angle, and a sweep angle.
2 is similar to 1, but does not require building a path to draw.
3 is similar to 1, but always begins new
Contour.
4 describes an arc from a pair of tangent lines and a radius.
5 describes an arc from
Oval center, arc start
Point and arc end
Point.
6 describes an arc from a pair of tangent lines and a
Conic Weight.
## arcTo
void arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
bool forceMoveTo)
Append Arc to Path. Arc added is part of ellipse
bounded by oval, from startAngle through sweepAngle. Both startAngle and
sweepAngle are measured in degrees, where zero degrees is aligned with the
positive x-axis, and positive sweeps extends Arc clockwise.
arcTo adds Line connecting Path last Point to initial Arc Point if forceMoveTo
is false and Path is not empty. Otherwise, added Contour begins with first point
of Arc. Angles greater than -360 and less than 360 are treated modulo 360.
### Parameters
### Example
### See Also
addArc SkCanvas::drawArc conicTo
---
void arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius)
Append Arc to Path, after appending Line if needed. Arc is implemented by Conic
weighted to describe part of Circle. Arc is contained by tangent from
last Path point (x0, y0) to (x1, y1), and tangent from (x1, y1) to (x2, y2). Arc
is part of Circle sized to radius, positioned so it touches both tangent lines.
### Example
If last Path Point does not start Arc, arcTo appends connecting Line to Path.
The length of Vector from (x1, y1) to (x2, y2) does not affect Arc.
### Example
Arc sweep is always less than 180 degrees. If radius is zero, or if
tangents are nearly parallel, arcTo appends Line from last Path Point to (x1, y1).
arcTo appends at most one Line and one Conic.
arcTo implements the functionality of PostScript Arct and HTML Canvas ArcTo.
### Parameters
x1 |
x common to pair of tangents |
y1 |
y common to pair of tangents |
x2 |
x end of second tangent |
y2 |
y end of second tangent |
radius |
distance from Arc to Circle center |
### Example
#### Example Output
~~~~
move to (156,20)
line (156,20),(79.2893,20)
conic (79.2893,20),(200,20),(114.645,105.355) weight 0.382683
~~~~
### See Also
conicTo
---
void arcTo(const SkPoint p1, const SkPoint p2, SkScalar radius)
Append Arc to Path, after appending Line if needed. Arc is implemented by Conic
weighted to describe part of Circle. Arc is contained by tangent from
last Path point to p1, and tangent from p1 to p2. Arc
is part of Circle sized to radius, positioned so it touches both tangent lines.
If last Path Point does not start Arc, arcTo appends connecting Line to Path.
The length of Vector from p1 to p2 does not affect Arc.
Arc sweep is always less than 180 degrees. If radius is zero, or if
tangents are nearly parallel, arcTo appends Line from last Path Point to p1.
arcTo appends at most one Line and one Conic.
arcTo implements the functionality of PostScript Arct and HTML Canvas ArcTo.
### Parameters
### Example
Because tangent lines are parallel,
arcTo appends line from last
Path Point to
p1, but does not append a circular
Conic.
#### Example Output
~~~~
move to (156,20)
line (156,20),(200,20)
~~~~
### See Also
conicTo
---
## Enum SkPath::ArcSize
enum ArcSize {
kSmall ArcSize,
kLarge ArcSize,
};
Four Oval parts with radii (rx, ry) start at last Path Point and ends at (x, y).
ArcSize and Direction select one of the four Oval parts.
### Constants
### Example
Arc begins at top of
Oval pair and ends at bottom.
Arc can take four routes to get there.
Two routes are large, and two routes are counterclockwise. The one route both large
and counterclockwise is blue.
### See Also
arcTo Direction
void arcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc,
Direction sweep, SkScalar x, SkScalar y)
Append Arc to Path. Arc is implemented by one or more Conics weighted to
describe part of Oval with radii (rx, ry) rotated by xAxisRotate degrees. Arc
curves from last Path Point to (x, y), choosing one of four possible routes:
clockwise or counterclockwise, and smaller or larger.
Arc sweep is always less than 360 degrees. arcTo appends Line to (x, y) if
either radii are zero, or if last Path Point equals (x, y). arcTo scales radii
(rx, ry) to fit last Path Point and (x, y) if both are greater than zero but
too small.
arcTo appends up to four Conic curves.
arcTo implements the functionality of SVG Arc, although SVG "" value
is opposite the integer value of sweep; SVG "" uses 1 for clockwise,
while kCW Direction cast to int is zero.
### Parameters
rx |
radius in x before x-axis rotation |
ry |
radius in y before x-axis rotation |
xAxisRotate |
x-axis rotation in degrees; positive values are clockwise |
largeArc |
chooses smaller or larger Arc |
sweep |
chooses clockwise or counterclockwise Arc |
x |
end of Arc |
y |
end of Arc |
### Example
### See Also
rArcTo ArcSize Direction
---
void arcTo(const SkPoint r, SkScalar xAxisRotate, ArcSize largeArc,
Direction sweep, const SkPoint xy)
Append Arc to Path. Arc is implemented by one or more Conic weighted to describe part of Oval
with radii (r.fX, r.fY) rotated by xAxisRotate degrees. Arc curves from last Path Point to
(xy.fX, xy.fY), choosing one of four possible routes: clockwise or counterclockwise,
and smaller or larger.
Arc sweep is always less than 360 degrees. arcTo appends Line to xy if either radii are zero,
or if last Path Point equals (x, y). arcTo scales radii r to fit last Path Point and
xy if both are greater than zero but too small to describe an arc.
arcTo appends up to four Conic curves.
arcTo implements the functionality of SVG Arc, although SVG "" value is
opposite the integer value of sweep; SVG "" uses 1 for clockwise, while
kCW Direction cast to int is zero.
### Parameters
r |
radii in x and y before x-axis rotation |
xAxisRotate |
x-axis rotation in degrees; positive values are clockwise |
largeArc |
chooses smaller or larger Arc |
sweep |
chooses clockwise or counterclockwise Arc |
xy |
end of Arc |
### Example
### See Also
rArcTo ArcSize Direction
---
## rArcTo
void rArcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc,
Direction sweep, SkScalar dx, SkScalar dy)
Append Arc to Path, relative to last Path Point. Arc is implemented by one or
more Conic, weighted to describe part of Oval with radii (rx, ry) rotated by
xAxisRotate degrees. Arc curves from last Path Point (x0, y0) to end Point:
(x0 + dx, y0 + dy),
choosing one of four possible routes: clockwise or
counterclockwise, and smaller or larger. If Path is empty, the start Arc Point
is (0, 0).
Arc sweep is always less than 360 degrees. arcTo appends Line to end Point
if either radii are zero, or if last Path Point equals end Point.
arcTo scales radii (rx, ry) to fit last Path Point and end Point if both are
greater than zero but too small to describe an arc.
arcTo appends up to four Conic curves.
arcTo implements the functionality of SVG Arc, although SVG "" value is
opposite the integer value of sweep; SVG "" uses 1 for clockwise, while
kCW Direction cast to int is zero.
### Parameters
### Example
### See Also
arcTo ArcSize Direction
---
## close
void close()
Append kClose Verb to Path. A closed Contour connects the first and last Point
with Line, forming a continuous loop. Open and closed Contour draw the same
with SkPaint::kFill Style. With SkPaint::kStroke Style, open Contour draws
Paint Stroke Cap at Contour start and end; closed Contour draws
Paint Stroke Join at Contour start and end.
close has no effect if Path is empty or last Path Verb is kClose Verb.
### Example
### See Also
---
## IsInverseFillType
static bool IsInverseFillType(FillType fill)
Returns true if fill is inverted and Path with fill represents area outside
of its geometric bounds.
| FillType | is inverse |
| --- | --- |
| kWinding FillType | false |
| kEvenOdd FillType | false |
| kInverseWinding FillType | true |
| kInverseEvenOdd FillType | true |
### Parameters
### Return Value
true if Path fills outside its bounds
### Example
#### Example Output
~~~~
IsInverseFillType(kWinding_FillType) == false
IsInverseFillType(kEvenOdd_FillType) == false
IsInverseFillType(kInverseWinding_FillType) == true
IsInverseFillType(kInverseEvenOdd_FillType) == true
~~~~
### See Also
FillType getFillType setFillType ConvertToNonInverseFillType
---
## ConvertToNonInverseFillType
static FillType ConvertToNonInverseFillType(FillType fill)
Returns equivalent Fill Type representing Path fill inside its bounds.
.
| FillType | inside FillType |
| --- | --- |
| kWinding FillType | kWinding FillType |
| kEvenOdd FillType | kEvenOdd FillType |
| kInverseWinding FillType | kWinding FillType |
| kInverseEvenOdd FillType | kEvenOdd FillType |
### Parameters
### Return Value
fill, or kWinding FillType or kEvenOdd FillType if fill is inverted
### Example
#### Example Output
~~~~
ConvertToNonInverseFillType(kWinding_FillType) == kWinding_FillType
ConvertToNonInverseFillType(kEvenOdd_FillType) == kEvenOdd_FillType
ConvertToNonInverseFillType(kInverseWinding_FillType) == kWinding_FillType
ConvertToNonInverseFillType(kInverseEvenOdd_FillType) == kEvenOdd_FillType
~~~~
### See Also
FillType getFillType setFillType IsInverseFillType
---
## ConvertConicToQuads
static int ConvertConicToQuads(const SkPoint& p0, const SkPoint& p1,
const SkPoint& p2, SkScalar w, SkPoint pts[],
int pow2)
Approximates Conic with Quad array. Conic is constructed from start Point p0,
control Point p1, end Point p2, and weight w.
Quad array is stored in pts; this storage is supplied by caller.
Maximum Quad count is 2 to the pow2.
Every third point in array shares last Point of previous Quad and first Point of
next Quad. Maximum pts storage size is given by:
(1 + 2 * (1 << pow2)) * sizeof(SkPoint).
Returns Quad count used the approximation, which may be smaller
than the number requested.
Conic Weight determines the amount of influence Conic control point has on the curve.
w less than one represents an elliptical section. w greater than one represents
a hyperbolic section. w equal to one represents a parabolic section.
Two Quad curves are sufficient to approximate an elliptical Conic with a sweep
of up to 90 degrees; in this case, set pow2 to one.
### Parameters
### Return Value
number of Quad curves written to pts
### Example
A pair of
Quad curves are drawn in red on top of the elliptical
Conic curve in black.
The middle curve is nearly circular. The top-right curve is parabolic, which can
be drawn exactly with a single
Quad.
### See Also
Conic Quad
---
## isRect
bool isRect(SkRect* rect, bool* isClosed = nullptr,
Direction* direction = nullptr) const
Returns true if Path is equivalent to Rect when filled.
If false: rect, isClosed, and direction are unchanged.
If true: rect, isClosed, and direction are written to if not nullptr.
rect may be smaller than the Path bounds. Path bounds may include kMove Verb points
that do not alter the area drawn by the returned rect.
### Parameters
### Return Value
true if Path contains Rect
### Example
#### Example Output
~~~~
empty is not rect
addRect is rect (10, 20, 30, 40); is closed; direction CW
moveTo is rect (10, 20, 30, 40); is closed; direction CW
lineTo is not rect
addPoly is rect (0, 0, 80, 80); is not closed; direction CCW
~~~~
### See Also
computeTightBounds conservativelyContainsRect getBounds isConvex isLastContourClosed isNestedFillRects
---
## isNestedFillRects
bool isNestedFillRects(SkRect rect[2], Direction dirs[2] = nullptr) const
Returns true if Path is equivalent to nested Rect pair when filled.
If false, rect and dirs are unchanged.
If true, rect and dirs are written to if not nullptr:
setting rect[0] to outer Rect, and rect[1] to inner Rect;
setting dirs[0] to Direction of outer Rect, and dirs[1] to Direction of inner
Rect.
### Parameters
### Return Value
true if Path contains nested Rect pair
### Example
#### Example Output
~~~~
outer (7.5, 17.5, 32.5, 42.5); direction CW
inner (12.5, 22.5, 27.5, 37.5); direction CCW
~~~~
### See Also
computeTightBounds conservativelyContainsRect getBounds isConvex isLastContourClosed isRect
---
## addRect
void addRect(const SkRect& rect, Direction dir = kCW_Direction)
Add Rect to Path, appending kMove Verb, three kLine Verb, and kClose Verb,
starting with top-left corner of Rect; followed by top-right, bottom-right,
and bottom-left if dir is kCW Direction; or followed by bottom-left,
bottom-right, and top-right if dir is kCCW Direction.
### Parameters
### Example
The left
Rect dashes starting at the top-left corner, to the right.
The right
Rect dashes starting at the top-left corner, towards the bottom.
### See Also
SkCanvas::drawRect Direction
---
void addRect(const SkRect& rect, Direction dir, unsigned start)
Add Rect to Path, appending kMove Verb, three kLine Verb, and kClose Verb.
If dir is kCW Direction, Rect corners are added clockwise; if dir is
kCCW Direction, Rect corners are added counterclockwise.
start determines the first corner added.
| start | first corner |
| --- | --- |
| 0 | top-left |
| 1 | top-right |
| 2 | bottom-right |
| 3 | bottom-left |
### Parameters
### Example
The arrow is just after the initial corner and points towards the next
corner appended to
Path.
### See Also
SkCanvas::drawRect Direction
---
void addRect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom,
Direction dir = kCW_Direction)
Add Rect (left, top, right, bottom) to Path,
appending kMove Verb, three kLine Verb, and kClose Verb,
starting with top-left corner of Rect; followed by top-right, bottom-right,
and bottom-left if dir is kCW Direction; or followed by bottom-left,
bottom-right, and top-right if dir is kCCW Direction.
### Parameters
### Example
The
left Rect dashes start at the top-left corner, and continue to the
right.
The
right Rect dashes start at the top-left corner, and continue down.
### See Also
SkCanvas::drawRect Direction
---
## addOval
void addOval(const SkRect& oval, Direction dir = kCW_Direction)
Add Oval to path, appending kMove Verb, four kConic Verb, and kClose Verb.
Oval is upright ellipse bounded by Rect oval with radii equal to half oval width
and half oval height. Oval begins at (oval.fRight, oval.centerY()) and continues
clockwise if dir is kCW Direction, counterclockwise if dir is kCCW Direction.
This form is identical to
### Parameters
### Example
### See Also
SkCanvas::drawOval Direction Oval
---
void addOval(const SkRect& oval, Direction dir, unsigned start)
Add Oval to Path, appending kMove Verb, four kConic Verb, and kClose Verb.
Oval is upright ellipse bounded by Rect oval with radii equal to half oval width
and half oval height. Oval begins at start and continues
clockwise if dir is kCW Direction, counterclockwise if dir is kCCW Direction.
| start | Point |
| --- | --- |
| 0 | oval.centerX(), oval.fTop |
| 1 | oval.fRight, oval.centerY() |
| 2 | oval.centerX(), oval.fBottom |
| 3 | oval.fLeft, oval.centerY() |
### Parameters
### Example
### See Also
SkCanvas::drawOval Direction Oval
---
## addCircle
void addCircle(SkScalar x, SkScalar y, SkScalar radius,
Direction dir = kCW_Direction)
Add Circle centered at (x, y) of size radius to Path, appending kMove Verb,
four kConic Verb, and kClose Verb. Circle begins at:
(x + radius, y),
continuing
clockwise if dir is kCW Direction, and counterclockwise if dir is kCCW Direction.
Has no effect if radius is zero or negative.
### Parameters
### Example
### See Also
SkCanvas::drawCircle Direction Circle
---
## addArc
void addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle)
Append Arc to Path, as the start of new Contour. Arc added is part of ellipse
bounded by oval, from startAngle through sweepAngle. Both startAngle and
sweepAngle are measured in degrees, where zero degrees is aligned with the
positive x-axis, and positive sweeps extends Arc clockwise.
If sweepAngle <= -360, or sweepAngle >= 360; and startAngle modulo 90 is nearly
zero, append Oval instead of Arc. Otherwise, sweepAngle values are treated
modulo 360, and Arc may or may not draw depending on numeric rounding.
### Parameters
oval |
bounds of ellipse containing Arc |
startAngle |
starting angle of Arc in degrees |
sweepAngle |
sweep, in degrees. Positive is clockwise; treated modulo 360 |
### Example
The middle row of the left and right columns draw differently from the entries
above and below because
sweepAngle is outside of the range of +/-360,
and
startAngle modulo 90 is not zero.
### See Also
Arc arcTo SkCanvas::drawArc
---
## addRoundRect
void addRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry,
Direction dir = kCW_Direction)
Append Round Rect to Path, creating a new closed Contour. Round Rect has bounds
equal to rect; each corner is 90 degrees of an ellipse with radii (rx, ry). If
dir is kCW Direction, Round Rect starts at top-left of the lower-left corner and
winds clockwise. If dir is kCCW Direction, Round Rect starts at the bottom-left
of the upper-left corner and winds counterclockwise.
If either rx or ry is too large, rx and ry are scaled uniformly until the
corners fit. If rx or ry is less than or equal to zero, addRoundRect appends
Rect rect to Path.
After appending, Path may be empty, or may contain: Rect, Oval, or RoundRect.
### Parameters
### Example
If either radius is zero, path
contains Rect and is drawn red.
If sides are only radii, path
contains Oval and is drawn blue.
All remaining path draws are convex, and are drawn in gray; no
paths constructed from
addRoundRect are concave, so none are
drawn in green.
### See Also
addRRect SkCanvas::drawRoundRect
---
void addRoundRect(const SkRect& rect, const SkScalar radii[],
Direction dir = kCW_Direction)
Append Round Rect to Path, creating a new closed Contour. Round Rect has bounds
equal to rect; each corner is 90 degrees of an ellipse with radii from the
array.
| radii index | location |
| --- | --- |
| 0 | x-radius of top-left corner |
| 1 | y-radius of top-left corner |
| 2 | x-radius of top-right corner |
| 3 | y-radius of top-right corner |
| 4 | x-radius of bottom-right corner |
| 5 | y-radius of bottom-right corner |
| 6 | x-radius of bottom-left corner |
| 7 | y-radius of bottom-left corner |
If dir is kCW Direction, Round Rect starts at top-left of the lower-left corner
and winds clockwise. If dir is kCCW Direction, Round Rect starts at the
bottom-left of the upper-left corner and winds counterclockwise.
If both radii on any side of rect exceed its length, all radii are scaled
uniformly until the corners fit. If either radius of a corner is less than or
equal to zero, both are treated as zero.
After appending, Path may be empty, or may contain: Rect, Oval, or RoundRect.
### Parameters
### Example
### See Also
addRRect SkCanvas::drawRoundRect
---
## addRRect
void addRRect(const SkRRect& rrect, Direction dir = kCW_Direction)
Add rrect to Path, creating a new closed Contour. If
dir is kCW Direction, rrect starts at top-left of the lower-left corner and
winds clockwise. If dir is kCCW Direction, rrect starts at the bottom-left
of the upper-left corner and winds counterclockwise.
After appending, Path may be empty, or may contain: Rect, Oval, or Round Rect.
### Parameters
### Example
### See Also
addRoundRect SkCanvas::drawRRect
---
void addRRect(const SkRRect& rrect, Direction dir, unsigned start)
Add rrect to Path, creating a new closed Contour. If dir is kCW Direction, rrect
winds clockwise; if dir is kCCW Direction, rrect winds counterclockwise.
start determines the first point of rrect to add.
| start | location |
| --- | --- |
| 0 | right of top-left corner |
| 1 | left of top-right corner |
| 2 | bottom of top-right corner |
| 3 | top of bottom-right corner |
| 4 | left of bottom-right corner |
| 5 | right of bottom-left corner |
| 6 | top of bottom-left corner |
| 7 | bottom of top-left corner |
After appending, Path may be empty, or may contain: Rect, Oval, or Round Rect.
### Parameters
### Example
### See Also
addRoundRect SkCanvas::drawRRect
---
## addPoly
void addPoly(const SkPoint pts[], int count, bool close)
Add Contour created from Line array, adding (count - 1) Line segments.
Contour added starts at pts[0], then adds a line for every additional Point
in pts array. If close is true,appends kClose Verb to Path, connecting
pts[count - 1] and pts[0].
If count is zero, append kMove Verb to path.
Has no effect if count is less than one.
### Parameters
### Example
### See Also
SkCanvas::drawPoints
---
## Enum SkPath::AddPathMode
enum AddPathMode {
kAppend AddPathMode,
kExtend AddPathMode,
};
AddPathMode chooses how addPath appends. Adding one Path to another can extend
the last Contour or start a new Contour.
### Constants
### Example
test is built from path, open on the top row, and closed on the bottom row.
The left column uses
kAppend AddPathMode; the right uses
kExtend AddPathMode.
The top right composition is made up of one contour; the other three have two.
### See Also
addPath reverseAddPath
## addPath
void addPath(const SkPath& src, SkScalar dx, SkScalar dy,
AddPathMode mode = kAppend_AddPathMode)
Append src to Path, offset by (dx, dy).
If mode is kAppend AddPathMode, src Verb Array, Point Array, and Conic Weights are
added unaltered. If mode is kExtend AddPathMode, add Line before appending
Verbs, Points, and Conic Weights.
### Parameters
### Example
### See Also
AddPathMode offset reverseAddPath
---
void addPath(const SkPath& src, AddPathMode mode = kAppend_AddPathMode)
Append src to Path.
If mode is kAppend AddPathMode, src Verb Array, Point Array, and Conic Weights are
added unaltered. If mode is kExtend AddPathMode, add Line before appending
Verbs, Points, and Conic Weights.
### Parameters
### Example
### See Also
AddPathMode reverseAddPath
---
void addPath(const SkPath& src, const SkMatrix& matrix,
AddPathMode mode = kAppend_AddPathMode)
Append src to Path, transformed by matrix. Transformed curves may have different
Verbs, Points, and Conic Weights.
If mode is kAppend AddPathMode, src Verb Array, Point Array, and Conic Weights are
added unaltered. If mode is kExtend AddPathMode, add Line before appending
Verbs, Points, and Conic Weights.
### Parameters
### Example
### See Also
AddPathMode transform offset reverseAddPath
---
## reverseAddPath
void reverseAddPath(const SkPath& src)
Append src to Path, from back to front.
Reversed src always appends a new Contour to Path.
### Parameters
### Example
### See Also
AddPathMode transform offset addPath
---
## offset
void offset(SkScalar dx, SkScalar dy, SkPath* dst) const
Offset Point Array by (dx, dy). Offset Path replaces dst.
If dst is nullptr, Path is replaced by offset data.
### Parameters
### Example
### See Also
addPath transform
---
void offset(SkScalar dx, SkScalar dy)
Offset Point Array by (dx, dy). Path is replaced by offset data.
### Parameters
### Example
### See Also
addPath transform SkCanvas::translate()
---
## transform
void transform(const SkMatrix& matrix, SkPath* dst) const
Transform Verb Array, Point Array, and weight by matrix.
transform may change Verbs and increase their number.
Transformed Path replaces dst; if dst is nullptr, original data
is replaced.
### Parameters
### Example
### See Also
addPath offset SkCanvas::concat() SkMatrix
---
void transform(const SkMatrix& matrix)
Transform Verb Array, Point Array, and weight by matrix.
transform may change Verbs and increase their number.
Path is replaced by transformed data.
### Parameters
### Example
### See Also
addPath offset SkCanvas::concat() SkMatrix
---
## Last Point
Path is defined cumulatively, often by adding a segment to the end of last
Contour. Last Point of Contour is shared as first Point of added Line or Curve.
Last Point can be read and written directly with getLastPt and setLastPt.
## getLastPt
bool getLastPt(SkPoint* lastPt) const
Returns Last Point on Path in lastPt. Returns false if Point Array is empty,
storing (0, 0) if lastPt is not nullptr.
### Parameters
### Return Value
true if Point Array contains one or more Points
### Example
#### Example Output
~~~~
last point: 35.2786, 52.9772
~~~~
### See Also
setLastPt
---
## setLastPt
void setLastPt(SkScalar x, SkScalar y)
Set Last Point to (x, y). If Point Array is empty, append kMove Verb to
Verb Array and (x, y) to Point Array.
### Parameters
### Example
### See Also
getLastPt
---
void setLastPt(const SkPoint& p)
Set the last point on the path. If no points have been added,
### Parameters
### Example
### See Also
getLastPt
---
## Enum SkPath::SegmentMask
enum SegmentMask {
kLine SegmentMask = 1 << 0,
kQuad SegmentMask = 1 << 1,
kConic SegmentMask = 1 << 2,
kCubic SegmentMask = 1 << 3,
};
SegmentMask constants correspond to each drawing Verb type in Path; for
instance, if Path only contains Lines, only the kLine SegmentMask bit is set.
### Constants
### Example
#### Example Output
~~~~
Path kConic_SegmentMask is clear
Path kQuad_SegmentMask is set
~~~~
### See Also
getSegmentMasks Verb
## getSegmentMasks
uint32_t getSegmentMasks() const
Returns a mask, where each set bit corresponds to a SegmentMask constant
if Path contains one or more Verbs of that type.
Returns zero if Path contains no Lines, or Curves: Quads, Conics, or Cubics.
getSegmentMasks returns a cached result; it is very fast.
### Return Value
SegmentMask bits or zero
### Example
#### Example Output
~~~~
mask quad set
~~~~
### See Also
getSegmentMasks Verb
---
## contains
bool contains(SkScalar x, SkScalar y) const
Returns true if the point (x, y) is contained by Path, taking into
account FillType.
| FillType | contains returns true if Point is enclosed by |
| --- | --- |
| kWinding FillType | a non-zero sum of Contour Directions. |
| kEvenOdd FillType | an odd number of Contours. |
| kInverseWinding FillType | a zero sum of Contour Directions. |
| kInverseEvenOdd FillType | and even number of Contours. |
### Parameters
x |
x-coordinate of containment test |
y |
y-coordinate of containment test |
### Return Value
true if Point is in Path
### Example
### See Also
conservativelyContainsRect Fill Type Op
---
## dump
void dump(SkWStream* stream, bool forceClose, bool dumpAsHex) const
Writes text representation of Path to stream. If stream is nullptr, writes to
standard output. Set forceClose to true to get edges used to fill Path.
Set dumpAsHex true to generate exact binary representations
of floating point numbers used in Point Array and Conic Weights.
### Parameters
### Example
#### Example Output
~~~~
path.setFillType(SkPath::kWinding_FillType);
path.moveTo(0, 0);
path.quadTo(20, 30, 40, 50);
path.setFillType(SkPath::kWinding_FillType);
path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0
path.quadTo(SkBits2Float(0x41a00000), SkBits2Float(0x41f00000), SkBits2Float(0x42200000), SkBits2Float(0x42480000)); // 20, 30, 40, 50
path.setFillType(SkPath::kWinding_FillType);
path.moveTo(0, 0);
path.quadTo(20, 30, 40, 50);
path.lineTo(0, 0);
path.close();
path.setFillType(SkPath::kWinding_FillType);
path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0
path.quadTo(SkBits2Float(0x41a00000), SkBits2Float(0x41f00000), SkBits2Float(0x42200000), SkBits2Float(0x42480000)); // 20, 30, 40, 50
path.lineTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0
path.close();
~~~~
### See Also
SkRect::dump() SkRRect::dump() SkPathMeasure::dump()
---
void dump() const
Writes text representation of Path to standard output. The representation may be
directly compiled as C++ code. Floating point values are written
with limited precision; it may not be possible to reconstruct original Path
from output.
### Example
#### Example Output
~~~~
path.setFillType(SkPath::kWinding_FillType);
path.moveTo(0, 0);
path.lineTo(0.857143f, 0.666667f);
path is not equal to copy
~~~~
### See Also
dumpHex SkRect::dump() SkRRect::dump() SkPathMeasure::dump() writeToMemory
---
## dumpHex
void dumpHex() const
Writes text representation of Path to standard output. The representation may be
directly compiled as C++ code. Floating point values are written
in hexadecimal to preserve their exact bit pattern. The output reconstructs the
original Path.
Use instead of dump when submittingbug reports against Skia.
### Example
#### Example Output
~~~~
path.setFillType(SkPath::kWinding_FillType);
path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0
path.lineTo(SkBits2Float(0x3f5b6db7), SkBits2Float(0x3f2aaaab)); // 0.857143f, 0.666667f
path is equal to copy
~~~~
### See Also
dump
---
## writeToMemory
size_t writeToMemory(void* buffer) const
Writes Path to buffer, returning the number of bytes written.
Pass nullptr to obtain the storage size.
Writes Fill Type, Verb Array, Point Array, Conic Weight, and
additionally writes computed information like Convexity and bounds.
Use only be used in concert with readFromMemory;
the format used for Path in memory is not guaranteed.
### Parameters
### Return Value
size of storage required for Path; always a multiple of 4
### Example
#### Example Output
~~~~
path is equal to copy
~~~~
### See Also
serialize readFromMemory dump dumpHex
---
## serialize
sk_sp<SkData> serialize() const
Write Path to buffer, returning the buffer written to, wrapped in Data.
serialize writes Fill Type, Verb Array, Point Array, Conic Weight, and
additionally writes computed information like Convexity and bounds.
serialize should only be used in concert with readFromMemory.
The format used for Path in memory is not guaranteed.
### Return Value
Path data wrapped in Data buffer
### Example
#### Example Output
~~~~
path is equal to copy
~~~~
### See Also
writeToMemory readFromMemory dump dumpHex
---
## readFromMemory
size_t readFromMemory(const void* buffer, size_t length)
Initializes Path from buffer of size length. Returns zero if the buffer is
data is inconsistent, or the length is too small.
Reads Fill Type, Verb Array, Point Array, Conic Weight, and
additionally reads computed information like Convexity and bounds.
Used only in concert with writeToMemory;
the format used for Path in memory is not guaranteed.
### Parameters
### Return Value
number of bytes read, or zero on failure
### Example
#### Example Output
~~~~
length = 60; returned by readFromMemory = 0
length = 68; returned by readFromMemory = 64
~~~~
### See Also
writeToMemory
---
# Generation ID
Generation ID provides a quick way to check if Verb Array, Point Array, or
Conic Weight has changed. Generation ID is not a hash; identical Paths will
not necessarily have matching Generation IDs.
Empty Paths have a Generation ID of one.
## getGenerationID
uint32_t getGenerationID() const
Returns a non-zero, globally unique value. A different value is returned
if Verb Array, Point Array, or Conic Weight changes.
Setting Fill Type does not change Generation ID.
Each time the path is modified, a different Generation ID will be returned.
### Return Value
non-zero, globally unique value
### Example
#### Example Output
~~~~
empty genID = 1
1st lineTo genID = 2
empty genID = 1
2nd lineTo genID = 3
~~~~
### See Also
operator==(const SkPath& a, const SkPath& b)
---
## isValid
bool isValid() const
Returns if Path data is consistent. Corrupt Path data is detected if
internal values are out of range or internal storage does not match
array dimensions.
### Return Value
true if Path data is consistent
---
## pathRefIsValid
bool pathRefIsValid() const
Returns if Path data is consistent.
To be deprecated soon.
### Return Value
true if Path data is consistent
---
# Class SkPath::Iter
Iterates through Verb Array, and associated Point Array and Conic Weight.
Provides options to treat open Contours as closed, and to ignore
degenerate data.
class Iter {
public:
Iter();
Iter(const SkPath& path, bool forceClose);
void setPath(const SkPath& path, bool forceClose);
Verb next(SkPoint pts[4], bool doConsumeDegenerates = true, bool exact = false);
SkScalar conicWeight const;
bool isCloseLine const;
bool isClosedContour const;
};
### Example
Ignoring the actual
Verbs and replacing them with
Quads rounds the
path of the glyph.
### See Also
RawIter
## Iter
Iter()
Initializes Iter with an empty Path. next on Iter returns kDone Verb.
Call setPath to initialize Iter at a later time.
### Return Value
Iter of empty Path
### Example
#### Example Output
~~~~
iter is done
iter is done
~~~~
### See Also
setPath
---
Iter(const SkPath& path, bool forceClose)
Sets Iter to return elements of Verb Array, Point Array, and Conic Weight in path.
If forceClose is true, Iter will add kLine Verb and kClose Verb after each
open Contour. path is not altered.
### Parameters
### Return Value
Iter of path
### Example
#### Example Output
~~~~
open:
kMove_Verb {0, 0},
kQuad_Verb {0, 0}, {10, 20}, {30, 40},
kDone_Verb
closed:
kMove_Verb {0, 0},
kQuad_Verb {0, 0}, {10, 20}, {30, 40},
kLine_Verb {30, 40}, {0, 0},
kClose_Verb {0, 0},
kDone_Verb
~~~~
### See Also
setPath
---
## setPath
void setPath(const SkPath& path, bool forceClose)
Sets Iter to return elements of Verb Array, Point Array, and Conic Weight in path.
If forceClose is true, Iter will add kLine Verb and kClose Verb after each
open Contour. path is not altered.
### Parameters
### Example
#### Example Output
~~~~
quad open:
kMove_Verb {0, 0},
kQuad_Verb {0, 0}, {10, 20}, {30, 40},
kDone_Verb
conic closed:
kMove_Verb {0, 0},
kConic_Verb {0, 0}, {1, 2}, {3, 4}, weight = 0.5
kLine_Verb {3, 4}, {0, 0},
kClose_Verb {0, 0},
kDone_Verb
~~~~
### See Also
Iter(const SkPath& path, bool forceClose)
---
## next
Verb next(SkPoint pts[4], bool doConsumeDegenerates = true, bool exact = false)
Returns next Verb in Verb Array, and advances Iter.
When Verb Array is exhausted, returns kDone Verb.
Zero to four Points are stored in pts, depending on the returned Verb.
If doConsumeDegenerates is true, skip consecutive kMove Verb entries, returning
only the last in the series; and skip very small Lines, Quads, and Conics; and
skip kClose Verb following kMove Verb.
if doConsumeDegenerates is true and exact is true, only skip Lines, Quads, and
Conics with zero lengths.
### Parameters
### Return Value
next Verb from Verb Array
### Example
#### Example Output
~~~~
skip degenerate:
kMove_Verb {20, 20},
kQuad_Verb {20, 20}, {10, 20}, {30, 40},
kDone_Verb
skip degenerate if exact:
kMove_Verb {20, 20},
kQuad_Verb {20, 20}, {10, 20}, {30, 40},
kMove_Verb {30, 30},
kLine_Verb {30, 30}, {30.00001, 30},
kDone_Verb
skip none:
kMove_Verb {10, 10},
kMove_Verb {20, 20},
kQuad_Verb {20, 20}, {10, 20}, {30, 40},
kMove_Verb {1, 1},
kClose_Verb {1, 1},
kMove_Verb {30, 30},
kLine_Verb {30, 30}, {30, 30},
kMove_Verb {30, 30},
kLine_Verb {30, 30}, {30.00001, 30},
kDone_Verb
~~~~
### See Also
Verb IsLineDegenerate IsCubicDegenerate IsQuadDegenerate
---
## conicWeight
SkScalar conicWeight() const
Returns Conic Weight if next returned kConic Verb.
If next has not been called, or next did not return kConic Verb,
result is undefined.
### Return Value
Conic Weight for Conic Points returned by next
### Example
#### Example Output
~~~~
first verb is move
next verb is conic
conic points: {0,0}, {1,2}, {3,4}
conic weight: 0.5
~~~~
### See Also
Conic Weight
---
## isCloseLine
bool isCloseLine() const
Returns true if last kLine Verb returned by next was generated
by kClose Verb. When true, the end point returned by next is
also the start point of Contour.
If next has not been called, or next did not return kLine Verb,
result is undefined.
### Return Value
true if last kLine Verb was generated by kClose Verb
### Example
#### Example Output
~~~~
1st verb is move
moveTo point: {6,7}
2nd verb is conic
3rd verb is line
line points: {3,4}, {6,7}
line generated by close
4th verb is close
~~~~
### See Also
close
---
## isClosedContour
bool isClosedContour() const
Returns true if subsequent calls to next return kClose Verb before returning
kMove Verb. if true, Contour Iter is processing may end with kClose Verb, or
Iter may have been initialized with force close set to true.
### Return Value
true if Contour is closed
### Example
#### Example Output
~~~~
without close(), forceClose is false: isClosedContour returns false
with close(), forceClose is false: isClosedContour returns true
without close(), forceClose is true : isClosedContour returns true
with close(), forceClose is true : isClosedContour returns true
~~~~
### See Also
Iter(const SkPath& path, bool forceClose)
---
# Class SkPath::RawIter
Iterates through Verb Array, and associated Point Array and Conic Weight.
Verb Array, Point Array, and Conic Weight are returned unaltered.
class RawIter {
public:
RawIter();
RawIter(const SkPath& path);
void setPath(const SkPath& path);
Verb next(SkPoint pts[4]);
Verb peek const;
SkScalar conicWeight const;
}
## RawIter
RawIter()
Initializes RawIter with an empty Path. next on RawIter returns kDone Verb.
Call setPath to initialize Iter at a later time.
### Return Value
RawIter of empty Path
---
RawIter(const SkPath& path)
Sets RawIter to return elements of Verb Array, Point Array, and Conic Weight in path.
### Parameters
### Return Value
RawIter of path
---
## setPath
void setPath(const SkPath& path)
Sets Iter to return elements of Verb Array, Point Array, and Conic Weight in path.
### Parameters
---
## next
Verb next(SkPoint pts[4])
Returns next Verb in Verb Array, and advances RawIter.
When Verb Array is exhausted, returns kDone Verb.
Zero to four Points are stored in pts, depending on the returned Verb.
### Parameters
### Return Value
next Verb from Verb Array
### Example
#### Example Output
~~~~
kMove_Verb {50, 60},
kQuad_Verb {50, 60}, {10, 20}, {30, 40},
kClose_Verb {50, 60},
kMove_Verb {50, 60},
kLine_Verb {50, 60}, {30, 30},
kConic_Verb {30, 30}, {1, 2}, {3, 4}, weight = 0.5
kCubic_Verb {3, 4}, {-1, -2}, {-3, -4}, {-5, -6},
kDone_Verb
~~~~
### See Also
peek
---
## peek
Verb peek() const
Returns next Verb, but does not advance RawIter.
### Return Value
next Verb from Verb Array
### Example
#### Example Output
~~~~
#Volatile
peek Move == verb Move
peek Quad == verb Quad
peek Conic == verb Conic
peek Cubic == verb Cubic
peek Done == verb Done
peek Done == verb Done
~~~~
### See Also
next
---
## conicWeight
SkScalar conicWeight() const
Returns Conic Weight if next returned kConic Verb.
If next has not been called, or next did not return kConic Verb,
result is undefined.
### Return Value
Conic Weight for Conic Points returned by next
### Example
#### Example Output
~~~~
first verb is move
next verb is conic
conic points: {0,0}, {1,2}, {3,4}
conic weight: 0.5
~~~~
### See Also
Conic Weight
---