Flutter Engine
The Flutter Engine
Public Member Functions | Friends | List of all members
SkTSpan Class Reference

#include <SkPathOpsTSect.h>

Public Member Functions

 SkTSpan (const SkTCurve &curve, SkArenaAlloc &heap)
 
void addBounded (SkTSpan *, SkArenaAlloc *)
 
double closestBoundedT (const SkDPoint &pt) const
 
bool contains (double t) const
 
void debugInit (const SkTCurve &curve, SkArenaAlloc &heap)
 
const SkTSectdebugOpp () const
 
void dump () const
 
void dumpAll () const
 
void dumpBounded (int id) const
 
void dumpBounds () const
 
void dumpCoin () const
 
double endT () const
 
SkTSpanfindOppSpan (const SkTSpan *opp) const
 
SkTSpanfindOppT (double t) const
 
 SkDEBUGCODE (SkOpGlobalState *globalState() const { return fDebugGlobalState;}) bool hasOppT(double t) const
 
int hullsIntersect (SkTSpan *span, bool *start, bool *oppStart)
 
void init (const SkTCurve &)
 
bool initBounds (const SkTCurve &)
 
bool isBounded () const
 
bool linearsIntersect (SkTSpan *span)
 
double linearT (const SkDPoint &) const
 
void markCoincident ()
 
const SkTSpannext () const
 
bool onlyEndPointsInCommon (const SkTSpan *opp, bool *start, bool *oppStart, bool *ptsInCommon)
 
const SkTCurvepart () const
 
int pointCount () const
 
const SkDPointpointFirst () const
 
const SkDPointpointLast () const
 
bool removeAllBounded ()
 
bool removeBounded (const SkTSpan *opp)
 
void reset ()
 
void resetBounds (const SkTCurve &curve)
 
bool split (SkTSpan *work, SkArenaAlloc *heap)
 
bool splitAt (SkTSpan *work, double t, SkArenaAlloc *heap)
 
double startT () const
 

Friends

class SkTSect
 

Detailed Description

Definition at line 93 of file SkPathOpsTSect.h.

Constructor & Destructor Documentation

◆ SkTSpan()

SkTSpan::SkTSpan ( const SkTCurve curve,
SkArenaAlloc heap 
)
inline

Definition at line 95 of file SkPathOpsTSect.h.

95 {
96 fPart = curve.make(heap);
97 }
virtual SkTCurve * make(SkArenaAlloc &) const =0

Member Function Documentation

◆ addBounded()

void SkTSpan::addBounded ( SkTSpan span,
SkArenaAlloc heap 
)

Definition at line 63 of file SkPathOpsTSect.cpp.

63 {
64 SkTSpanBounded* bounded = heap->make<SkTSpanBounded>();
65 bounded->fBounded = span;
66 bounded->fNext = fBounded;
67 fBounded = bounded;
68}
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
Definition: SkArenaAlloc.h:120
SkTSpan * fBounded
SkTSpanBounded * fNext

◆ closestBoundedT()

double SkTSpan::closestBoundedT ( const SkDPoint pt) const

Definition at line 118 of file SkPathOpsTSect.cpp.

118 {
119 double result = -1;
120 double closest = DBL_MAX;
121 const SkTSpanBounded* testBounded = fBounded;
122 while (testBounded) {
123 const SkTSpan* test = testBounded->fBounded;
124 double startDist = test->pointFirst().distanceSquared(pt);
125 if (closest > startDist) {
126 closest = startDist;
127 result = test->fStartT;
128 }
129 double endDist = test->pointLast().distanceSquared(pt);
130 if (closest > endDist) {
131 closest = endDist;
132 result = test->fEndT;
133 }
134 testBounded = testBounded->fNext;
135 }
136 SkASSERT(between(0, result, 1));
137 return result;
138}
#define SkASSERT(cond)
Definition: SkAssert.h:116
bool between(double a, double b, double c)
GAsyncResult * result

◆ contains()

bool SkTSpan::contains ( double  t) const

Definition at line 153 of file SkPathOpsTSect.cpp.

