Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkPath::Iter Class Reference

#include <SkPath.h>

Public Member Functions

 Iter ()
 
 Iter (const SkPath &path, bool forceClose)
 
void setPath (const SkPath &path, bool forceClose)
 
Verb next (SkPoint pts[4])
 
SkScalar conicWeight () const
 
bool isCloseLine () const
 
bool isClosedContour () const
 

Detailed Description

Iterates through verb array, and associated SkPoint array and conic weight. Provides options to treat open contours as closed, and to ignore degenerate data.

Definition at line 1480 of file SkPath.h.

Constructor & Destructor Documentation

◆ Iter() [1/2]

SkPath::Iter::Iter ( )

Initializes SkPath::Iter with an empty SkPath. next() on SkPath::Iter returns kDone_Verb. Call setPath to initialize SkPath::Iter at a later time.

Returns
SkPath::Iter of empty SkPath

example: https://fiddle.skia.org/c/@Path_Iter_Iter

Definition at line 1820 of file SkPath.cpp.

1820 {
1821#ifdef SK_DEBUG
1822 fPts = nullptr;
1823 fConicWeights = nullptr;
1824 fMoveTo.fX = fMoveTo.fY = fLastPt.fX = fLastPt.fY = 0;
1825 fForceClose = fCloseLine = false;
1826#endif
1827 // need to init enough to make next() harmlessly return kDone_Verb
1828 fVerbs = nullptr;
1829 fVerbStop = nullptr;
1830 fNeedClose = false;
1831}
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165

◆ Iter() [2/2]

SkPath::Iter::Iter ( const SkPath path,
bool  forceClose 
)

Sets SkPath::Iter to return elements of verb array, SkPoint array, and conic weight in path. If forceClose is true, SkPath::Iter will add kLine_Verb and kClose_Verb after each open contour. path is not altered.

Parameters
pathSkPath to iterate
forceClosetrue if open contours generate kClose_Verb
Returns
SkPath::Iter of path

example: https://fiddle.skia.org/c/@Path_Iter_const_SkPath

Definition at line 1833 of file SkPath.cpp.

1833 {
1834 this->setPath(path, forceClose);
1835}
void setPath(const SkPath &path, bool forceClose)
Definition: SkPath.cpp:1837

Member Function Documentation

◆ conicWeight()

SkScalar SkPath::Iter::conicWeight ( ) const
inline

Returns conic weight if next() returned kConic_Verb.

If next() has not been called, or next() did not return kConic_Verb, result is undefined.

Returns
conic weight for conic SkPoint returned by next()

Definition at line 1535 of file SkPath.h.

1535{ return *fConicWeights; }

◆ isClosedContour()

bool SkPath::Iter::isClosedContour ( ) const

Returns true if subsequent calls to next() return kClose_Verb before returning kMove_Verb. if true, contour SkPath::Iter is processing may end with kClose_Verb, or SkPath::Iter may have been initialized with force close set to true.

Returns
true if contour is closed

example: https://fiddle.skia.org/c/@Path_Iter_isClosedContour

Definition at line 1851 of file SkPath.cpp.

1851 {
1852 if (fVerbs == nullptr || fVerbs == fVerbStop) {
1853 return false;
1854 }
1855 if (fForceClose) {
1856 return true;
1857 }
1858
1859 const uint8_t* verbs = fVerbs;
1860 const uint8_t* stop = fVerbStop;
1861
1862 if (kMove_Verb == *verbs) {
1863 verbs += 1; // skip the initial moveto
1864 }
1865
1866 while (verbs < stop) {
1867 // verbs points one beyond the current verb, decrement first.
1868 unsigned v = *verbs++;
1869 if (kMove_Verb == v) {
1870 break;
1871 }
1872 if (kClose_Verb == v) {
1873 return true;
1874 }
1875 }
1876 return false;
1877}
@ kClose_Verb
Definition: SkPath.h:1471
@ kMove_Verb
Definition: SkPath.h:1466

◆ isCloseLine()

bool SkPath::Iter::isCloseLine ( ) const
inline

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.

Returns
true if last kLine_Verb was generated by kClose_Verb

Definition at line 1546 of file SkPath.h.

1546{ return SkToBool(fCloseLine); }
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35

◆ next()

SkPath::Verb SkPath::Iter::next ( SkPoint  pts[4])

Returns next SkPath::Verb in verb array, and advances SkPath::Iter. When verb array is exhausted, returns kDone_Verb.

