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

Public Member Functions

bool init (const SkRect &bounds, int vertexCount)
 
void add (TriangulationVertex *v)
 
void remove (TriangulationVertex *v)
 
bool checkTriangle (const SkPoint &p0, const SkPoint &p1, const SkPoint &p2, uint16_t ignoreIndex0, uint16_t ignoreIndex1) const
 

Detailed Description

Definition at line 1523 of file SkPolyUtils.cpp.

Member Function Documentation

◆ add()

void ReflexHash::add ( TriangulationVertex v)
inline

Definition at line 1555 of file SkPolyUtils.cpp.

1555 {
1556 int index = hash(v);
1557 fGrid[index].addToTail(v);
1558 ++fNumVerts;
1559 }

◆ checkTriangle()

bool ReflexHash::checkTriangle ( const SkPoint p0,
const SkPoint p1,
const SkPoint p2,
uint16_t  ignoreIndex0,
uint16_t  ignoreIndex1 
) const
inline

Definition at line 1567 of file SkPolyUtils.cpp.

1568 {
1569 if (!fNumVerts) {
1570 return false;
1571 }
1572
1573 SkRect triBounds;
1574 compute_triangle_bounds(p0, p1, p2, &triBounds);
1575 int h0 = (triBounds.fLeft - fBounds.fLeft)*fGridConversion.fX;
1576 int h1 = (triBounds.fRight - fBounds.fLeft)*fGridConversion.fX;
1577 int v0 = (triBounds.fTop - fBounds.fTop)*fGridConversion.fY;
1578 int v1 = (triBounds.fBottom - fBounds.fTop)*fGridConversion.fY;
1579
1580 for (int v = v0; v <= v1; ++v) {
1581 for (int h = h0; h <= h1; ++h) {
1582 int i = v * fHCount + h;
1583 for (SkTInternalLList<TriangulationVertex>::Iter reflexIter = fGrid[i].begin();
1584 reflexIter != fGrid[i].end(); ++reflexIter) {
1585 TriangulationVertex* reflexVertex = *reflexIter;
1586 if (reflexVertex->fIndex != ignoreIndex0 &&
1587 reflexVertex->fIndex != ignoreIndex1 &&
1588 point_in_triangle(p0, p1, p2, reflexVertex->fPosition)) {
1589 return true;
1590 }
1591 }
1592
1593 }
1594 }
1595
1596 return false;
1597 }
static void compute_triangle_bounds(const SkPoint &p0, const SkPoint &p1, const SkPoint &p2, SkRect *bounds)
static bool point_in_triangle(const SkPoint &p0, const SkPoint &p1, const SkPoint &p2, const SkPoint &p)
T * end()
Definition: SkTDArray.h:152
static const char * begin(const StringSlice &s)
Definition: editor.cpp:252
SkScalar h
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
SkScalar fBottom
larger y-axis bounds
Definition: extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15

◆ init()

bool ReflexHash::init ( const SkRect bounds,
int  vertexCount 
)
inline

Definition at line 1525 of file SkPolyUtils.cpp.

1525 {
1526 fBounds = bounds;
1527 fNumVerts = 0;
1528 SkScalar width = bounds.width();
1529 SkScalar height = bounds.height();
1530 if (!SkIsFinite(width, height)) {
1531 return false;
1532 }
1533
1534 // We want vertexCount grid cells, roughly distributed to match the bounds ratio
1535 SkScalar hCount = SkScalarSqrt(sk_ieee_float_divide(vertexCount*width, height));
1536 if (!SkIsFinite(hCount)) {
1537 return false;
1538 }
1539 fHCount = std::max(std::min(SkScalarRoundToInt(hCount), vertexCount), 1);
1540 fVCount = vertexCount/fHCount;
1541 fGridConversion.set(sk_ieee_float_divide(fHCount - 0.001f, width),
1542 sk_ieee_float_divide(fVCount - 0.001f, height));
1543 if (!fGridConversion.isFinite()) {
1544 return false;
1545 }
1546
1547 fGrid.resize(fHCount*fVCount);
1548 for (int i = 0; i < fGrid.size(); ++i) {
1549 fGrid[i].reset();
1550 }
1551
1552 return true;
1553 }
static bool SkIsFinite(T x, Pack... values)
static constexpr float sk_ieee_float_divide(float numer, float denom)
#define SkScalarRoundToInt(x)
Definition: SkScalar.h:37
#define SkScalarSqrt(x)
Definition: SkScalar.h:42
int size() const
Definition: SkTDArray.h:138
void reset()
Definition: SkTDArray.h:171
void resize(int count)
Definition: SkTDArray.h:183
float SkScalar
Definition: extension.cpp:12
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
Optional< SkRect > bounds
Definition: SkRecords.h:189
int32_t height
int32_t width
bool isFinite() const
Definition: SkPoint_impl.h:412
void set(float x, float y)
Definition: SkPoint_impl.h:200

◆ remove()

void ReflexHash::remove ( TriangulationVertex v)
inline

Definition at line 1561 of file SkPolyUtils.cpp.

1561 {
1562 int index = hash(v);
1563 fGrid[index].remove(v);
1564 --fNumVerts;
1565 }
void remove(int index, int count=1)
Definition: SkTDArray.h:210

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