153 {
154 const SkTSpan* work = this;
155 do {
156 if (between(work->fStartT, t, work->fEndT)) {
157 return true;
158 }
159 } while ((work = work->fNext));
160 return false;
161}

◆ debugInit()

void SkTSpan::debugInit ( const SkTCurve curve,
SkArenaAlloc heap 
)
inline

Definition at line 103 of file SkPathOpsTSect.h.

103 {
104#ifdef SK_DEBUG
105 SkTCurve* fake = curve.make(heap);
106 fake->debugInit();
107 init(*fake);
108 initBounds(*fake);
109 fCoinStart.init();
110 fCoinEnd.init();
111#endif
112 }
virtual void debugInit()=0
bool initBounds(const SkTCurve &)
void init(const SkTCurve &)

◆ debugOpp()

const SkTSect * SkTSpan::debugOpp ( ) const

Definition at line 163 of file SkPathOpsTSect.cpp.

163 {
164 return SkDEBUGRELEASE(fDebugSect->debugOpp(), nullptr);
165}
#define SkDEBUGRELEASE(a, b)

◆ dump()

void SkTSpan::dump ( ) const

Definition at line 1340 of file PathOpsDebug.cpp.

1340 {
1341 dumpID();
1342 SkDebugf("=(%g,%g) [", fStartT, fEndT);
1343 const SkTSpanBounded* testBounded = fBounded;
1344 while (testBounded) {
1345 const SkTSpan* span = testBounded->fBounded;
1346 const SkTSpanBounded* next = testBounded->fNext;
1347 span->dumpID();
1348 if (next) {
1349 SkDebugf(",");
1350 }
1351 testBounded = next;
1352 }
1353 SkDebugf("]");
1354}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
const SkTSpan * next() const

◆ dumpAll()

void SkTSpan::dumpAll ( ) const

Definition at line 1323 of file PathOpsDebug.cpp.

1323 {
1324 dumpID();
1325 SkDebugf("=(%g,%g) [", fStartT, fEndT);
1326 const SkTSpanBounded* testBounded = fBounded;
1327 while (testBounded) {
1328 const SkTSpan* span = testBounded->fBounded;
1329 const SkTSpanBounded* next = testBounded->fNext;
1330 span->dumpID();
1331 SkDebugf("=(%g,%g)", span->fStartT, span->fEndT);
1332 if (next) {
1333 SkDebugf(" ");
1334 }
1335 testBounded = next;
1336 }
1337 SkDebugf("]\n");
1338}

◆ dumpBounded()

void SkTSpan::dumpBounded ( int  id) const

Definition at line 1356 of file PathOpsDebug.cpp.

1356 {
1357 SkDEBUGCODE(fDebugSect->dumpBounded(id));
1358}
SkDEBUGCODE(SkOpGlobalState *globalState() const { return fDebugGlobalState;}) bool hasOppT(double t) const

◆ dumpBounds()

void SkTSpan::dumpBounds ( ) const

Definition at line 1360 of file PathOpsDebug.cpp.

1360 {
1361 dumpID();
1362 SkDebugf(" bounds=(%1.9g,%1.9g, %1.9g,%1.9g) boundsMax=%1.9g%s\n",
1363 fBounds.fLeft, fBounds.fTop, fBounds.fRight, fBounds.fBottom, fBoundsMax,
1364 fCollapsed ? " collapsed" : "");
1365}
double fTop
Definition: SkPathOpsRect.h:22
double fRight
Definition: SkPathOpsRect.h:22
double fBottom
Definition: SkPathOpsRect.h:22
double fLeft
Definition: SkPathOpsRect.h:22

◆ dumpCoin()

void SkTSpan::dumpCoin ( ) const

Definition at line 1367 of file PathOpsDebug.cpp.

1367 {
1368 dumpID();
1369 SkDebugf(" coinStart ");
1370 fCoinStart.dump();
1371 SkDebugf(" coinEnd ");
1372 fCoinEnd.dump();
1373}
void dump() const

◆ endT()

double SkTSpan::endT ( ) const
inline

Definition at line 131 of file SkPathOpsTSect.h.

