Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkRegion::Spanerator Class Reference

#include <SkRegion.h>

Public Member Functions

 Spanerator (const SkRegion &region, int y, int left, int right)
 
bool next (int *left, int *right)
 

Detailed Description

Returns the line segment ends within SkRegion that intersect a horizontal line.

Definition at line 563 of file SkRegion.h.

Constructor & Destructor Documentation

◆ Spanerator()

SkRegion::Spanerator::Spanerator ( const SkRegion region,
int  y,
int  left,
int  right 
)

Sets SkRegion::Spanerator to return line segments in SkRegion on scan line.

Parameters
regionSkRegion to iterate
yhorizontal line to intersect
leftbounds of iteration
rightbounds of iteration
Returns
SkRegion iterator

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

Definition at line 1466 of file SkRegion.cpp.

1467 {
1469
1470 const SkIRect& r = rgn.getBounds();
1471
1472 fDone = true;
1473 if (!rgn.isEmpty() && y >= r.fTop && y < r.fBottom &&
1474 right > r.fLeft && left < r.fRight) {
1475 if (rgn.isRect()) {
1476 if (left < r.fLeft) {
1477 left = r.fLeft;
1478 }
1479 if (right > r.fRight) {
1480 right = r.fRight;
1481 }
1482 fLeft = left;
1483 fRight = right;
1484 fRuns = nullptr; // means we're a rect, not a rgn
1485 fDone = false;
1486 } else {
1487 const SkRegion::RunType* runs = rgn.fRunHead->findScanline(y);
1488 runs += 2; // skip Bottom and IntervalCount
1489 for (;;) {
1490 // runs[0..1] is to the right of the span, so we're done
1491 if (runs[0] >= right) {
1492 break;
1493 }
1494 // runs[0..1] is to the left of the span, so continue
1495 if (runs[1] <= left) {
1496 runs += 2;
1497 continue;
1498 }
1499 // runs[0..1] intersects the span
1500 fRuns = runs;
1501 fLeft = left;
1502 fRight = right;
1503 fDone = false;
1504 break;
1505 }
1506 }
1507 }
1508}
#define SkDEBUGCODE(...)
Definition: SkDebug.h:23
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
double y
void Validate(const Table &table)
Definition: SkRect.h:32
int32_t fBottom
larger y-axis bounds
Definition: SkRect.h:36
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:34
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:33
int32_t fRight
larger x-axis bounds
Definition: SkRect.h:35

Member Function Documentation

◆ next()

bool SkRegion::Spanerator::next ( int left,
int right 
)

Advances iterator to next span intersecting SkRegion within line segment provided in constructor. Returns true if interval was found.

Parameters
leftpointer to span start; may be nullptr
rightpointer to span end; may be nullptr
Returns
true if interval was found

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

Definition at line 1510 of file SkRegion.cpp.

1510 {
1511 if (fDone) {
1512 return false;
1513 }
1514
1515 if (fRuns == nullptr) { // we're a rect
1516 fDone = true; // ok, now we're done
1517 if (left) {
1518 *left = fLeft;
1519 }
1520 if (right) {
1521 *right = fRight;
1522 }
1523 return true; // this interval is legal
1524 }
1525
1526 const SkRegion::RunType* runs = fRuns;
1527
1528 if (runs[0] >= fRight) {
1529 fDone = true;
1530 return false;
1531 }
1532
1533 SkASSERT(runs[1] > fLeft);
1534
1535 if (left) {
1536 *left = std::max(fLeft, runs[0]);
1537 }
1538 if (right) {
1539 *right = std::min(fRight, runs[1]);
1540 }
1541 fRuns = runs + 2;
1542 return true;
1543}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48

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