SkPath.h revision 7e6c4d16010550ee148f1c79cf088c0320fed5c1
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project
48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkPath_DEFINED
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkPath_DEFINED
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkMatrix.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTDArray.h"
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1656c69773aea56c6c6bd47bc7e7970dd081205184djsollen@google.com#ifdef SK_BUILD_FOR_ANDROID
17f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com#define GEN_ID_INC              fGenerationID++
18f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com#define GEN_ID_PTR_INC(ptr)     ptr->fGenerationID++
19f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com#else
20f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com#define GEN_ID_INC
21f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com#define GEN_ID_PTR_INC(ptr)
22f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com#endif
23f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com
24739456585a0cc52b335cd1c0a9fc6b01782a7f89reed@google.comclass SkReader32;
25739456585a0cc52b335cd1c0a9fc6b01782a7f89reed@google.comclass SkWriter32;
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAutoPathBoundsUpdate;
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkString;
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkPath
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    The SkPath class encapsulates compound (multiple contour) geometric paths
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    consisting of straight line segments, quadratic curves, and cubic curves.
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
347ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkPath {
358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkPath();
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkPath(const SkPath&);
388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ~SkPath();
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkPath& operator=(const SkPath&);
41b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org
423abec1d7c38e9bd786fc6057f9608f3eeec98c86reed@android.com    friend bool operator==(const SkPath&, const SkPath&);
433abec1d7c38e9bd786fc6057f9608f3eeec98c86reed@android.com    friend bool operator!=(const SkPath& a, const SkPath& b) {
443abec1d7c38e9bd786fc6057f9608f3eeec98c86reed@android.com        return !(a == b);
453abec1d7c38e9bd786fc6057f9608f3eeec98c86reed@android.com    }
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum FillType {
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Specifies that "inside" is computed by a non-zero sum of signed
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            edge crossings
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kWinding_FillType,
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Specifies that "inside" is computed by an odd number of edge
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            crossings
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kEvenOdd_FillType,
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Same as Winding, but draws outside of the path, rather than inside
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kInverseWinding_FillType,
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Same as EvenOdd, but draws outside of the path, rather than inside
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com         */
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kInverseEvenOdd_FillType
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the path's fill type. This is used to define how "inside" is
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        computed. The default value is kWinding_FillType.
668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the path's fill type
688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    FillType getFillType() const { return (FillType)fFillType; }
708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the path's fill type. This is used to define how "inside" is
728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        computed. The default value is kWinding_FillType.
73b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org
748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param ft The new fill type for this path
758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
76f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com    void setFillType(FillType ft) {
77f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com        fFillType = SkToU8(ft);
78f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com        GEN_ID_INC;
79f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com    }
808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns true if the filltype is one of the Inverse variants */
828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool isInverseFillType() const { return (fFillType & 2) != 0; }
838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
84b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com    /**
85b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  Toggle between inverse and normal filltypes. This reverse the return
86b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  value of isInverseFillType()
87b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     */
88f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com    void toggleInverseFillType() {
89f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com        fFillType ^= 2;
90f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com        GEN_ID_INC;
91f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com     }
928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9304863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    enum Convexity {
9404863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com        kUnknown_Convexity,
9504863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com        kConvex_Convexity,
9604863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com        kConcave_Convexity
9704863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    };
9804863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com
9904863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    /**
100b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  Return the path's convexity, as stored in the path. If it is currently
101b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  unknown, and the computeIfUnknown bool is true, then this will first
102b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  call ComputeConvexity() and then return that (cached) value.
103b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     */
104b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com    Convexity getConvexity() const {
105b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com        if (kUnknown_Convexity == fConvexity) {
106b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com            fConvexity = (uint8_t)ComputeConvexity(*this);
107b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com        }
108b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com        return (Convexity)fConvexity;
109b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com    }
110b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com
111b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com    /**
112b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  Return the currently cached value for convexity, even if that is set to
113b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  kUnknown_Convexity. Note: getConvexity() will automatically call
114b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  ComputeConvexity and cache its return value if the current setting is
115b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  kUnknown.
11604863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     */
117b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com    Convexity getConvexityOrUnknown() const { return (Convexity)fConvexity; }
11804863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com
11904863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    /**
12004863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  Store a convexity setting in the path. There is no automatic check to
12104863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  see if this value actually agress with the return value from
12204863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  ComputeConvexity().
123b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *
124b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  Note: even if this is set to a "known" value, if the path is later
125b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  changed (e.g. lineTo(), addRect(), etc.) then the cached value will be
126b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  reset to kUnknown_Convexity.
12704863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     */
12804863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    void setConvexity(Convexity);
12904863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com
13004863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    /**
13104863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  Compute the convexity of the specified path. This does not look at the
13204863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  value stored in the path, but computes it directly from the path's data.
13304863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *
134b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  This never returns kUnknown_Convexity.
135b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *
13604863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  If there is more than one contour, this returns kConcave_Convexity.
137b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  If the contour is degenerate (e.g. there are fewer than 3 non-degenerate
138b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  segments), then this returns kConvex_Convexity.
13904863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  The contour is treated as if it were closed, even if there is no kClose
14004863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  verb.
1416b82d1adc6a4726e36674e468ff1157e0b75373freed@android.com     */
14204863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    static Convexity ComputeConvexity(const SkPath&);
1436b82d1adc6a4726e36674e468ff1157e0b75373freed@android.com
14404863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    /**
14504863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  DEPRECATED: use getConvexity()
14604863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  Returns true if the path is flagged as being convex. This is not a
14704863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  confirmed by any analysis, it is just the value set earlier.
14804863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     */
14904863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    bool isConvex() const {
15004863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com        return kConvex_Convexity == this->getConvexity();
15104863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    }
15204863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com
15304863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    /**
15404863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  DEPRECATED: use setConvexity()
15504863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  Set the isConvex flag to true or false. Convex paths may draw faster if
15604863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  this flag is set, though setting this to true on a path that is in fact
15704863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  not convex can give undefined results when drawn. Paths default to
15804863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  isConvex == false
1596b82d1adc6a4726e36674e468ff1157e0b75373freed@android.com     */
160f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com    void setIsConvex(bool isConvex) {
16104863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com        this->setConvexity(isConvex ? kConvex_Convexity : kConcave_Convexity);
162f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com    }
1636b82d1adc6a4726e36674e468ff1157e0b75373freed@android.com
1646aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com    /** Returns true if the path is an oval.
1656aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     *
1666aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     * @param rect      returns the bounding rect of this oval. It's a circle
1676aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     *                  if the height and width are the same.
1686aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     *
1696aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     * @return true if this path is an oval.
1706aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     *              Tracking whether a path is an oval is considered an
1716aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     *              optimization for performance and so some paths that are in
1726aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     *              fact ovals can report false.
1736aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     */
1746aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com    bool isOval(SkRect* rect) const;
1756aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com
1768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Clear any lines and curves from the path, making it empty. This frees up
1778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        internal storage associated with those segments.
1786b82d1adc6a4726e36674e468ff1157e0b75373freed@android.com        This does NOT change the fill-type setting nor isConvex
1798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void reset();
1818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Similar to reset(), in that all lines and curves are removed from the
1838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path. However, any internal storage for those lines/curves is retained,
1848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        making reuse of the path potentially faster.
1856b82d1adc6a4726e36674e468ff1157e0b75373freed@android.com        This does NOT change the fill-type setting nor isConvex
1868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void rewind();
1888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns true if the path is empty (contains no lines or curves)
1908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the path is empty (contains no lines or curves)
1928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool isEmpty() const;
1948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1954da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    /** Test a line for zero length
1964da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org
1974da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org        @return true if the line is of zero length; otherwise false.
1984da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    */
1994da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2) {
20094fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com        return p1.equalsWithinTolerance(p2);
2014da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    }
2024da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org
2034da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    /** Test a quad for zero length
2044da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org
2054da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org        @return true if the quad is of zero length; otherwise false.
2064da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    */
2074da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    static bool IsQuadDegenerate(const SkPoint& p1, const SkPoint& p2,
2084da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org                                 const SkPoint& p3) {
20994fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com        return p1.equalsWithinTolerance(p2) &&
21094fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com               p2.equalsWithinTolerance(p3);
2114da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    }
2124da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org
2134da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    /** Test a cubic curve for zero length
2144da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org
2154da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org        @return true if the cubic is of zero length; otherwise false.
2164da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    */
2174da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    static bool IsCubicDegenerate(const SkPoint& p1, const SkPoint& p2,
2184da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org                                  const SkPoint& p3, const SkPoint& p4) {
21994fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com        return p1.equalsWithinTolerance(p2) &&
22094fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com               p2.equalsWithinTolerance(p3) &&
22194fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com               p3.equalsWithinTolerance(p4);
2224da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    }
2234da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org
2247e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com    /**
2257e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com     *  Returns true if the path specifies a single line (i.e. it contains just
2267e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com     *  a moveTo and a lineTo). If so, and line[] is not null, it sets the 2
2277e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com     *  points in line[] to the end-points of the line. If the path is not a
2287e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com     *  line, returns false and ignores line[].
2297e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com     */
2307e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com    bool isLine(SkPoint line[2]) const;
2317e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com
2328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns true if the path specifies a rectangle. If so, and if rect is
2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        not null, set rect to the bounds of the path. If the path does not
2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specify a rectangle, return false and ignore rect.
2358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect If not null, returns the bounds of the path if it specifies
2378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    a rectangle
2388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the path specifies a rectangle
2398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool isRect(SkRect* rect) const;
2418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
242d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com    /** Return the number of points in the path
243d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com     */
244d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com    int countPoints() const {
245d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com        return this->getPoints(NULL, 0);
246d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com    }
247d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com
248d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com    /** Return the point at the specified index. If the index is out of range
249d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com         (i.e. is not 0 <= index < countPoints()) then the returned coordinates
250d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com         will be (0,0)
251d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com     */
252d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com    SkPoint getPoint(int index) const;
253d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com
2548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns the number of points in the path. Up to max points are copied.
2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param points If not null, receives up to max points
2578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param max The maximum number of points to copy into points
2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the actual number of points in the path
2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int getPoints(SkPoint points[], int max) const;
2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //! Swap contents of this and other. Guaranteed not to throw
2638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void swap(SkPath& other);
2648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
265d252db03d9650013b545ef9781fe993c07f8f314reed@android.com    /** Returns the bounds of the path's points. If the path contains 0 or 1
266d252db03d9650013b545ef9781fe993c07f8f314reed@android.com        points, the bounds is set to (0,0,0,0), and isEmpty() will return true.
267d252db03d9650013b545ef9781fe993c07f8f314reed@android.com        Note: this bounds may be larger than the actual shape, since curves
268d252db03d9650013b545ef9781fe993c07f8f314reed@android.com        do not extend as far as their control points.
269d252db03d9650013b545ef9781fe993c07f8f314reed@android.com    */
270d252db03d9650013b545ef9781fe993c07f8f314reed@android.com    const SkRect& getBounds() const {
271d252db03d9650013b545ef9781fe993c07f8f314reed@android.com        if (fBoundsIsDirty) {
272d252db03d9650013b545ef9781fe993c07f8f314reed@android.com            this->computeBounds();
273d252db03d9650013b545ef9781fe993c07f8f314reed@android.com        }
274d252db03d9650013b545ef9781fe993c07f8f314reed@android.com        return fBounds;
275d252db03d9650013b545ef9781fe993c07f8f314reed@android.com    }
2768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Calling this will, if the internal cache of the bounds is out of date,
278d252db03d9650013b545ef9781fe993c07f8f314reed@android.com        update it so that subsequent calls to getBounds will be instanteous.
2798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        This also means that any copies or simple transformations of the path
2808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will inherit the cached bounds.
281d252db03d9650013b545ef9781fe993c07f8f314reed@android.com     */
282d252db03d9650013b545ef9781fe993c07f8f314reed@android.com    void updateBoundsCache() const {
283d252db03d9650013b545ef9781fe993c07f8f314reed@android.com        // for now, just calling getBounds() is sufficient
284d252db03d9650013b545ef9781fe993c07f8f314reed@android.com        this->getBounds();
285d252db03d9650013b545ef9781fe993c07f8f314reed@android.com    }
2868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //  Construction methods
2888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Hint to the path to prepare for adding more points. This can allow the
2908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to more efficiently grow its storage.
2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param extraPtCount The number of extra points the path should
2938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            preallocate for.
2948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void incReserve(unsigned extraPtCount);
2968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the beginning of the next contour to the point (x,y).
2988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x    The x-coordinate of the start of a new contour
3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y    The y-coordinate of the start of a new contour
3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void moveTo(SkScalar x, SkScalar y);
3038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the beginning of the next contour to the point
3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param p    The start of a new contour
3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void moveTo(const SkPoint& p) {
3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->moveTo(p.fX, p.fY);
3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
3118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the beginning of the next contour relative to the last point on the
3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        previous contour. If there is no previous contour, this is treated the
3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        same as moveTo().
3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The amount to add to the x-coordinate of the end of the
3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    previous contour, to specify the start of a new contour
3188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy   The amount to add to the y-coordinate of the end of the
3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    previous contour, to specify the start of a new contour
3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void rMoveTo(SkScalar dx, SkScalar dy);
3228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a line from the last point to the specified point (x,y). If no
3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        moveTo() call has been made for this contour, the first point is
3258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        automatically set to (0,0).
3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x    The x-coordinate of the end of a line
3288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y    The y-coordinate of the end of a line
3298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void lineTo(SkScalar x, SkScalar y);
3318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a line from the last point to the specified point. If no moveTo()
3338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        call has been made for this contour, the first point is automatically
3348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        set to (0,0).
3358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param p    The end of a line
3378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void lineTo(const SkPoint& p) {
3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->lineTo(p.fX, p.fY);
3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
3418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Same as lineTo, but the coordinates are considered relative to the last
3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        point on this contour. If there is no previous point, then a moveTo(0,0)
3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        is inserted automatically.
3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The amount to add to the x-coordinate of the previous point
3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    on this contour, to specify a line
3488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy   The amount to add to the y-coordinate of the previous point
3498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    on this contour, to specify a line
3508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void rLineTo(SkScalar dx, SkScalar dy);
3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a quadratic bezier from the last point, approaching control point
3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (x1,y1), and ending at (x2,y2). If no moveTo() call has been made for
3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this contour, the first point is automatically set to (0,0).
3568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x1   The x-coordinate of the control point on a quadratic curve
3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y1   The y-coordinate of the control point on a quadratic curve
3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x2   The x-coordinate of the end point on a quadratic curve
3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y2   The y-coordinate of the end point on a quadratic curve
3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2);
3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a quadratic bezier from the last point, approaching control point
3658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        p1, and ending at p2. If no moveTo() call has been made for this
3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        contour, the first point is automatically set to (0,0).
3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param p1   The control point on a quadratic curve
3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param p2   The end point on a quadratic curve
3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void quadTo(const SkPoint& p1, const SkPoint& p2) {
3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->quadTo(p1.fX, p1.fY, p2.fX, p2.fY);
3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Same as quadTo, but the coordinates are considered relative to the last
3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        point on this contour. If there is no previous point, then a moveTo(0,0)
3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        is inserted automatically.
3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx1   The amount to add to the x-coordinate of the last point on
3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                this contour, to specify the control point of a quadratic curve
3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy1   The amount to add to the y-coordinate of the last point on
3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                this contour, to specify the control point of a quadratic curve
3838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx2   The amount to add to the x-coordinate of the last point on
3848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     this contour, to specify the end point of a quadratic curve
3858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy2   The amount to add to the y-coordinate of the last point on
3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     this contour, to specify the end point of a quadratic curve
3878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void rQuadTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2);
3898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a cubic bezier from the last point, approaching control points
3918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (x1,y1) and (x2,y2), and ending at (x3,y3). If no moveTo() call has been
3928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        made for this contour, the first point is automatically set to (0,0).
3938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x1   The x-coordinate of the 1st control point on a cubic curve
3958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y1   The y-coordinate of the 1st control point on a cubic curve
3968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x2   The x-coordinate of the 2nd control point on a cubic curve
3978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y2   The y-coordinate of the 2nd control point on a cubic curve
3988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x3   The x-coordinate of the end point on a cubic curve
3998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y3   The y-coordinate of the end point on a cubic curve
4008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
4028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                 SkScalar x3, SkScalar y3);
4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a cubic bezier from the last point, approaching control points p1
4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        and p2, and ending at p3. If no moveTo() call has been made for this
4068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        contour, the first point is automatically set to (0,0).
4078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param p1   The 1st control point on a cubic curve
4098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param p2   The 2nd control point on a cubic curve
4108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param p3   The end point on a cubic curve
4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void cubicTo(const SkPoint& p1, const SkPoint& p2, const SkPoint& p3) {
4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->cubicTo(p1.fX, p1.fY, p2.fX, p2.fY, p3.fX, p3.fY);
4148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
4158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Same as cubicTo, but the coordinates are considered relative to the
4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current point on this contour. If there is no previous point, then a
4188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        moveTo(0,0) is inserted automatically.
4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx1   The amount to add to the x-coordinate of the last point on
4218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                this contour, to specify the 1st control point of a cubic curve
4228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy1   The amount to add to the y-coordinate of the last point on
4238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                this contour, to specify the 1st control point of a cubic curve
4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx2   The amount to add to the x-coordinate of the last point on
4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                this contour, to specify the 2nd control point of a cubic curve
4268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy2   The amount to add to the y-coordinate of the last point on
4278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                this contour, to specify the 2nd control point of a cubic curve
4288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx3   The amount to add to the x-coordinate of the last point on
4298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     this contour, to specify the end point of a cubic curve
4308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy3   The amount to add to the y-coordinate of the last point on
4318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     this contour, to specify the end point of a cubic curve
4328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void    rCubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
4348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     SkScalar x3, SkScalar y3);
4358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Append the specified arc to the path as a new contour. If the start of
4378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the path is different from the path's current last point, then an
4388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        automatic lineTo() is added to connect the current contour to the start
4398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        of the arc. However, if the path is empty, then we call moveTo() with
4408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the first point of the arc. The sweep angle is treated mod 360.
4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval The bounding oval defining the shape and size of the arc
4438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param startAngle Starting angle (in degrees) where the arc begins
4448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sweepAngle Sweep angle (in degrees) measured clockwise. This is
4458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          treated mod 360.
4468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param forceMoveTo If true, always begin a new contour with the arc
4478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void    arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
4498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                  bool forceMoveTo);
4508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Append a line and arc to the current path. This is the same as the
4528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        PostScript call "arct".
4538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
4558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com               SkScalar radius);
4568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Append a line and arc to the current path. This is the same as the
4588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        PostScript call "arct".
4598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void arcTo(const SkPoint p1, const SkPoint p2, SkScalar radius) {
4618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->arcTo(p1.fX, p1.fY, p2.fX, p2.fY, radius);
4628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
4638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Close the current contour. If the current point is not equal to the
4658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        first point of the contour, a line segment is automatically added.
4668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void close();
4688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum Direction {
4708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** clockwise direction for adding closed contours */
4718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kCW_Direction,
4728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** counter-clockwise direction for adding closed contours */
4738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kCCW_Direction
4748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
4758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
47669a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com    /**
47769a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com     *  Tries to quickly compute the direction of the first non-degenerate
47869a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com     *  contour. If it can be computed, return true and set dir to that
47969a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com     *  direction. If it cannot be (quickly) determined, return false and ignore
48069a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com     *  the dir parameter.
48169a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com     */
48269a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com    bool cheapComputeDirection(Direction* dir) const;
48369a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com
48469a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com    /**
48569a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com     *  Returns true if the path's direction can be computed via
48669a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com     *  cheapComputDirection() and if that computed direction matches the
48769a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com     *  specified direction.
48869a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com     */
48969a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com    bool cheapIsDirection(Direction dir) const {
49069a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com        Direction computedDir;
49169a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com        return this->cheapComputeDirection(&computedDir) && computedDir == dir;
49269a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com    }
49369a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com
4948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a closed rectangle contour to the path
4958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect The rectangle to add as a closed contour to the path
4968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dir  The direction to wind the rectangle's contour
4978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void    addRect(const SkRect& rect, Direction dir = kCW_Direction);
4998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a closed rectangle contour to the path
5018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The left side of a rectangle to add as a closed contour
5038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        to the path
5048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The top of a rectangle to add as a closed contour to the
5058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        path
5068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param right    The right side of a rectangle to add as a closed contour
5078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        to the path
5088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bottom   The bottom of a rectangle to add as a closed contour to
5098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        the path
5108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dir      The direction to wind the rectangle's contour
5118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void addRect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom,
5138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                 Direction dir = kCW_Direction);
5148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a closed oval contour to the path
5168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval The bounding oval to add as a closed contour to the path
5188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dir  The direction to wind the oval's contour
5198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void addOval(const SkRect& oval, Direction dir = kCW_Direction);
5218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a closed circle contour to the path
5238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x        The x-coordinate of the center of a circle to add as a
5258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        closed contour to the path
5268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y        The y-coordinate of the center of a circle to add as a
5278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        closed contour to the path
5288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param radius   The radius of a circle to add as a closed contour to the
5298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        path
5308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dir      The direction to wind the circle's contour
5318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void addCircle(SkScalar x, SkScalar y, SkScalar radius,
5338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                   Direction dir = kCW_Direction);
5348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add the specified arc to the path as a new contour.
5368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval The bounds of oval used to define the size of the arc
5388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param startAngle Starting angle (in degrees) where the arc begins
5398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sweepAngle Sweep angle (in degrees) measured clockwise
5408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle);
5428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a closed round-rectangle contour to the path
5448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect The bounds of a round-rectangle to add as a closed contour
5458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rx   The x-radius of the rounded corners on the round-rectangle
5468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param ry   The y-radius of the rounded corners on the round-rectangle
5478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dir  The direction to wind the round-rectangle's contour
5488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void    addRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry,
5508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                         Direction dir = kCW_Direction);
5518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a closed round-rectangle contour to the path. Each corner receives
5538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        two radius values [X, Y]. The corners are ordered top-left, top-right,
5548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bottom-right, bottom-left.
5558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect The bounds of a round-rectangle to add as a closed contour
5568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param radii Array of 8 scalars, 4 [X,Y] pairs for each corner
5578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dir  The direction to wind the round-rectangle's contour
5588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
5598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void addRoundRect(const SkRect& rect, const SkScalar radii[],
5608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                      Direction dir = kCW_Direction);
5618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a copy of src to the path, offset by (dx,dy)
5638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param src  The path to add as a new contour
5648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The amount to translate the path in X as it is added
5658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The amount to translate the path in Y as it is added
5668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
56763d73749fbe36491403ea521005fd298dc70a94creed@google.com    void addPath(const SkPath& src, SkScalar dx, SkScalar dy);
5688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a copy of src to the path
5708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void addPath(const SkPath& src) {
5728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkMatrix m;
5738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        m.reset();
5748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->addPath(src, m);
5758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
5768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a copy of src to the path, transformed by matrix
5788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param src  The path to add as a new contour
5798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void addPath(const SkPath& src, const SkMatrix& matrix);
5818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
58263d73749fbe36491403ea521005fd298dc70a94creed@google.com    /**
58363d73749fbe36491403ea521005fd298dc70a94creed@google.com     *  Same as addPath(), but reverses the src input
58463d73749fbe36491403ea521005fd298dc70a94creed@google.com     */
58563d73749fbe36491403ea521005fd298dc70a94creed@google.com    void reverseAddPath(const SkPath& src);
58663d73749fbe36491403ea521005fd298dc70a94creed@google.com
5878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Offset the path by (dx,dy), returning true on success
5888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The amount in the X direction to offset the entire path
5908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy   The amount in the Y direction to offset the entire path
5918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dst  The translated path is written here
5928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void offset(SkScalar dx, SkScalar dy, SkPath* dst) const;
5948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Offset the path by (dx,dy), returning true on success
5968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The amount in the X direction to offset the entire path
5988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy   The amount in the Y direction to offset the entire path
5998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void offset(SkScalar dx, SkScalar dy) {
6018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->offset(dx, dy, this);
6028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
6038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Transform the points in this path by matrix, and write the answer into
6058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        dst.
6068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix   The matrix to apply to the path
6088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dst      The transformed path is written here
6098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void transform(const SkMatrix& matrix, SkPath* dst) const;
6118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Transform the points in this path by matrix
6138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix The matrix to apply to the path
6158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void transform(const SkMatrix& matrix) {
6178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->transform(matrix, this);
6188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
6198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the last point on the path. If no points have been added, (0,0)
621294dd7b3d7b55ba38881cd4cabb6636abda23eb9reed@google.com        is returned. If there are no points, this returns false, otherwise it
622294dd7b3d7b55ba38881cd4cabb6636abda23eb9reed@google.com        returns true.
6238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param lastPt   The last point on the path is returned here
6258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
626294dd7b3d7b55ba38881cd4cabb6636abda23eb9reed@google.com    bool getLastPt(SkPoint* lastPt) const;
6278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the last point on the path. If no points have been added,
6298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        moveTo(x,y) is automatically called.
6308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x    The new x-coordinate for the last point
6328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y    The new y-coordinate for the last point
6338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void setLastPt(SkScalar x, SkScalar y);
6358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the last point on the path. If no points have been added, moveTo(p)
6378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        is automatically called.
6388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param p    The new location for the last point
6408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void setLastPt(const SkPoint& p) {
6428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->setLastPt(p.fX, p.fY);
6438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
6448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
64510296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com    enum SegmentMask {
64610296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com        kLine_SegmentMask   = 1 << 0,
64710296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com        kQuad_SegmentMask   = 1 << 1,
64810296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com        kCubic_SegmentMask  = 1 << 2
64910296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com    };
65010296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com
65110296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com    /**
65210296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com     *  Returns a mask, where each bit corresponding to a SegmentMask is
65310296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com     *  set if the path contains 1 or more segments of that type.
65410296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com     *  Returns 0 for an empty path (no segments).
65510296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com     */
65610296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com    uint32_t getSegmentMasks() const { return fSegmentMask; }
65710296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com
6588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum Verb {
6598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kMove_Verb,     //!< iter.next returns 1 point
6608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kLine_Verb,     //!< iter.next returns 2 points
6618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kQuad_Verb,     //!< iter.next returns 3 points
6628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kCubic_Verb,    //!< iter.next returns 4 points
663b3b8dfa31326c51dab8b5ed569e19ee715582d1bbsalomon@google.com        kClose_Verb,    //!< iter.next returns 1 point (contour's moveTo pt)
6648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kDone_Verb      //!< iter.next returns 0 points
6658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
6668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Iterate through all of the segments (lines, quadratics, cubics) of
6688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        each contours in a path.
66972785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org
67072785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org        The iterator cleans up the segments along the way, removing degenerate
67172785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org        segments and adding close verbs where necessary. When the forceClose
67272785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org        argument is provided, each contour (as defined by a new starting
67372785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org        move command) will be completed with a close verb regardless of the
67472785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org        contour's contents.
6758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6767ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.org    class SK_API Iter {
6778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    public:
67872785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org        Iter();
67972785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org        Iter(const SkPath&, bool forceClose);
6808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        void setPath(const SkPath&, bool forceClose);
6828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Return the next verb in this iteration of the path. When all
6848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            segments have been visited, return kDone_Verb.
685b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org
6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            @param  pts The points representing the current verb and/or segment
6878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            @return The verb for the current segment
6888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
6898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Verb next(SkPoint pts[4]);
6908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** If next() returns kLine_Verb, then this query returns true if the
6928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            line was the result of a close() command (i.e. the end point is the
6938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            initial moveto for this contour). If next() returned a different
6948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            verb, this returns an undefined value.
695b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org
6968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            @return If the last call to next() returned kLine_Verb, return true
6978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    if it was the result of an explicit close command.
6988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
6998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bool isCloseLine() const { return SkToBool(fCloseLine); }
700b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org
7018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Returns true if the current contour is closed (has a kClose_Verb)
7028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            @return true if the current contour is closed (has a kClose_Verb)
7038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
7048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bool isClosedContour() const;
7058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    private:
7078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const SkPoint*  fPts;
7088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const uint8_t*  fVerbs;
7098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const uint8_t*  fVerbStop;
7108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkPoint         fMoveTo;
7118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkPoint         fLastPt;
7128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkBool8         fForceClose;
7138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkBool8         fNeedClose;
7148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkBool8         fCloseLine;
715b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org        SkBool8         fSegmentState;
7168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bool cons_moveTo(SkPoint pts[1]);
7188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Verb autoClose(SkPoint pts[2]);
7194da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org        void consumeDegenerateSegments();
7208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
7218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7226630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org    /** Iterate through the verbs in the path, providing the associated points.
7236630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org    */
7246630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org    class SK_API RawIter {
7256630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org    public:
7266630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        RawIter();
7276630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        RawIter(const SkPath&);
7286630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org
7296630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        void setPath(const SkPath&);
7306630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org
7316630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        /** Return the next verb in this iteration of the path. When all
7326630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org            segments have been visited, return kDone_Verb.
7336630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org
7346630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org            @param  pts The points representing the current verb and/or segment
7356630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org            @return The verb for the current segment
7366630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        */
7376630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        Verb next(SkPoint pts[4]);
7386630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org
7396630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org    private:
7406630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        const SkPoint*  fPts;
7416630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        const uint8_t*  fVerbs;
7426630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        const uint8_t*  fVerbStop;
7436630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        SkPoint         fMoveTo;
7446630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        SkPoint         fLastPt;
7456630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org    };
7466630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org
7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void dump(bool forceClose, const char title[] = NULL) const;
748e522ca5d5f249bd51a00cb68bb051f811d0a9e85reed@android.com    void dump() const;
7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
750739456585a0cc52b335cd1c0a9fc6b01782a7f89reed@google.com    void flatten(SkWriter32&) const;
751739456585a0cc52b335cd1c0a9fc6b01782a7f89reed@google.com    void unflatten(SkReader32&);
7528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
75356c69773aea56c6c6bd47bc7e7970dd081205184djsollen@google.com#ifdef SK_BUILD_FOR_ANDROID
754f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com    uint32_t getGenerationID() const;
755e63793a2c8d2871bf7d95195be7b93ff669688d7djsollen@google.com    const SkPath* getSourcePath() const;
756e63793a2c8d2871bf7d95195be7b93ff669688d7djsollen@google.com    void setSourcePath(const SkPath* path);
757f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com#endif
758f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com
7598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDEBUGCODE(void validate() const;)
7608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
7628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkTDArray<SkPoint>  fPts;
7638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkTDArray<uint8_t>  fVerbs;
764d252db03d9650013b545ef9781fe993c07f8f314reed@android.com    mutable SkRect      fBounds;
765d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com    int                 fLastMoveToIndex;
7668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    uint8_t             fFillType;
76710296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com    uint8_t             fSegmentMask;
76810296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com    mutable uint8_t     fBoundsIsDirty;
769b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com    mutable uint8_t     fConvexity;
7706aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com
7716aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com    mutable SkBool8     fIsOval;
77256c69773aea56c6c6bd47bc7e7970dd081205184djsollen@google.com#ifdef SK_BUILD_FOR_ANDROID
773f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com    uint32_t            fGenerationID;
774e63793a2c8d2871bf7d95195be7b93ff669688d7djsollen@google.com    const SkPath*       fSourcePath;
775f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com#endif
7768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
777d252db03d9650013b545ef9781fe993c07f8f314reed@android.com    // called, if dirty, by getBounds()
778d252db03d9650013b545ef9781fe993c07f8f314reed@android.com    void computeBounds() const;
779d252db03d9650013b545ef9781fe993c07f8f314reed@android.com
7808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class Iter;
7818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkPathStroker;
7838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /*  Append the first contour of path, ignoring path's initial point. If no
7848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        moveTo() call has been made for this contour, the first point is
7858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        automatically set to (0,0).
7868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void pathTo(const SkPath& path);
7888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /*  Append, in reverse order, the first contour of path, ignoring path's
7908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        last point. If no moveTo() call has been made for this contour, the
7918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        first point is automatically set to (0,0).
7928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void reversePathTo(const SkPath&);
7948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
795d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com    // called before we add points for lineTo, quadTo, cubicTo, checking to see
796d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com    // if we need to inject a leading moveTo first
797d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com    //
798d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com    //  SkPath path; path.lineTo(...);   <--- need a leading moveTo(0, 0)
799d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com    // SkPath path; ... path.close(); path.lineTo(...) <-- need a moveTo(previous moveTo)
800d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com    //
801d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com    inline void injectMoveToIfNeeded();
802d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com
8036aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com    inline bool hasOnlyMoveTos() const;
8046aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com
8058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkAutoPathBoundsUpdate;
8066aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com    friend class SkAutoDisableOvalCheck;
8078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
8088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
810