131 {
132 return fEndT;
133 }

◆ findOppSpan()

SkTSpan * SkTSpan::findOppSpan ( const SkTSpan opp) const

Definition at line 167 of file SkPathOpsTSect.cpp.

168 {
169 SkTSpanBounded* bounded = fBounded;
170 while (bounded) {
171 SkTSpan* test = bounded->fBounded;
172 if (opp == test) {
173 return test;
174 }
175 bounded = bounded->fNext;
176 }
177 return nullptr;
178}
#define test(name)

◆ findOppT()

SkTSpan * SkTSpan::findOppT ( double  t) const
inline

Definition at line 137 of file SkPathOpsTSect.h.

137 {
138 SkTSpan* result = oppT(t);
140 return result;
141 }
#define SkOPASSERT(cond)

◆ hullsIntersect()

int SkTSpan::hullsIntersect ( SkTSpan span,
bool *  start,
bool *  oppStart 
)

Definition at line 212 of file SkPathOpsTSect.cpp.

213 {
214 if (!fBounds.intersects(opp->fBounds)) {
215 return 0;
216 }
217 int hullSect = this->hullCheck(opp, start, oppStart);
218 if (hullSect >= 0) {
219 return hullSect;
220 }
221 hullSect = opp->hullCheck(this, oppStart, start);
222 if (hullSect >= 0) {
223 return hullSect;
224 }
225 return -1;
226}
bool intersects(const SkDRect &r) const
Definition: SkPathOpsRect.h:38

◆ init()

void SkTSpan::init ( const SkTCurve c)

Definition at line 228 of file SkPathOpsTSect.cpp.

228 {
229 fPrev = fNext = nullptr;
230 fStartT = 0;
231 fEndT = 1;
232 fBounded = nullptr;
233 resetBounds(c);
234}
void resetBounds(const SkTCurve &curve)

◆ initBounds()

bool SkTSpan::initBounds ( const SkTCurve c)

Definition at line 236 of file SkPathOpsTSect.cpp.

236 {
237 if (SkDoubleIsNaN(fStartT) || SkDoubleIsNaN(fEndT)) {
238 return false;
239 }
240 c.subDivide(fStartT, fEndT, fPart);
241 fBounds.setBounds(*fPart);
242 fCoinStart.init();
243 fCoinEnd.init();
244 fBoundsMax = std::max(fBounds.width(), fBounds.height());
245 fCollapsed = fPart->collapsed();
246 fHasPerp = false;
247 fDeleted = false;
248#if DEBUG_T_SECT
249 if (fCollapsed) {
250 SkDebugf("%s", ""); // for convenient breakpoints
251 }
252#endif
253 return fBounds.valid();
254}
static bool SkDoubleIsNaN(double x)
virtual bool collapsed() const =0
virtual void subDivide(double t1, double t2, SkTCurve *curve) const =0
static float max(float r, float g, float b)
Definition: hsl.cpp:49
double height() const
Definition: SkPathOpsRect.h:55
double width() const
Definition: SkPathOpsRect.h:51
bool valid() const
Definition: SkPathOpsRect.h:79
void setBounds(const SkDConic &curve)
Definition: SkPathOpsRect.h:59

◆ isBounded()

bool SkTSpan::isBounded ( ) const
inline

Definition at line 153 of file SkPathOpsTSect.h.

153 {
154 return fBounded != nullptr;
155 }

◆ linearsIntersect()

bool SkTSpan::linearsIntersect ( SkTSpan span)

Definition at line 256 of file SkPathOpsTSect.cpp.

256 {
257 int result = this->linearIntersects(*span->fPart);
258 if (result <= 1) {
259 return SkToBool(result);
260 }
261 SkASSERT(span->fIsLinear);
262 result = span->linearIntersects(*fPart);
263// SkASSERT(result <= 1);
264 return SkToBool(result);
265}
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35

◆ linearT()

double SkTSpan::linearT ( const SkDPoint pt) const

Definition at line 267 of file SkPathOpsTSect.cpp.