Zero to four SkPoint are stored in pts, depending on the returned SkPath::Verb.

Parameters
ptsstorage for SkPoint data describing returned SkPath::Verb
Returns
next SkPath::Verb from verb array

example: https://fiddle.skia.org/c/@Path_RawIter_next

Definition at line 1901 of file SkPath.cpp.

1901 {
1902 SkASSERT(ptsParam);
1903
1904 if (fVerbs == fVerbStop) {
1905 // Close the curve if requested and if there is some curve to close
1906 if (fNeedClose) {
1907 if (kLine_Verb == this->autoClose(ptsParam)) {
1908 return kLine_Verb;
1909 }
1910 fNeedClose = false;
1911 return kClose_Verb;
1912 }
1913 return kDone_Verb;
1914 }
1915
1916 unsigned verb = *fVerbs++;
1917 const SkPoint* SK_RESTRICT srcPts = fPts;
1918 SkPoint* SK_RESTRICT pts = ptsParam;
1919
1920 switch (verb) {
1921 case kMove_Verb:
1922 if (fNeedClose) {
1923 fVerbs--; // move back one verb
1924 verb = this->autoClose(pts);
1925 if (verb == kClose_Verb) {
1926 fNeedClose = false;
1927 }
1928 return (Verb)verb;
1929 }
1930 if (fVerbs == fVerbStop) { // might be a trailing moveto
1931 return kDone_Verb;
1932 }
1933 fMoveTo = *srcPts;
1934 pts[0] = *srcPts;
1935 srcPts += 1;
1936 fLastPt = fMoveTo;
1937 fNeedClose = fForceClose;
1938 break;
1939 case kLine_Verb:
1940 pts[0] = fLastPt;
1941 pts[1] = srcPts[0];
1942 fLastPt = srcPts[0];
1943 fCloseLine = false;
1944 srcPts += 1;
1945 break;
1946 case kConic_Verb:
1947 fConicWeights += 1;
1948 [[fallthrough]];
1949 case kQuad_Verb:
1950 pts[0] = fLastPt;
1951 memcpy(&pts[1], srcPts, 2 * sizeof(SkPoint));
1952 fLastPt = srcPts[1];
1953 srcPts += 2;
1954 break;
1955 case kCubic_Verb:
1956 pts[0] = fLastPt;
1957 memcpy(&pts[1], srcPts, 3 * sizeof(SkPoint));
1958 fLastPt = srcPts[2];
1959 srcPts += 3;
1960 break;
1961 case kClose_Verb:
1962 verb = this->autoClose(pts);
1963 if (verb == kLine_Verb) {
1964 fVerbs--; // move back one verb
1965 } else {
1966 fNeedClose = false;
1967 }
1968 fLastPt = fMoveTo;
1969 break;
1970 }
1971 fPts = srcPts;
1972 return (Verb)verb;
1973}
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SK_RESTRICT
Definition: SkFeatures.h:42
@ kConic_Verb
Definition: SkPath.h:1469
@ kDone_Verb
Definition: SkPath.h:1472
@ kCubic_Verb
Definition: SkPath.h:1470
@ kQuad_Verb
Definition: SkPath.h:1468
@ kLine_Verb
Definition: SkPath.h:1467

◆ setPath()

void SkPath::Iter::setPath ( const SkPath path,
bool  forceClose 
)

Sets SkPath::Iter to return elements of verb array, SkPoint array, and conic weight in path. If forceClose is true, SkPath::Iter will add kLine_Verb and kClose_Verb after each open contour. path is not altered.

Parameters
pathSkPath to iterate
forceClosetrue if open contours generate kClose_Verb

example: https://fiddle.skia.org/c/@Path_Iter_setPath

Definition at line 1837 of file SkPath.cpp.

1837 {
1838 fPts = path.fPathRef->points();
1839 fVerbs = path.fPathRef->verbsBegin();
1840 fVerbStop = path.fPathRef->verbsEnd();
1841 fConicWeights = path.fPathRef->conicWeights();
1842 if (fConicWeights) {
1843 fConicWeights -= 1; // begin one behind
1844 }
1845 fLastPt.fX = fLastPt.fY = 0;
1846 fMoveTo.fX = fMoveTo.fY = 0;
1847 fForceClose = SkToU8(forceClose);
1848 fNeedClose = false;
1849}
constexpr uint8_t SkToU8(S x)
Definition: SkTo.h:22
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

The documentation for this class was generated from the following files: