Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
skgpu::tess::MiddleOutPolygonTriangulator Class Reference

#include <MiddleOutPolygonTriangulator.h>

Classes

class  PoppedTriangleStack
 

Public Member Functions

 MiddleOutPolygonTriangulator (int maxPushVertexCalls, SkPoint startPoint={0, 0})
 
PoppedTriangleStack pushVertex (SkPoint pt)
 
PoppedTriangleStack closeAndMove (SkPoint newStartPoint)
 
PoppedTriangleStack close ()
 

Detailed Description

Definition at line 52 of file MiddleOutPolygonTriangulator.h.

Constructor & Destructor Documentation

◆ MiddleOutPolygonTriangulator()

skgpu::tess::MiddleOutPolygonTriangulator::MiddleOutPolygonTriangulator ( int  maxPushVertexCalls,
SkPoint  startPoint = {0,0} 
)
inline

Definition at line 127 of file MiddleOutPolygonTriangulator.h.

127 {0,0}) {
128 SkASSERT(maxPushVertexCalls >= 0);
129 // Determine the deepest our stack can ever go.
130 int maxStackDepth = SkNextLog2(maxPushVertexCalls) + 1;
131 if (maxStackDepth > kStackPreallocCount) {
132 fVertexStack.reset(maxStackDepth);
133 }
134 SkDEBUGCODE(fStackAllocCount = maxStackDepth;)
135 // The stack will always contain a starting point. This is an implicit moveTo(0, 0)
136 // initially, but will be overridden if moveTo() gets called before adding geometry.
137 fVertexStack[0] = {startPoint, 0};
138 fTop = fVertexStack;
139 }
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
static int SkNextLog2(uint32_t value)
Definition SkMathPriv.h:238
T * reset(size_t count)

Member Function Documentation

◆ close()

PoppedTriangleStack skgpu::tess::MiddleOutPolygonTriangulator::close ( )
inline

Definition at line 187 of file MiddleOutPolygonTriangulator.h.

187 {
188 return this->closeAndMove(fVertexStack[0].fPoint);
189 }
PoppedTriangleStack closeAndMove(SkPoint newStartPoint)

◆ closeAndMove()

PoppedTriangleStack skgpu::tess::MiddleOutPolygonTriangulator::closeAndMove ( SkPoint  newStartPoint)
inline

Definition at line 170 of file MiddleOutPolygonTriangulator.h.

170 {
171 // Add an implicit line back to the starting point.
172 SkPoint startPt = fVertexStack[0].fPoint;
173
174 // Triangulate the rest of the polygon. Since we simply have to finish now, we can't be
175 // picky anymore about getting a pure middle-out topology.
176 StackVertex* endVertex = std::min(fTop, fVertexStack + 1);
177
178 // Once every remaining triangle is popped, reset the vertex stack with newStartPoint.
179 StackVertex* newTopVertex = fVertexStack;
180 StackVertex newTopValue = {newStartPoint, 0};
181
182 return PoppedTriangleStack(this, startPt, endVertex, newTopVertex, newTopValue);
183 }

◆ pushVertex()

PoppedTriangleStack skgpu::tess::MiddleOutPolygonTriangulator::pushVertex ( SkPoint  pt)
inline

Definition at line 143 of file MiddleOutPolygonTriangulator.h.

143 {
144 // Our topology wants triangles that have the same vertexIdxDelta on both sides:
145 // e.g., a run of 9 points should be triangulated as:
146 //
147 // [0, 1, 2], [2, 3, 4], [4, 5, 6], [6, 7, 8] // vertexIdxDelta == 1
148 // [0, 2, 4], [4, 6, 8] // vertexIdxDelta == 2
149 // [0, 4, 8] // vertexIdxDelta == 4
150 //
151 // Find as many new triangles as we can pop off the stack that have equal-delta sides. (This
152 // is a stack-based implementation of the recursive example method from the class comment.)
153 StackVertex* endVertex = fTop;
154 int vertexIdxDelta = 1;
155 while (endVertex->fVertexIdxDelta == vertexIdxDelta) {
156 --endVertex;
157 vertexIdxDelta *= 2;
158 }
159
160 // Once the above triangles are popped, push 'pt' to the top of the stack.
161 StackVertex* newTopVertex = endVertex + 1;
162 StackVertex newTopValue = {pt, vertexIdxDelta};
163 SkASSERT(newTopVertex < fVertexStack + fStackAllocCount); // Is fStackAllocCount enough?
164
165 return PoppedTriangleStack(this, pt, endVertex, newTopVertex, newTopValue);
166 }

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