267 {
268 SkDVector len = this->pointLast() - this->pointFirst();
269 return fabs(len.fX) > fabs(len.fY)
270 ? (pt.fX - this->pointFirst().fX) / len.fX
271 : (pt.fY - this->pointFirst().fY) / len.fY;
272}
const SkDPoint & pointLast() const
const SkDPoint & pointFirst() const

◆ markCoincident()

void SkTSpan::markCoincident ( )
inline

Definition at line 160 of file SkPathOpsTSect.h.

160 {
161 fCoinStart.markCoincident();
162 fCoinEnd.markCoincident();
163 }
void markCoincident()

◆ next()

const SkTSpan * SkTSpan::next ( ) const
inline

Definition at line 165 of file SkPathOpsTSect.h.

165 {
166 return fNext;
167 }

◆ onlyEndPointsInCommon()

bool SkTSpan::onlyEndPointsInCommon ( const SkTSpan opp,
bool *  start,
bool *  oppStart,
bool *  ptsInCommon 
)

Definition at line 320 of file SkPathOpsTSect.cpp.

321 {
322 if (opp->pointFirst() == this->pointFirst()) {
323 *start = *oppStart = true;
324 } else if (opp->pointFirst() == this->pointLast()) {
325 *start = false;
326 *oppStart = true;
327 } else if (opp->pointLast() == this->pointFirst()) {
328 *start = true;
329 *oppStart = false;
330 } else if (opp->pointLast() == this->pointLast()) {
331 *start = *oppStart = false;
332 } else {
333 *ptsInCommon = false;
334 return false;
335 }
336 *ptsInCommon = true;
337 const SkDPoint* otherPts[4], * oppOtherPts[4];
338// const SkDPoint* otherPts[this->pointCount() - 1], * oppOtherPts[opp->pointCount() - 1];
339 int baseIndex = *start ? 0 : fPart->pointLast();
340 fPart->otherPts(baseIndex, otherPts);
341 opp->fPart->otherPts(*oppStart ? 0 : opp->fPart->pointLast(), oppOtherPts);
342 const SkDPoint& base = (*fPart)[baseIndex];
343 for (int o1 = 0; o1 < this->pointCount() - 1; ++o1) {
344 SkDVector v1 = *otherPts[o1] - base;
345 for (int o2 = 0; o2 < opp->pointCount() - 1; ++o2) {
346 SkDVector v2 = *oppOtherPts[o2] - base;
347 if (v2.dot(v1) >= 0) {
348 return false;
349 }
350 }
351 }
352 return true;
353}
Vec2Value v2
virtual void otherPts(int oddMan, const SkDPoint *endPt[2]) const =0
virtual int pointLast() const =0
int pointCount() const

◆ part()

const SkTCurve & SkTSpan::part ( ) const
inline

Definition at line 172 of file SkPathOpsTSect.h.

172 {
173 return *fPart;
174 }

◆ pointCount()

int SkTSpan::pointCount ( ) const
inline

Definition at line 176 of file SkPathOpsTSect.h.

176 {
177 return fPart->pointCount();
178 }
virtual int pointCount() const =0

◆ pointFirst()

const SkDPoint & SkTSpan::pointFirst ( ) const
inline

Definition at line 180 of file SkPathOpsTSect.h.

180 {
181 return (*fPart)[0];
182 }

◆ pointLast()

const SkDPoint & SkTSpan::pointLast ( ) const
inline

Definition at line 184 of file SkPathOpsTSect.h.

184 {
185 return (*fPart)[fPart->pointLast()];
186 }

◆ removeAllBounded()

bool SkTSpan::removeAllBounded ( )

Definition at line 367 of file SkPathOpsTSect.cpp.

367 {
368 bool deleteSpan = false;
369 SkTSpanBounded* bounded = fBounded;
370 while (bounded) {
371 SkTSpan* opp = bounded->fBounded;
372 deleteSpan |= opp->removeBounded(this);
373 bounded = bounded->fNext;
374 }
375 return deleteSpan;
376}
bool removeBounded(const SkTSpan *opp)

◆ removeBounded()

bool SkTSpan::removeBounded ( const SkTSpan opp)

