MCPcopy Create free account
hub / github.com/MyGUI/mygui / edgeColoringInkTrap

Function edgeColoringInkTrap

MyGUIEngine/src/msdfgen/core/edge-coloring.cpp:151–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149};
150
151void edgeColoringInkTrap(Shape &shape, double angleThreshold, unsigned long long seed) {
152 typedef EdgeColoringInkTrapCorner Corner;
153 double crossThreshold = sin(angleThreshold);
154 EdgeColor color = initColor(seed);
155 std::vector<Corner> corners;
156 for (std::vector<Contour>::iterator contour = shape.contours.begin(); contour != shape.contours.end(); ++contour) {
157 if (contour->edges.empty())
158 continue;
159 double splineLength = 0;
160 { // Identify corners
161 corners.clear();
162 Vector2 prevDirection = contour->edges.back()->direction(1);
163 int index = 0;
164 for (std::vector<EdgeHolder>::const_iterator edge = contour->edges.begin(); edge != contour->edges.end(); ++edge, ++index) {
165 if (isCorner(prevDirection.normalize(), (*edge)->direction(0).normalize(), crossThreshold)) {
166 Corner corner = { index, splineLength };
167 corners.push_back(corner);
168 splineLength = 0;
169 }
170 splineLength += estimateEdgeLength(*edge);
171 prevDirection = (*edge)->direction(1);
172 }
173 }
174
175 // Smooth contour
176 if (corners.empty()) {
177 switchColor(color, seed);
178 for (std::vector<EdgeHolder>::iterator edge = contour->edges.begin(); edge != contour->edges.end(); ++edge)
179 (*edge)->color = color;
180 }
181 // "Teardrop" case
182 else if (corners.size() == 1) {
183 EdgeColor colors[3];
184 switchColor(color, seed);
185 colors[0] = color;
186 colors[1] = WHITE;
187 switchColor(color, seed);
188 colors[2] = color;
189 int corner = corners[0].index;
190 if (contour->edges.size() >= 3) {
191 int m = (int) contour->edges.size();
192 for (int i = 0; i < m; ++i)
193 contour->edges[(corner+i)%m]->color = colors[1+symmetricalTrichotomy(i, m)];
194 } else if (contour->edges.size() >= 1) {
195 // Less than three edge segments for three colors => edges must be split
196 EdgeSegment *parts[7] = { };
197 contour->edges[0]->splitInThirds(parts[0+3*corner], parts[1+3*corner], parts[2+3*corner]);
198 if (contour->edges.size() >= 2) {
199 contour->edges[1]->splitInThirds(parts[3-3*corner], parts[4-3*corner], parts[5-3*corner]);
200 parts[0]->color = parts[1]->color = colors[0];
201 parts[2]->color = parts[3]->color = colors[1];
202 parts[4]->color = parts[5]->color = colors[2];
203 } else {
204 parts[0]->color = colors[0];
205 parts[1]->color = colors[1];
206 parts[2]->color = colors[2];
207 }
208 contour->edges.clear();

Callers

nothing calls this directly

Calls 15

initColorFunction · 0.85
isCornerFunction · 0.85
estimateEdgeLengthFunction · 0.85
switchColorFunction · 0.85
symmetricalTrichotomyFunction · 0.85
EdgeHolderClass · 0.85
EdgeColorEnum · 0.85
directionMethod · 0.80
splitInThirdsMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected