1 /* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 #include "PathOpsTestCommon.h" 8 #include "SkIntersections.h" 9 #include "SkOpContour.h" 10 #include "SkOpSegment.h" 11 #include "SkRandom.h" 12 #include "SkTSort.h" 13 #include "Test.h" 14 15 static bool gDisableAngleTests = true; 16 17 static float next(float f) 18 { 19 int fBits = SkFloatAs2sCompliment(f); 20 ++fBits; 21 float fNext = Sk2sComplimentAsFloat(fBits); 22 return fNext; 23 } 24 25 static float prev(float f) 26 { 27 int fBits = SkFloatAs2sCompliment(f); 28 --fBits; 29 float fNext = Sk2sComplimentAsFloat(fBits); 30 return fNext; 31 } 32 33 DEF_TEST(PathOpsAngleFindCrossEpsilon, reporter) { 34 if (gDisableAngleTests) { 35 return; 36 } 37 SkRandom ran; 38 int maxEpsilon = 0; 39 for (int index = 0; index < 10000000; ++index) { 40 SkDLine line = {{{0, 0}, {ran.nextRangeF(0.0001f, 1000), ran.nextRangeF(0.0001f, 1000)}}}; 41 for (int inner = 0; inner < 10; ++inner) { 42 float t = ran.nextRangeF(0.0001f, 1); 43 SkDPoint dPt = line.ptAtT(t); 44 SkPoint pt = dPt.asSkPoint(); 45 float xs[3] = { prev(pt.fX), pt.fX, next(pt.fX) }; 46 float ys[3] = { prev(pt.fY), pt.fY, next(pt.fY) }; 47 for (int xIdx = 0; xIdx < 3; ++xIdx) { 48 for (int yIdx = 0; yIdx < 3; ++yIdx) { 49 SkPoint test = { xs[xIdx], ys[yIdx] }; 50 float p1 = SkDoubleToScalar(line[1].fX * test.fY); 51 float p2 = SkDoubleToScalar(line[1].fY * test.fX); 52 int p1Bits = SkFloatAs2sCompliment(p1); 53 int p2Bits = SkFloatAs2sCompliment(p2); 54 int epsilon = SkTAbs(p1Bits - p2Bits); 55 if (maxEpsilon < epsilon) { 56 SkDebugf("line={{0, 0}, {%1.7g, %1.7g}} t=%1.7g pt={%1.7g, %1.7g}" 57 " epsilon=%d\n", 58 line[1].fX, line[1].fY, t, test.fX, test.fY, epsilon); 59 maxEpsilon = epsilon; 60 } 61 } 62 } 63 } 64 } 65 } 66 67 DEF_TEST(PathOpsAngleFindQuadEpsilon, reporter) { 68 if (gDisableAngleTests) { 69 return; 70 } 71 SkRandom ran; 72 int maxEpsilon = 0; 73 double maxAngle = 0; 74 for (int index = 0; index < 100000; ++index) { 75 SkDLine line = {{{0, 0}, {ran.nextRangeF(0.0001f, 1000), ran.nextRangeF(0.0001f, 1000)}}}; 76 float t = ran.nextRangeF(0.0001f, 1); 77 SkDPoint dPt = line.ptAtT(t); 78 float t2 = ran.nextRangeF(0.0001f, 1); 79 SkDPoint qPt = line.ptAtT(t2); 80 float t3 = ran.nextRangeF(0.0001f, 1); 81 SkDPoint qPt2 = line.ptAtT(t3); 82 qPt.fX += qPt2.fY; 83 qPt.fY -= qPt2.fX; 84 SkDQuad quad = {{line[0], dPt, qPt}}; 85 // binary search for maximum movement of quad[1] towards test that still has 1 intersection 86 double moveT = 0.5f; 87 double deltaT = moveT / 2; 88 SkDPoint last; 89 do { 90 last = quad[1]; 91 quad[1].fX = dPt.fX - line[1].fY * moveT; 92 quad[1].fY = dPt.fY + line[1].fX * moveT; 93 SkIntersections i; 94 i.intersect(quad, line); 95 REPORTER_ASSERT(reporter, i.used() > 0); 96 if (i.used() == 1) { 97 moveT += deltaT; 98 } else { 99 moveT -= deltaT; 100 } 101 deltaT /= 2; 102 } while (last.asSkPoint() != quad[1].asSkPoint()); 103 float p1 = SkDoubleToScalar(line[1].fX * last.fY); 104 float p2 = SkDoubleToScalar(line[1].fY * last.fX); 105 int p1Bits = SkFloatAs2sCompliment(p1); 106 int p2Bits = SkFloatAs2sCompliment(p2); 107 int epsilon = SkTAbs(p1Bits - p2Bits); 108 if (maxEpsilon < epsilon) { 109 SkDebugf("line={{0, 0}, {%1.7g, %1.7g}} t=%1.7g/%1.7g/%1.7g moveT=%1.7g" 110 " pt={%1.7g, %1.7g} epsilon=%d\n", 111 line[1].fX, line[1].fY, t, t2, t3, moveT, last.fX, last.fY, epsilon); 112 maxEpsilon = epsilon; 113 } 114 double a1 = atan2(line[1].fY, line[1].fX); 115 double a2 = atan2(last.fY, last.fX); 116 double angle = fabs(a1 - a2); 117 if (maxAngle < angle) { 118 SkDebugf("line={{0, 0}, {%1.7g, %1.7g}} t=%1.7g/%1.7g/%1.7g moveT=%1.7g" 119 " pt={%1.7g, %1.7g} angle=%1.7g\n", 120 line[1].fX, line[1].fY, t, t2, t3, moveT, last.fX, last.fY, angle); 121 maxAngle = angle; 122 } 123 } 124 } 125 126 static int find_slop(double x, double y, double rx, double ry) { 127 int slopBits = 0; 128 bool less1, less2; 129 double absX = fabs(x); 130 double absY = fabs(y); 131 double length = absX < absY ? absX / 2 + absY : absX + absY / 2; 132 int exponent; 133 (void) frexp(length, &exponent); 134 double epsilon = ldexp(FLT_EPSILON, exponent); 135 do { 136 // get the length as the larger plus half the smaller (both same signs) 137 // find the ulps of the length 138 // compute the offsets from there 139 double xSlop = epsilon * slopBits; 140 double ySlop = x * y < 0 ? -xSlop : xSlop; // OPTIMIZATION: use copysign / _copysign ? 141 double x1 = x - xSlop; 142 double y1 = y + ySlop; 143 double x_ry1 = x1 * ry; 144 double rx_y1 = rx * y1; 145 less1 = x_ry1 < rx_y1; 146 double x2 = x + xSlop; 147 double y2 = y - ySlop; 148 double x_ry2 = x2 * ry; 149 double rx_y2 = rx * y2; 150 less2 = x_ry2 < rx_y2; 151 } while (less1 == less2 && ++slopBits); 152 return slopBits; 153 } 154 155 // from http://stackoverflow.com/questions/1427422/cheap-algorithm-to-find-measure-of-angle-between-vectors 156 static double diamond_angle(double y, double x) 157 { 158 if (y >= 0) 159 return (x >= 0 ? y/(x+y) : 1-x/(-x+y)); 160 else 161 return (x < 0 ? 2-y/(-x-y) : 3+x/(x-y)); 162 } 163 164 static const double slopTests[][4] = { 165 // x y rx ry 166 {-0.058554756452593892, -0.18804585843827226, -0.018568569646021160, -0.059615294434479438}, 167 {-0.0013717412948608398, 0.0041152238845825195, -0.00045837944195925573, 0.0013753175735478074}, 168 {-2.1033774145221198, -1.4046019261273715e-008, -0.70062688352066704, -1.2706324683777995e-008}, 169 }; 170 171 DEF_TEST(PathOpsAngleFindSlop, reporter) { 172 if (gDisableAngleTests) { 173 return; 174 } 175 for (int index = 0; index < (int) SK_ARRAY_COUNT(slopTests); ++index) { 176 const double* slopTest = slopTests[index]; 177 double x = slopTest[0]; 178 double y = slopTest[1]; 179 double rx = slopTest[2]; 180 double ry = slopTest[3]; 181 SkDebugf("%s xy %d=%d\n", __FUNCTION__, index, find_slop(x, y, rx, ry)); 182 SkDebugf("%s rxy %d=%d\n", __FUNCTION__, index, find_slop(rx, ry, x, y)); 183 double angle = diamond_angle(y, x); 184 double rAngle = diamond_angle(ry, rx); 185 double diff = fabs(angle - rAngle); 186 SkDebugf("%s diamond xy=%1.9g rxy=%1.9g diff=%1.9g factor=%d\n", __FUNCTION__, 187 angle, rAngle, diff, (int) (diff / FLT_EPSILON)); 188 } 189 } 190 191 class PathOpsAngleTester { 192 public: 193 static int After(SkOpAngle& lh, SkOpAngle& rh) { 194 return lh.after(&rh); 195 } 196 197 static int ConvexHullOverlaps(SkOpAngle& lh, SkOpAngle& rh) { 198 return lh.convexHullOverlaps(&rh); 199 } 200 201 static int Orderable(SkOpAngle& lh, SkOpAngle& rh) { 202 return lh.orderable(&rh); 203 } 204 205 static int EndsIntersect(SkOpAngle& lh, SkOpAngle& rh) { 206 return lh.endsIntersect(&rh); 207 } 208 209 static void SetNext(SkOpAngle& lh, SkOpAngle& rh) { 210 lh.fNext = &rh; 211 } 212 }; 213 214 class PathOpsSegmentTester { 215 public: 216 static void DebugReset(SkOpSegment* segment) { 217 segment->debugReset(); 218 } 219 }; 220 221 struct CircleData { 222 const SkDCubic fPts; 223 const int fPtCount; 224 SkPoint fShortPts[4]; 225 }; 226 227 static CircleData circleDataSet[] = { 228 { {{{313.0155029296875, 207.90290832519531}, {320.05078125, 227.58743286132812}}}, 2, {} }, 229 { {{{313.0155029296875, 207.90290832519531}, {313.98246891063195, 219.33615203830394}, 230 {320.05078125, 227.58743286132812}}}, 3, {} }, 231 }; 232 233 static const int circleDataSetSize = (int) SK_ARRAY_COUNT(circleDataSet); 234 235 DEF_TEST(PathOpsAngleCircle, reporter) { 236 SkChunkAlloc allocator(4096); 237 SkOpContourHead contour; 238 SkOpGlobalState state(nullptr, &contour SkDEBUGPARAMS(nullptr)); 239 contour.init(&state, false, false); 240 for (int index = 0; index < circleDataSetSize; ++index) { 241 CircleData& data = circleDataSet[index]; 242 for (int idx2 = 0; idx2 < data.fPtCount; ++idx2) { 243 data.fShortPts[idx2] = data.fPts.fPts[idx2].asSkPoint(); 244 } 245 switch (data.fPtCount) { 246 case 2: 247 contour.addLine(data.fShortPts, &allocator); 248 break; 249 case 3: 250 contour.addQuad(data.fShortPts, &allocator); 251 break; 252 case 4: 253 contour.addCubic(data.fShortPts, &allocator); 254 break; 255 } 256 } 257 SkOpSegment* first = contour.first(); 258 first->debugAddAngle(0, 1, &allocator); 259 SkOpSegment* next = first->next(); 260 next->debugAddAngle(0, 1, &allocator); 261 PathOpsAngleTester::Orderable(*first->debugLastAngle(), *next->debugLastAngle()); 262 } 263 264 struct IntersectData { 265 const SkDCubic fPts; 266 const int fPtCount; 267 double fTStart; 268 double fTEnd; 269 SkPoint fShortPts[4]; 270 }; 271 272 static IntersectData intersectDataSet1[] = { 273 { {{{322.935669,231.030273}, {312.832214,220.393295}, {312.832214,203.454178}}}, 3, 274 0.865309956, 0.154740299, {} }, 275 { {{{322.12738,233.397751}, {295.718353,159.505829}}}, 2, 276 0.345028807, 0.0786326511, {} }, 277 { {{{322.935669,231.030273}, {312.832214,220.393295}, {312.832214,203.454178}}}, 3, 278 0.865309956, 1, {} }, 279 { {{{322.12738,233.397751}, {295.718353,159.505829}}}, 2, 280 0.345028807, 1, {} }, 281 }; 282 283 static IntersectData intersectDataSet2[] = { 284 { {{{364.390686,157.898193}, {375.281769,136.674606}, {396.039917,136.674606}}}, 3, 285 0.578520747, 1, {} }, 286 { {{{364.390686,157.898193}, {375.281769,136.674606}, {396.039917,136.674606}}}, 3, 287 0.578520747, 0.536512973, {} }, 288 { {{{366.608826,151.196014}, {378.803101,136.674606}, {398.164948,136.674606}}}, 3, 289 0.490456543, 1, {} }, 290 }; 291 292 static IntersectData intersectDataSet3[] = { 293 { {{{2.000000,0.000000}, {1.33333333,0.66666667}}}, 2, 1, 0, {} }, 294 { {{{1.33333333,0.66666667}, {0.000000,2.000000}}}, 2, 0, 0.25, {} }, 295 { {{{2.000000,2.000000}, {1.33333333,0.66666667}}}, 2, 1, 0, {} }, 296 }; 297 298 static IntersectData intersectDataSet4[] = { 299 { {{{1.3333333,0.6666667}, {0.000,2.000}}}, 2, 0.250000006, 0, {} }, 300 { {{{1.000,0.000}, {1.000,1.000}}}, 2, 1, 0, {} }, 301 { {{{1.000,1.000}, {0.000,0.000}}}, 2, 0, 1, {} }, 302 }; 303 304 static IntersectData intersectDataSet5[] = { 305 { {{{0.000,0.000}, {1.000,0.000}, {1.000,1.000}}}, 3, 1, 0.666666667, {} }, 306 { {{{0.000,0.000}, {2.000,1.000}, {0.000,2.000}}}, 3, 0.5, 1, {} }, 307 { {{{0.000,0.000}, {2.000,1.000}, {0.000,2.000}}}, 3, 0.5, 0, {} }, 308 }; 309 310 static IntersectData intersectDataSet6[] = { // pathops_visualizer.htm:3658 311 { {{{0.000,1.000}, {3.000,4.000}, {1.000,0.000}, {3.000,0.000}}}, 4, 0.0925339054, 0, {} }, // pathops_visualizer.htm:3616 312 { {{{0.000,1.000}, {0.000,3.000}, {1.000,0.000}, {4.000,3.000}}}, 4, 0.453872386, 0, {} }, // pathops_visualizer.htm:3616 313 { {{{0.000,1.000}, {3.000,4.000}, {1.000,0.000}, {3.000,0.000}}}, 4, 0.0925339054, 0.417096368, {} }, // pathops_visualizer.htm:3616 314 }; 315 316 static IntersectData intersectDataSet7[] = { // pathops_visualizer.htm:3748 317 { {{{2.000,1.000}, {0.000,1.000}}}, 2, 0.5, 0, {} }, // pathops_visualizer.htm:3706 318 { {{{2.000,0.000}, {0.000,2.000}}}, 2, 0.5, 1, {} }, // pathops_visualizer.htm:3706 319 { {{{0.000,1.000}, {0.000,2.000}, {2.000,0.000}, {2.000,1.000}}}, 4, 0.5, 1, {} }, // pathops_visualizer.htm:3706 320 }; // 321 322 static IntersectData intersectDataSet8[] = { // pathops_visualizer.htm:4194 323 { {{{0.000,1.000}, {2.000,3.000}, {5.000,1.000}, {4.000,3.000}}}, 4, 0.311007457, 0.285714286, {} }, // pathops_visualizer.htm:4152 324 { {{{1.000,5.000}, {3.000,4.000}, {1.000,0.000}, {3.000,2.000}}}, 4, 0.589885081, 0.999982974, {} }, // pathops_visualizer.htm:4152 325 { {{{1.000,5.000}, {3.000,4.000}, {1.000,0.000}, {3.000,2.000}}}, 4, 0.589885081, 0.576935809, {} }, // pathops_visualizer.htm:4152 326 }; // 327 328 static IntersectData intersectDataSet9[] = { // pathops_visualizer.htm:4142 329 { {{{0.000,1.000}, {2.000,3.000}, {5.000,1.000}, {4.000,3.000}}}, 4, 0.476627072, 0.311007457, {} }, // pathops_visualizer.htm:4100 330 { {{{1.000,5.000}, {3.000,4.000}, {1.000,0.000}, {3.000,2.000}}}, 4, 0.999982974, 1, {} }, // pathops_visualizer.htm:4100 331 { {{{0.000,1.000}, {2.000,3.000}, {5.000,1.000}, {4.000,3.000}}}, 4, 0.476627072, 1, {} }, // pathops_visualizer.htm:4100 332 }; // 333 334 static IntersectData intersectDataSet10[] = { // pathops_visualizer.htm:4186 335 { {{{0.000,1.000}, {1.000,6.000}, {1.000,0.000}, {1.000,0.000}}}, 4, 0.788195121, 0.726275769, {} }, // pathops_visualizer.htm:4144 336 { {{{0.000,1.000}, {0.000,1.000}, {1.000,0.000}, {6.000,1.000}}}, 4, 0.473378977, 1, {} }, // pathops_visualizer.htm:4144 337 { {{{0.000,1.000}, {1.000,6.000}, {1.000,0.000}, {1.000,0.000}}}, 4, 0.788195121, 1, {} }, // pathops_visualizer.htm:4144 338 }; // 339 340 static IntersectData intersectDataSet11[] = { // pathops_visualizer.htm:4704 341 { {{{979.305,561.000}, {1036.695,291.000}}}, 2, 0.888888874, 0.11111108, {} }, // pathops_visualizer.htm:4662 342 { {{{1006.695,291.000}, {1023.264,291.000}, {1033.840,304.431}, {1030.318,321.000}}}, 4, 1, 0, {} }, // pathops_visualizer.htm:4662 343 { {{{979.305,561.000}, {1036.695,291.000}}}, 2, 0.888888874, 1, {} }, // pathops_visualizer.htm:4662 344 }; // 345 346 static IntersectData intersectDataSet12[] = { // pathops_visualizer.htm:5481 347 { {{{67.000,912.000}, {67.000,913.000}}}, 2, 1, 0, {} }, // pathops_visualizer.htm:5439 348 { {{{67.000,913.000}, {67.000,917.389}, {67.224,921.726}, {67.662,926.000}}}, 4, 0, 1, {} }, // pathops_visualizer.htm:5439 349 { {{{194.000,1041.000}, {123.860,1041.000}, {67.000,983.692}, {67.000,913.000}}}, 4, 1, 0, {} }, // pathops_visualizer.htm:5439 350 }; // 351 352 static IntersectData intersectDataSet13[] = { // pathops_visualizer.htm:5735 353 { {{{6.000,0.000}, {0.000,4.000}}}, 2, 0.625, 0.25, {} }, // pathops_visualizer.htm:5693 354 { {{{0.000,1.000}, {0.000,6.000}, {4.000,0.000}, {6.000,1.000}}}, 4, 0.5, 0.833333333, {} }, // pathops_visualizer.htm:5693 355 { {{{0.000,1.000}, {0.000,6.000}, {4.000,0.000}, {6.000,1.000}}}, 4, 0.5, 0.379043969, {} }, // pathops_visualizer.htm:5693 356 }; // 357 358 static IntersectData intersectDataSet14[] = { // pathops_visualizer.htm:5875 359 { {{{0.000,1.000}, {4.000,6.000}, {2.000,1.000}, {2.000,0.000}}}, 4, 0.0756502183, 0.0594570973, {} }, // pathops_visualizer.htm:5833 360 { {{{1.000,2.000}, {0.000,2.000}, {1.000,0.000}, {6.000,4.000}}}, 4, 0.0756502184, 0, {} }, // pathops_visualizer.htm:5833 361 { {{{0.000,1.000}, {4.000,6.000}, {2.000,1.000}, {2.000,0.000}}}, 4, 0.0756502183, 0.531917258, {} }, // pathops_visualizer.htm:5833 362 }; // 363 364 static IntersectData intersectDataSet15[] = { // pathops_visualizer.htm:6580 365 { {{{490.435,879.407}, {405.593,909.436}}}, 2, 0.500554405, 1, {} }, // pathops_visualizer.htm:6538 366 { {{{447.967,894.438}, {448.007,894.424}, {448.014,894.422}}}, 3, 0, 1, {} }, // pathops_visualizer.htm:6538 367 { {{{490.435,879.407}, {405.593,909.436}}}, 2, 0.500554405, 0.500000273, {} }, // pathops_visualizer.htm:6538 368 }; // 369 370 static IntersectData intersectDataSet16[] = { // pathops_visualizer.htm:7419 371 { {{{1.000,4.000}, {4.000,5.000}, {3.000,2.000}, {6.000,3.000}}}, 4, 0.5, 0, {} }, // pathops_visualizer.htm:7377 372 { {{{2.000,3.000}, {3.000,6.000}, {4.000,1.000}, {5.000,4.000}}}, 4, 0.5, 0.112701665, {} }, // pathops_visualizer.htm:7377 373 { {{{5.000,4.000}, {2.000,3.000}}}, 2, 0.5, 0, {} }, // pathops_visualizer.htm:7377 374 }; // 375 376 // from skpi_gino_com_16 377 static IntersectData intersectDataSet17[] = { 378 { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}} 379 , 3, 0.74590454, 0.547660352, {} }, 380 { /*seg=8*/ {{{185, 734}, {252.93103f, 734}, {308, 789.06897f}, {308, 857}}} 381 , 4, 0.12052623, 0, {} }, 382 { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}} 383 , 3, 0.74590454, 1, {} }, 384 }; 385 386 static IntersectData intersectDataSet18[] = { 387 { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}} 388 , 3, 0.74590454, 1, {} }, 389 { /*seg=8*/ {{{185, 734}, {252.93103f, 734}, {308, 789.06897f}, {308, 857}}} 390 , 4, 0.12052623, 0.217351928, {} }, 391 { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}} 392 , 3, 0.74590454, 0.547660352, {} }, 393 }; 394 395 static IntersectData intersectDataSet19[] = { 396 { /*seg=1*/ {{{0, 1}, {3, 5}, {2, 1}, {3, 1}}} 397 , 4, 0.135148995, 0.134791946, {} }, 398 { /*seg=3*/ {{{1, 2}, {1, 2.15061641f}, {1, 2.21049166f}, {1.01366711f, 2.21379328f}}} 399 , 4, 0.956740456, 0.894913214, {} }, 400 { /*seg=1*/ {{{0, 1}, {3, 5}, {2, 1}, {3, 1}}} 401 , 4, 0.135148995, 0.551812363, {} }, 402 }; 403 404 #define I(x) intersectDataSet##x 405 406 static IntersectData* intersectDataSets[] = { 407 I(1), I(2), I(3), I(4), I(5), I(6), I(7), I(8), I(9), I(10), 408 I(11), I(12), I(13), I(14), I(15), I(16), I(17), I(18), I(19), 409 }; 410 411 #undef I 412 #define I(x) (int) SK_ARRAY_COUNT(intersectDataSet##x) 413 414 static const int intersectDataSetSizes[] = { 415 I(1), I(2), I(3), I(4), I(5), I(6), I(7), I(8), I(9), I(10), 416 I(11), I(12), I(13), I(14), I(15), I(16), I(17), I(18), I(19), 417 }; 418 419 #undef I 420 421 static const int intersectDataSetsSize = (int) SK_ARRAY_COUNT(intersectDataSetSizes); 422 423 struct FourPoints { 424 SkPoint pts[4]; 425 }; 426 427 DEF_TEST(PathOpsAngleAfter, reporter) { 428 SkChunkAlloc allocator(4096); 429 SkOpContourHead contour; 430 SkOpGlobalState state(nullptr, &contour SkDEBUGPARAMS(nullptr)); 431 contour.init(&state, false, false); 432 for (int index = intersectDataSetsSize - 1; index >= 0; --index) { 433 IntersectData* dataArray = intersectDataSets[index]; 434 const int dataSize = intersectDataSetSizes[index]; 435 for (int index2 = 0; index2 < dataSize - 2; ++index2) { 436 allocator.reset(); 437 contour.reset(); 438 for (int index3 = 0; index3 < 3; ++index3) { 439 IntersectData& data = dataArray[index2 + index3]; 440 SkPoint* temp = (SkPoint*) SkOpTAllocator<FourPoints>::Allocate(&allocator); 441 for (int idx2 = 0; idx2 < data.fPtCount; ++idx2) { 442 temp[idx2] = data.fPts.fPts[idx2].asSkPoint(); 443 } 444 switch (data.fPtCount) { 445 case 2: { 446 contour.addLine(temp, &allocator); 447 } break; 448 case 3: { 449 contour.addQuad(temp, &allocator); 450 } break; 451 case 4: { 452 contour.addCubic(temp, &allocator); 453 } break; 454 } 455 } 456 SkOpSegment* seg1 = contour.first(); 457 seg1->debugAddAngle(dataArray[index2 + 0].fTStart, dataArray[index2 + 0].fTEnd, &allocator); 458 SkOpSegment* seg2 = seg1->next(); 459 seg2->debugAddAngle(dataArray[index2 + 1].fTStart, dataArray[index2 + 1].fTEnd, &allocator); 460 SkOpSegment* seg3 = seg2->next(); 461 seg3->debugAddAngle(dataArray[index2 + 2].fTStart, dataArray[index2 + 2].fTEnd, &allocator); 462 SkOpAngle& angle1 = *seg1->debugLastAngle(); 463 SkOpAngle& angle2 = *seg2->debugLastAngle(); 464 SkOpAngle& angle3 = *seg3->debugLastAngle(); 465 PathOpsAngleTester::SetNext(angle1, angle3); 466 // These data sets are seeded when the set itself fails, so likely the dataset does not 467 // match the expected result. The tests above return 1 when first added, but 468 // return 0 after the bug is fixed. 469 SkDEBUGCODE(int result =) PathOpsAngleTester::After(angle2, angle1); 470 SkASSERT(result == 0 || result == 1); 471 } 472 } 473 } 474 475 void SkOpSegment::debugAddAngle(double startT, double endT, SkChunkAlloc* allocator) { 476 SkOpPtT* startPtT = startT == 0 ? fHead.ptT() : startT == 1 ? fTail.ptT() 477 : this->addT(startT, kNoAlias, allocator); 478 SkOpPtT* endPtT = endT == 0 ? fHead.ptT() : endT == 1 ? fTail.ptT() 479 : this->addT(endT, kNoAlias, allocator); 480 SkOpAngle* angle = SkOpTAllocator<SkOpAngle>::Allocate(allocator); 481 SkOpSpanBase* startSpan = &fHead; 482 while (startSpan->ptT() != startPtT) { 483 startSpan = startSpan->upCast()->next(); 484 } 485 SkOpSpanBase* endSpan = &fHead; 486 while (endSpan->ptT() != endPtT) { 487 endSpan = endSpan->upCast()->next(); 488 } 489 angle->set(startSpan, endSpan); 490 if (startT < endT) { 491 startSpan->upCast()->setToAngle(angle); 492 endSpan->setFromAngle(angle); 493 } else { 494 endSpan->upCast()->setToAngle(angle); 495 startSpan->setFromAngle(angle); 496 } 497 } 498