qualify bookmaker links to remove file reference if intra-file and add class reference if part of a class TBR=caryclark@google.com Docs-Preview: https://skia.org/?cl=38722 Bug: skia: 6898 Change-Id: Ie0548485a6e3f596efc0f15b819bd5060e983a5b Reviewed-on: https://skia-review.googlesource.com/38722 Reviewed-by: Cary Clark <caryclark@skia.org> Commit-Queue: Cary Clark <caryclark@skia.org>
228 KiB
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 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 decribes 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 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
Overview
Constants
constants | description |
---|---|
AddPathMode | Sets addPath options. |
ArcSize | Sets arcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc, Direction sweep, SkScalar x, SkScalar y) options. |
Convexity | Returns if Path is convex or concave. |
Direction | Sets Contour clockwise or counterclockwise. |
FillType | Sets winding rule and inverse fill. |
SegmentMask | |
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 stdout. |
dumpHex | Sends text representation using hexadecimal to stdout. |
experimentalValidateRef | Experimental; debugging only. |
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. |
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 | Initialize 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. |
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 | Refresh result of getBounds. |
writeToMemory | Copy 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 Weight; manage Contour, and terminate Path.
Constants
Each Verb has zero or more Points stored in Path. Path iterator returns complete curve descriptions, duplicating shared Points for consecutive entries. 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 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 Weight. 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. |
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
SkPath::kCW_Direction | Contour travels in a clockwise direction. | |
SkPath::kCCW_Direction | Contour travels in a counterclockwise direction. |
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
path | Path to copy by value. |
Return Value
Copy of Path.
Example
Example Output
path verbs: 2
path2 verbs: 3
after reset
path verbs: 0
path2 verbs: 3
See Also
~SkPath
~SkPath()
Releases ownership of any shared data and deletes data if Path is sole owner.
Example
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
path | Verb Array, Point Array, Weights, amd Fill Type to copy. |
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==
friend SK_API 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
a | Path to compare. |
b | Path to compare. |
Return Value
true if Path pair are equivalent.
Example
Example Output
empty one == two
moveTo one != two
rewind one == two
reset one == two
operator!=
friend 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
a | Path to compare. |
b | Path to compare. |
Return Value
true if Path pair are not equivalent.
Example
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 trival to interpolate a pair of Paths containing Conics with different Conic Weight values.
Parameters
compare | Path to compare. |
Return Value
true if Paths Verb Array and Weights are equivalent.
Example
Example Output
paths are interpolatable
See Also
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)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
ending | Point Array averaged with this Point Array. |
weight | Most useful when between zero (ending Point Array) and one (this Point Array); will work with values outside of this range. |
out |
Return Value
true if Paths contain same number of Points.
Example
See Also
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
Constants
SkPath::kWinding_FillType | Specifies fill as area is enclosed by a non-zero sum of Contour Directions. | |
SkPath::kEvenOdd_FillType | Specifies fill as area enclosed by an odd number of Contours. | |
SkPath::kInverseWinding_FillType | Specifies fill as area is enclosed by a zero sum of Contour Directions. | |
SkPath::kInverseEvenOdd_FillType | Specifies fill as area enclosed by an even number of Contours. |
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 setFillType does not check that ft is legal, values outside of FillType are not supported.
Parameters
ft | one of: kWinding FillType, kEvenOdd FillType, kInverseWinding FillType, kInverseEvenOdd FillType. |
Example
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
See Also
FillType getFillType setFillType isInverseFillType
Convexity
Enum SkPath::Convexity
enum Convexity { 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
SkPath::kUnknown_Convexity | Indicates Convexity has not been determined. | |
SkPath::kConvex_Convexity | Path has one Contour made of a simple geometry without indentations. | |
SkPath::kConcave_Convexity | Path has more than one Contour, or a geometry with indentations. |
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
convexity | One of kUnknown Convexity, kConvex Convexity, or kConcave Convexity. |
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
See Also
Convexity Contour Direction getConvexity getConvexityOrUnknown setConvexity
setIsConvex
void setIsConvex(bool isConvex)
Use setConvexity.
isOval
bool isOval(SkRect* rect, Direction* dir = nullptr, unsigned* start = nullptr) const
Path is Oval 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.
isOval triggers performance optimizations on some GPU Surface implementations.
Parameters
rect | storage for bounding Rect of Oval. Oval is Circle if rect width equals rect height. Unwritten if Path is not Oval. May be nullptr. |
dir | storage for Direction; kCW Direction if clockwise, kCCW Direction if counterclockwise. Unwritten if Path is not Oval. May be nullptr. |
start | storage for start of Oval: 0 for top, 1 for right, 2 for bottom, 3 for left. Unwritten if Path is not Oval. May be nullptr. |
Return Value
true if Path was constructed by method that reduces to Oval.
Example
See Also
isRRect
bool isRRect(SkRRect* rrect, Direction* dir = nullptr, unsigned* start = nullptr) const
Path is Round Rect if constructed by addRoundRect, addRRect; and if construction is not empty, not Rect, and not Oval. Path constructed with other other calls will not return true though Path draws Round Rect.
isRRect triggers performance optimizations on some GPU Surface implementations.
Parameters
rrect | storage for bounding Rect of Round Rect. Unwritten if Path is not Round Rect. May be nullptr. |
dir | storage for Direction; kCW Direction if clockwise, kCCW Direction if counterclockwise. Unwritten if Path is not Round Rect. May be nullptr. |
start | storage for start of Round Rect: 0 for top, 1 for right, 2 for bottom, 3 for left. Unwritten if Path is not Round Rect. May be nullptr. |
Return Value
true for Round Rect Path constructed by addRoundRect or addRRect.
Example
See Also
Round Rect addRoundRect addRRect
reset
void reset()
Sets Path to its intial 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
void rewind()
Sets Path to its intial 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
See Also
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
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
isFinite
bool isFinite() const
Finite Point array values are between negative SK ScalarMax and positive SK ScalarMax. Any Point array value of SK ScalarInfinity, SK ScalarNegativeInfinity, or SK ScalarNaN cause isFinite to return false.
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
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
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-volative 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
isVolatile | true if caller will alter Path after drawing. |
Example
See Also
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.
Parameters
p1 | Line start point. |
p2 | Line end point. |
exact | If true, returns true only if p1 equals p2. If false, returns true if p1 equals or nearly equals p2. |
Return Value
true if Line is degenerate; its length is effectively zero.
Example
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
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
p1 | Cubic start point. |
p2 | Cubic control point 1. |
p3 | Cubic control point 2. |
p4 | Cubic end point. |
exact | If true, returns true only if p1, p2, p3, and p4 are equal. If false, returns true if p1, p2, p3, and p4 are equal or nearly equal. |
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
line | storage for Line. May be nullptr. |
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: move to, line to, quad to; 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 | Number of points alloted in points storage; must be greater than or equal to zero. |
Return Value
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
int countPoints() const
Returns the number of points in Path. Point count is initially zero.
Return Value
Example
Example Output
empty point count: 0
zero line point count: 2
line point count: 2
second move point count: 3
See Also
getPoint
SkPoint getPoint(int index) const
Returns Point at index in Point Array. Valid range for index is 0 to countPoints - 1. If the index is out of range, getPoint returns (0, 0).
Parameters
index | Point Array element selector. |
Return Value
Point Array value or (0, 0).
Example
Example Output
point 0: (-10,-10)
point 1: (10,10)
See Also
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
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
verbs | If not null, receives up to max verbs |
max | The maximum number of verbs to copy into verbs |
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 util they are written to, making assignment as efficient as swap.
Parameters
other | Path exchanged by value. |
Example
Example Output
path1 bounds = 0, 0, 0, 0
path2 bounds = 10, 20, 30, 40
See Also
getBounds
const SkRect& getBounds() const
Returns minimum and maximum x and y values of Point Array. If Path contains no points, getBounds returns (0, 0, 0, 0). Returned bounds width and height may be larger or smaller than area affected when Path is drawn.
getBounds 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
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, updateBoundsCache is identical to getBounds, where the returned value is ignored.
updateBoundsCache prepares a 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
computeTightBounds
SkRect computeTightBounds() const
Returns minimum and maximum x and y values of the lines and curves in Path. If Path contains no points, computeTightBounds returns (0, 0, 0, 0). Returned bounds width and height may be larger or smaller than area affected when Path is drawn.
computeTightBounds behaves identically to getBounds when Path contains only lines. If Path contains curves, compute computeTightBounds includes the maximum extent of the Quad, Conic, or Cubic; is slower, and does not cache the result.
Like getBounds, computeTightBounds includes Points associated with kMove Verb that define empty Contours.
Return Value
Example
Example Output
empty bounds = 0, 0, 0, 0
circle bounds = 25, 20, 75, 70
rotated circle bounds = 25, 20, 75, 70
See Also
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. If rect is empty, that is, it has zero width or height; conservativelyContainsRect returns true if the Point or Line described by rect is contained by Path.
Parameters
rect | Rect, Line, or Point checked for containment. |
Return Value
true if rect is contained.
Example
See Also
incReserve
void incReserve(unsigned extraPtCount)
grows Path Verb Array and Point Array to contain extraPtCount additional Points. incReserve may improve performance and use less memory by reducing the number and size of allocations when creating Path.
Parameters
extraPtCount | number of additional Points to preallocate. |
Example
See Also
moveTo
void moveTo(SkScalar x, SkScalar y)
Adds beginning of Contour at Point (x, y).
Parameters
x | x-coordinate of Contour start. |
y | y-coordinate of Contour start. |
Example
See Also
Contour lineTo rMoveTo quadTo conicTo cubicTo close
void moveTo(const SkPoint& p)
Adds beginning of Contour at Point p.
Parameters
p | Contour start. |
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). rMoveTo stands for relative move to.
Parameters
dx | offset from Last Point x to Contour start x. |
dy | offset from Last Point y to Contour start y. |
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
x | end of added Line in x. |
y | end of added Line in y. |
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
p | end Point of added Line. |
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.
rLineTo first appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed. rLineTo then appends kLine Verb to Verb Array and Line end to Point Array. Line end is Last Point plus Vector (dx, dy). rLineTo stands for relative line to.
Parameters
dx | offset from Last Point x to Line end x. |
dy | offset from Last Point y to Line end y. |
Example
See Also
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.
quadTo appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed. quadTo then appends kQuad Verb to Verb Array; and (x1, y1), (x2, y2) to Point Array.
Parameters
x1 | control Point of Quad in x. |
y1 | control Point of Quad in y. |
x2 | end Point of Quad in x. |
y2 | end Point of Quad in y. |
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.
quadTo appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed. quadTo then appends kQuad Verb to Verb Array; and Points p1, p2 to Point Array.
Parameters
p1 | control Point of added Quad. |
p2 | end Point of added Quad. |
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.
rQuadTo first appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed. rQuadTo 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). rQuadTo stands for relative quad to.
Parameters
dx1 | offset from Last Point x to Quad control x. |
dy1 | offset from Last Point x to Quad control y. |
dx2 | offset from Last Point x to Quad end x. |
dy2 | offset from Last Point x to Quad end y. |
Example
See Also
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 Weight. 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
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 w 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.
conicTo appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed.
If w is finite and not one, conicTo then appends kConic Verb to Verb Array; and (x1, y1), (x2, y2) to Point Array; and w to Weights.
If w is one, conicTo appends kQuad Verb to Verb Array, and (x1, y1), (x2, y2) to Point Array.
If w is not finite, conicTo appends kLine Verb twice to Verb Array, and (x1, y1), (x2, y2) to Point Array.
Parameters
x1 | control Point of Conic in x. |
y1 | control Point of Conic in y. |
x2 | end Point of Conic in x. |
y2 | end Point of Conic in y. |
w | weight of added Conic. |
Example
See Also
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.
conicTo appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed.
If w is finite and not one, conicTo then appends kConic Verb to Verb Array; and Points p1, p2 to Point Array; and w to Weights.
If w is one, conicTo appends kQuad Verb to Verb Array, and Points p1, p2 to Point Array.
If w is not finite, conicTo appends kLine Verb twice to Verb Array, and Points p1, p2 to Point Array.
Parameters
p1 | control Point of added Conic. |
p2 | end Point of added Conic. |
w | weight of added Conic. |
Example
See Also
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.
rConicTo first appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed. If w is finite and not one, rConicTo then appends kConic Verb to Verb Array, and w is recorded as Conic Weight; otherwise, if w is one, rConicTo appends kQuad Verb to Verb Array; or if w is not finite, rConicTo appends kLine Verb twice to Verb Array.
In all cases rConicTo then appends Points control and end to Point Array. control is Last Point plus Vector (dx1, dy1). end is Last Point plus Vector (dx2, dy2).
rConicTo stands for relative conic to.
Parameters
dx1 | offset from Last Point x to Conic control x. |
dy1 | offset from Last Point x to Conic control y. |
dx2 | offset from Last Point x to Conic end x. |
dy2 | offset from Last Point x to Conic end y. |
w | weight of added Conic. |
Example
See Also
Cubic
Cubic describes a cubic Bezier, a third-order curve. 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.
cubicTo appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed. cubicTo then appends kCubic Verb to Verb Array; and (x1, y1), (x2, y2), (x3, y3) to Point Array.
Parameters
x1 | first control Point of Cubic in x. |
y1 | first control Point of Cubic in y. |
x2 | second control Point of Cubic in x. |
y2 | second control Point of Cubic in y. |
x3 | end Point of Cubic in x. |
y3 | end Point of Cubic in y. |
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.
cubicTo appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed. cubicTo then appends kCubic Verb to Verb Array; and Points p1, p2, p3 to Point Array.
Parameters
p1 | first control Point of Cubic. |
p2 | second control Point of Cubic. |
p3 | end Point of Cubic. |
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.
rCubicTo first appends kMove Verb to Verb Array and (0, 0) to Point Array, if needed. rCubicTo 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). rCubicTo stands for relative cubic to.
Parameters
x1 | offset from Last Point x to first Cubic control x. |
y1 | offset from Last Point x to first Cubic control y. |
x2 | offset from Last Point x to second Cubic control x. |
y2 | offset from Last Point x to second Cubic control y. |
x3 | offset from Last Point x to Cubic end x. |
y3 | offset from Last Point x to Cubic end y. |
Example
See Also
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
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
oval | bounds of ellipse containing Arc. |
startAngle | starting angle of Arc in degrees. |
sweepAngle | sweep, in degrees. Positive is clockwise; treated modulo 360. |
forceMoveTo | true to start a new contour with Arc. |
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
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
p1 | Point common to pair of tangents. |
p2 | end of second tangent. |
radius | distance from Arc to Circle center. |
Example
Example Output
move to (156,20)
line (156,20),(200,20)
See Also
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
SkPath::kSmall_ArcSize | 0 | Smaller of Arc pair. |
SkPath::kLarge_ArcSize | 1 | Larger of Arc pair. |
Example
See Also
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 Conic 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 functionatlity of SVG Arc, although SVG sweep-flag value is opposite the integer value of sweep; SVG sweep-flag 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; positve 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
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.
arcTo appends up to four Conic curves. arcTo implements the functionatlity of SVG Arc, although SVG sweep-flag value is opposite the integer value of sweep; SVG sweep-flag 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; positve values are clockwise. |
largeArc | chooses smaller or larger Arc. |
sweep | chooses clockwise or counterclockwise Arc. |
xy | end of Arc. |
Example
See Also
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 (r.fX, r.fY) rotated by xAxisRotate degrees. Arc curves from last Path Point (x0, y0) to (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 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.
arcTo appends up to four Conic curves. arcTo implements the functionatlity of SVG Arc, although SVG sweep-flag value is opposite the integer value of sweep; SVG sweep-flag 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; positve values are clockwise. |
largeArc | chooses smaller or larger Arc. |
sweep | chooses clockwise or counterclockwise Arc. |
dx | x offset end of Arc from last Path Point. |
dy | y offset end of Arc from last Path Point. |
Example
See Also
close
void close()
Append kClose Verb to Path. A closed Contour connects the first and last Point with Line, forming a continous 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
fill | one of: kWinding FillType, kEvenOdd FillType, kInverseWinding FillType, kInverseEvenOdd FillType. |
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
fill | one of: kWinding FillType, kEvenOdd FillType, kInverseWinding FillType, kInverseEvenOdd FillType. |
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)ConvertConicToQuads 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
p0 | Conic start Point. |
p1 | Conic control Point. |
p2 | Conic end Point. |
w | Conic weight. |
pts | storage for Quad array. |
pow2 | Quad count, as power of two, normally 0 to 5 (1 to 32 Quad curves). |
Return Value
Number of Quad curves written to pts.
Example
See Also
isRect
bool isRect(SkRect* rect, bool* isClosed = NULL, Direction* direction = NULL) const
Returns true if Path is eqivalent to Rect when filled. If isRect returns false: rect, isClosed, and direction are unchanged. If isRect returns 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
rect | storage for bounds of Rect; may be nullptr. |
isClosed | storage set to true if Path is closed; may be nullptr |
direction | storage set to Rect direction; may be nullptr. |
Return Value
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] = NULL) const
Returns true if Path is equivalent to nested Rect pair when filled. If isNestedFillRects returns false, rect and dirs are unchanged. If isNestedFillRects returns 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
rect | storage for Rect pair; may be nullptr. |
dirs | storage for Direction pair; may be nullptr. |
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
rect | Rect to add as a closed contour. |
dir | Direction to wind added contour. |
Example
See Also
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
rect | Rect to add as a closed contour. |
dir | Direction to wind added contour. |
start | Initial corner of Rect to add. |
Example
See Also
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
left | smaller x of Rect. |
top | smaller y of Rect. |
right | larger x of Rect. |
bottom | larger y of Rect. |
dir | Direction to wind added contour. |
Example
See Also
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
oval | bounds of ellipse added. |
dir | Direction to wind ellipse. |
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
oval | bounds of ellipse added. |
dir | Direction to wind ellipse. |
start | index of initial point of ellipse. |
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) and continues clockwise if dir is kCW Direction, counterclockwise if dir is kCCW Direction.
addCircle has no effect if radius is zero or negative.
Parameters
x | center of Circle. |
y | center of Circle. |
radius | distance from center to edge. |
dir | Direction to wind Circle. |
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
See Also
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
rect | bounds of Round Rect. |
rx | x-radius of rounded corners on the Round Rect |
ry | y-radius of rounded corners on the Round Rect |
dir | Direction to wind Round Rect. |
Example
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
rect | bounds of Round Rect. |
radii | array of 8 SkScalar values, a radius pair for each corner. |
dir | Direction to wind Round Rect. |
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 RRect.
Parameters
rrect | bounds and radii of rounded rectangle. |
dir | Direction to wind Round Rect. |
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 RRect.
Parameters
rrect | bounds and radii of rounded rectangle. |
dir | Direction to wind RRect. |
start | Index of initial point of RRect. |
Example
See Also
addRoundRect SkCanvas::drawRRect
addPoly
void addPoly(const SkPoint pts[], int count, bool close)
Add Contour created from Line Array. Given count pts, addPoly adds count - 1 Line segments. Contour added starts at pt[0], then adds a line for every additional Point in pts array. If close is true, addPoly appends kClose Verb to Path, connecting pts[count - 1] and pts[0].
If count is zero, append kMove Verb to path. addPoly has no effect if count is less than one.
Parameters
pts | Array of Line sharing end and start Point. |
count | Length of Point array. |
close | true to add Line connecting Contour end and start. |
Example
See Also
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
SkPath::kAppend_AddPathMode | Path Verbs, Points, and Weights are appended to destination unaltered. | Since Path Verb Array begins with kMove Verb if src is not empty, this starts a new Contour. |
SkPath::kExtend_AddPathMode | If destination is closed or empty, start a new Contour. If destination | is not empty, add Line from Last Point to added Path first Point. Skip added Path initial kMove Verb, then append remining Verbs, Points, and Weights. |
Example
See Also
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 Weights are added unaltered. If mode is kExtend AddPathMode, add Line before appending Verbs, Points, and Weights.
Parameters
src | Path Verbs, Points, and Weights to add. |
dx | offset added to src Point Array x coordinates. |
dy | offset added to src Point Array y coordinates. |
mode | kAppend AddPathMode or kExtend AddPathMode. |
Example
See Also
AddPathMode offset reverseAddPath
void addPath(const SkPath& src, AddPathMode mode = kAppend_AddPathMode)
If mode is kAppend AddPathMode, src Verb Array, Point Array, and Weights are added unaltered. If mode is kExtend AddPathMode, add Line before appending Verbs, Points, and Weights.
Parameters
src | Path Verbs, Points, and Weights to add. |
mode | kAppend AddPathMode or kExtend AddPathMode. |
Example
See Also
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 Weights.
If mode is kAppend AddPathMode, src Verb Array, Point Array, and Weights are added unaltered. If mode is kExtend AddPathMode, add Line before appending Verbs, Points, and Weights.
Parameters
src | Path Verbs, Points, and Weights to add. |
matrix | Transform applied to src. |
mode | kAppend AddPathMode or kExtend AddPathMode. |
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
src | Path Verbs, Points, and Weights to add. |
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
dx | offset added to Point Array x coordinates. |
dy | offset added to Point Array y coordinates. |
dst | overwritten, translated copy of Path; may be nullptr. |
Example
See Also
addPath transform
void offset(SkScalar dx, SkScalar dy)
Offset Point Array by (dx, dy). Path is replaced by offset data.
Parameters
dx | offset added to Point Array x coordinates. |
dy | offset added to Point Array y coordinates. |
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
matrix | Matrix to apply to Path. |
dst | overwritten, transformed copy of Path; may be nullptr. |
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
matrix | Matrix to apply to Path. |
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
lastPt | storage for final Point in Point Array; may be nullptr. |
Return Value
true if Point Array contains one or more Points.
Example
Example Output
last point: 35.2786, 52.9772
See Also
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
x | set x-coordinate of Last Point. |
y | set y-coordinate of Last Point. |
Example
See Also
void setLastPt(const SkPoint& p)
Set the last point on the path. If no points have been added,
Parameters
p | set value of Last Point. |
Example
See Also
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
SkPath::kLine_SegmentMask | 1 | Set if Verb Array contains kLine Verb. |
SkPath::kQuad_SegmentMask | 2 | Set if Verb Array contains kQuad Verb. Note that conicTo may add a Quad. |
SkPath::kConic_SegmentMask | 4 | Set if Verb Array contains kConic Verb. |
SkPath::kCubic_SegmentMask | 8 | Set if Verb Array contains kCubic Verb. |
Example
Example Output
Path kConic_SegmentMask is clear
Path kQuad_SegmentMask is set
See Also
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, 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
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
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, dump writes to stdout. Set forceClose to true to get edges used to fill Path. Set dumpAsHex true to get exact binary representations of floating point numbers used in Point Array and Weights.
Parameters
stream | writable Stream receiving Path text representation; may be nullptr. |
forceClose | true if missing kClose Verb is output. |
dumpAsHex | true if SkScalar values are written as hexidecimal. |
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 stdout. 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 stdout. 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 dumpHex when submittingbug reports against Skiahttp://bug.skia.org. Slight value changes in Point Array may cause the bug to disappear.
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
Write Path to buffer, returning the number of bytes written. Pass nullptr to obtain the storage size.
writeToMemory writes Fill Type, Verb Array, Point Array, Conic Weight, and additionally writes computed information like Convexity and bounds.
writeToMemory should only be used in concert with readFromMemory. The format used for Path in memory is not guaranteed.
Parameters
buffer | storage for Path; may be nullptr. |
Return Value
size of storage required for Path; always a multiple of 4.
Example
See Also
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.
readFromMemory reads Fill Type, Verb Array, Point Array, Conic Weight, and additionally reads computed information like Convexity and bounds.
readFromMemory should only be used in concert with writeToMemory. The format used for Path in memory is not guaranteed.
Parameters
buffer | storage for Path. |
length | buffer size in bytes; must be multiple of 4. |
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
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)
validate
void validate() const
Debugging check to see if Path data is consistent. Not currently maintained.
experimentalValidateRef
void experimentalValidateRef() const
Class 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.
Example
See Also
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
Example
Example Output
iter is done
iter is done
See Also
Iter
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
path | Path to iterate. |
forceClose | true if open Contours generate kClose Verb. |
Return Value
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
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
path | Path to iterate. |
forceClose | true if open Contours generate kClose Verb. |
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
pts | Storage for Point data describing returned Verb. |
doConsumeDegenerates | If true, skip degenerate Verbs. |
exact | If true, skip zero length curves. Has no effect if doConsumeDegenerates is false. |
Return Value
next Verb from Verb Array.
Example
skip degenerate if exact skips the same as skip degenerate, but shows the very small Line.
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
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
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 RawIter
Iterates through Verb Array, and associated Point Array and Conic Weight. Verb Array, Point Array, and Conic Weight are returned unaltered.
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
RawIter(const SkPath& path)
Sets RawIter to return elements of Verb Array, Point Array, and Conic Weight in path.
Parameters
path | Path to iterate. |
Return Value
setPath
void setPath(const SkPath& path)
Sets Iter to return elements of Verb Array, Point Array, and Conic Weight in path.
Parameters
path | Path to iterate. |
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
pts | Storage for Point data describing returned Verb. |
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
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
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