Definition at line 378 of file SkPathOpsTSect.cpp.

378 {
379 if (fHasPerp) {
380 bool foundStart = false;
381 bool foundEnd = false;
382 SkTSpanBounded* bounded = fBounded;
383 while (bounded) {
384 SkTSpan* test = bounded->fBounded;
385 if (opp != test) {
386 foundStart |= between(test->fStartT, fCoinStart.perpT(), test->fEndT);
387 foundEnd |= between(test->fStartT, fCoinEnd.perpT(), test->fEndT);
388 }
389 bounded = bounded->fNext;
390 }
391 if (!foundStart || !foundEnd) {
392 fHasPerp = false;
393 fCoinStart.init();
394 fCoinEnd.init();
395 }
396 }
397 SkTSpanBounded* bounded = fBounded;
398 SkTSpanBounded* prev = nullptr;
399 while (bounded) {
400 SkTSpanBounded* boundedNext = bounded->fNext;
401 if (opp == bounded->fBounded) {
402 if (prev) {
403 prev->fNext = boundedNext;
404 return false;
405 } else {
406 fBounded = boundedNext;
407 return fBounded == nullptr;
408 }
409 }
410 prev = bounded;
411 bounded = boundedNext;
412 }
413 SkOPASSERT(0);
414 return false;
415}
static float prev(float f)
double perpT() const

◆ reset()

void SkTSpan::reset ( )
inline

Definition at line 191 of file SkPathOpsTSect.h.

191 {
192 fBounded = nullptr;
193 }

◆ resetBounds()

void SkTSpan::resetBounds ( const SkTCurve curve)
inline

Definition at line 195 of file SkPathOpsTSect.h.

195 {
196 fIsLinear = fIsLine = false;
197 initBounds(curve);
198 }

◆ SkDEBUGCODE()

SkTSpan::SkDEBUGCODE ( SkOpGlobalState *globalState() const { return fDebugGlobalState;}  ) const
inline

Definition at line 143 of file SkPathOpsTSect.h.

143 { return fDebugGlobalState; })
144
145 bool hasOppT(double t) const {
146 return SkToBool(oppT(t));
147 }

◆ split()

bool SkTSpan::split ( SkTSpan work,
SkArenaAlloc heap 
)
inline

Definition at line 200 of file SkPathOpsTSect.h.

200 {
201 return splitAt(work, (work->fStartT + work->fEndT) * 0.5, heap);
202 }
bool splitAt(SkTSpan *work, double t, SkArenaAlloc *heap)

◆ splitAt()

bool SkTSpan::splitAt ( SkTSpan work,
double  t,
SkArenaAlloc heap 
)

Definition at line 417 of file SkPathOpsTSect.cpp.

417 {
418 fStartT = t;
419 fEndT = work->fEndT;
420 if (fStartT == fEndT) {
421 fCollapsed = true;
422 return false;
423 }
424 work->fEndT = t;
425 if (work->fStartT == work->fEndT) {
426 work->fCollapsed = true;
427 return false;
428 }
429 fPrev = work;
430 fNext = work->fNext;
431 fIsLinear = work->fIsLinear;
432 fIsLine = work->fIsLine;
433
434 work->fNext = this;
435 if (fNext) {
436 fNext->fPrev = this;
437 }
438 this->validate();
439 SkTSpanBounded* bounded = work->fBounded;
440 fBounded = nullptr;
441 while (bounded) {
442 this->addBounded(bounded->fBounded, heap);
443 bounded = bounded->fNext;
444 }
445 bounded = fBounded;
446 while (bounded) {
447 bounded->fBounded->addBounded(this, heap);
448 bounded = bounded->fNext;
449 }
450 return true;
451}
void addBounded(SkTSpan *, SkArenaAlloc *)

◆ startT()

double SkTSpan::startT ( ) const
inline

Definition at line 206 of file SkPathOpsTSect.h.

206 {
207 return fStartT;
208 }

Friends And Related Function Documentation

◆ SkTSect

friend class SkTSect
friend

Definition at line 246 of file SkPathOpsTSect.h.


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