Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 1472 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 1756 of file SkPath.cpp.

1756 {
1757#ifdef SK_DEBUG
1758 fPts = nullptr;
1759 fConicWeights = nullptr;
1760 fMoveTo.fX = fMoveTo.fY = fLastPt.fX = fLastPt.fY = 0;
1761 fForceClose = fCloseLine = false;
1762#endif
1763 // need to init enough to make next() harmlessly return kDone_Verb
1764 fVerbs = nullptr;
1765 fVerbStop = nullptr;
1766 fNeedClose = false;
1767}
float fX
x-axis value
float fY
y-axis value

◆ 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 1769 of file SkPath.cpp.

1769 {
1770 this->setPath(path, forceClose);
1771}
void setPath(const SkPath &path, bool forceClose)
Definition SkPath.cpp:1773

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 1527 of file SkPath.h.

1527{ 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 1787 of file SkPath.cpp.

1787 {
1788 if (fVerbs == nullptr || fVerbs == fVerbStop) {
1789 return false;
1790 }
1791 if (fForceClose) {
1792 return true;
1793 }
1794
1795 const uint8_t* verbs = fVerbs;
1796 const uint8_t* stop = fVerbStop;
1797
1798 if (kMove_Verb == *verbs) {
1799 verbs += 1; // skip the initial moveto
1800 }
1801
1802 while (verbs < stop) {
1803 // verbs points one beyond the current verb, decrement first.
1804 unsigned v = *verbs++;
1805 if (kMove_Verb == v) {
1806 break;
1807 }
1808 if (kClose_Verb == v) {
1809 return true;
1810 }
1811 }
1812 return false;
1813}
@ kClose_Verb
Definition SkPath.h:1463
@ kMove_Verb
Definition SkPath.h:1458

◆ 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 1538 of file SkPath.h.

1538{ 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 1837 of file SkPath.cpp.

1837 {
1838 SkASSERT(ptsParam);
1839
1840 if (fVerbs == fVerbStop) {
1841 // Close the curve if requested and if there is some curve to close
1842 if (fNeedClose) {
1843 if (kLine_Verb == this->autoClose(ptsParam)) {
1844 return kLine_Verb;
1845 }
1846 fNeedClose = false;
1847 return kClose_Verb;
1848 }
1849 return kDone_Verb;
1850 }
1851
1852 unsigned verb = *fVerbs++;
1853 const SkPoint* SK_RESTRICT srcPts = fPts;
1854 SkPoint* SK_RESTRICT pts = ptsParam;
1855
1856 switch (verb) {
1857 case kMove_Verb:
1858 if (fNeedClose) {
1859 fVerbs--; // move back one verb
1860 verb = this->autoClose(pts);
1861 if (verb == kClose_Verb) {
1862 fNeedClose = false;
1863 }
1864 return (Verb)verb;
1865 }
1866 if (fVerbs == fVerbStop) { // might be a trailing moveto
1867 return kDone_Verb;
1868 }
1869 fMoveTo = *srcPts;
1870 pts[0] = *srcPts;
1871 srcPts += 1;
1872 fLastPt = fMoveTo;
1873 fNeedClose = fForceClose;
1874 break;
1875 case kLine_Verb:
1876 pts[0] = fLastPt;
1877 pts[1] = srcPts[0];
1878 fLastPt = srcPts[0];
1879 fCloseLine = false;
1880 srcPts += 1;
1881 break;
1882 case kConic_Verb:
1883 fConicWeights += 1;
1884 [[fallthrough]];
1885 case kQuad_Verb:
1886 pts[0] = fLastPt;
1887 memcpy(&pts[1], srcPts, 2 * sizeof(SkPoint));
1888 fLastPt = srcPts[1];
1889 srcPts += 2;
1890 break;
1891 case kCubic_Verb:
1892 pts[0] = fLastPt;
1893 memcpy(&pts[1], srcPts, 3 * sizeof(SkPoint));
1894 fLastPt = srcPts[2];
1895 srcPts += 3;
1896 break;
1897 case kClose_Verb:
1898 verb = this->autoClose(pts);
1899 if (verb == kLine_Verb) {
1900 fVerbs--; // move back one verb
1901 } else {
1902 fNeedClose = false;
1903 }
1904 fLastPt = fMoveTo;
1905 break;
1906 }
1907 fPts = srcPts;
1908 return (Verb)verb;
1909}
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SK_RESTRICT
Definition SkFeatures.h:42
@ kConic_Verb
Definition SkPath.h:1461
@ kDone_Verb
Definition SkPath.h:1464
@ kCubic_Verb
Definition SkPath.h:1462
@ kQuad_Verb
Definition SkPath.h:1460
@ kLine_Verb
Definition SkPath.h:1459

◆ 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 1773 of file SkPath.cpp.

1773 {
1774 fPts = path.fPathRef->points();
1775 fVerbs = path.fPathRef->verbsBegin();
1776 fVerbStop = path.fPathRef->verbsEnd();
1777 fConicWeights = path.fPathRef->conicWeights();
1778 if (fConicWeights) {
1779 fConicWeights -= 1; // begin one behind
1780 }
1781 fLastPt.fX = fLastPt.fY = 0;
1782 fMoveTo.fX = fMoveTo.fY = 0;
1783 fForceClose = SkToU8(forceClose);
1784 fNeedClose = false;
1785}
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: