| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 #include "SkOpSegment.h" | 7 #include "SkOpSegment.h" |
| 8 #include "SkTArray.h" | 8 #include "SkTArray.h" |
| 9 #include "Test.h" | 9 #include "Test.h" |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 /* 8 */ {{0,3}, {0,1}, {2,0}, {1,0}}, | 21 /* 8 */ {{0,3}, {0,1}, {2,0}, {1,0}}, |
| 22 /* 9 */ {{189,7}, {189,5.3431458473205566f}, {190.3431396484375f,4}, {192,4}}
, | 22 /* 9 */ {{189,7}, {189,5.3431458473205566f}, {190.3431396484375f,4}, {192,4}}
, |
| 23 /* 10 */ {{0,1}, {1,3}, {1,0}, {6,4}}, | 23 /* 10 */ {{0,1}, {1,3}, {1,0}, {6,4}}, |
| 24 /* 11 */ {{0,1}, {2,3}, {2,1}, {4,3}}, | 24 /* 11 */ {{0,1}, {2,3}, {2,1}, {4,3}}, |
| 25 /* 12 */ {{1,2}, {3,4}, {1,0}, {3,2}}, | 25 /* 12 */ {{1,2}, {3,4}, {1,0}, {3,2}}, |
| 26 /* 13 */ {{0,1}, {4,6}, {4,3}, {5,4}}, | 26 /* 13 */ {{0,1}, {4,6}, {4,3}, {5,4}}, |
| 27 /* 14 */ {{806,11419}, {806.962890625f,11419}, {807.76690673828125f,11418.3193
359375f}, {807.957275390625f,11417.4130859375f}}, | 27 /* 14 */ {{806,11419}, {806.962890625f,11419}, {807.76690673828125f,11418.3193
359375f}, {807.957275390625f,11417.4130859375f}}, |
| 28 /* 15 */ {{808,11417}, {808,11418.1044921875f}, {807.10455322265625f,11419}, {
806,11419}}, | 28 /* 15 */ {{808,11417}, {808,11418.1044921875f}, {807.10455322265625f,11419}, {
806,11419}}, |
| 29 /* 16 */ {{132,11419}, {130.89543151855469f,11419}, {130,11418.1044921875f}, {
130,11417}}, | 29 /* 16 */ {{132,11419}, {130.89543151855469f,11419}, {130,11418.1044921875f}, {
130,11417}}, |
| 30 /* 17 */ {{130.04275512695312f,11417.4130859375f}, {130.23312377929687f,11418.
3193359375f}, {131.03707885742187f,11419}, {132,11419}}, | 30 /* 17 */ {{130.04275512695312f,11417.4130859375f}, {130.23312377929687f,11418.
3193359375f}, {131.03707885742187f,11419}, {132,11419}}, |
| 31 /* 18 */ {{1006.6951293945312f,291}, {1023.263671875f,291}, {1033.840209960937
5f,304.43145751953125f}, {1030.318359375f,321}}, |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 static const SkPoint quads[][3] = { | 34 static const SkPoint quads[][3] = { |
| 34 /* 0 */ {{12.3423996f, 228.342407f}, {10, 230.686295f}, {10, 234}}, | 35 /* 0 */ {{12.3423996f, 228.342407f}, {10, 230.686295f}, {10, 234}}, |
| 35 /* 1 */ {{304.24319458007812f,591.75677490234375f}, {306,593.51470947265625f}
, {306,596}}, | 36 /* 1 */ {{304.24319458007812f,591.75677490234375f}, {306,593.51470947265625f}
, {306,596}}, |
| 36 /* 2 */ {{0,0}, {3,1}, {0,3}}, | 37 /* 2 */ {{0,0}, {3,1}, {0,3}}, |
| 37 /* 3 */ {{0,1}, {3,1}, {0,2}}, | 38 /* 3 */ {{0,1}, {3,1}, {0,2}}, |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 static const SkPoint lines[][2] = { | 41 static const SkPoint lines[][2] = { |
| 41 /* 0 */ {{6, 2}, {2, 4}}, | 42 /* 0 */ {{6, 2}, {2, 4}}, |
| 42 /* 1 */ {{306,617}, {306,590}}, | 43 /* 1 */ {{306,617}, {306,590}}, |
| 43 /* 2 */ {{306,596}, {306,617}}, | 44 /* 2 */ {{306,596}, {306,617}}, |
| 44 /* 3 */ {{6,4}, {0,1}}, | 45 /* 3 */ {{6,4}, {0,1}}, |
| 45 /* 4 */ {{6,1}, {0,1}}, | 46 /* 4 */ {{6,1}, {0,1}}, |
| 46 /* 5 */ {{1,0}, {0,3}}, | 47 /* 5 */ {{1,0}, {0,3}}, |
| 47 /* 6 */ {{246,4}, {189,4}}, | 48 /* 6 */ {{246,4}, {189,4}}, |
| 48 /* 7 */ {{192,4}, {243,4}}, | 49 /* 7 */ {{192,4}, {243,4}}, |
| 49 /* 8 */ {{4,3}, {0,1}}, | 50 /* 8 */ {{4,3}, {0,1}}, |
| 50 /* 9 */ {{3,2}, {1,2}}, | 51 /* 9 */ {{3,2}, {1,2}}, |
| 51 /* 10 */ {{6,4}, {3,4}}, | 52 /* 10 */ {{6,4}, {3,4}}, |
| 53 /* 11 */ {{979.30487060546875f,561}, {1036.695068359375f,291}}, |
| 52 }; | 54 }; |
| 53 | 55 |
| 54 struct SortSet { | 56 struct SortSet { |
| 55 const SkPoint* ptData; | 57 const SkPoint* ptData; |
| 56 int ptCount; | 58 int ptCount; |
| 57 double tStart; | 59 double tStart; |
| 58 double tEnd; | 60 double tEnd; |
| 59 SkPoint endPt; | 61 SkPoint endPt; |
| 60 }; | 62 }; |
| 61 | 63 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 {cubics[15], 4, 0.188518131, 0, {0, 0}}, | 187 {cubics[15], 4, 0.188518131, 0, {0, 0}}, |
| 186 {cubics[14], 4, 0.93081374, 0, {0, 0}}, | 188 {cubics[14], 4, 0.93081374, 0, {0, 0}}, |
| 187 }; | 189 }; |
| 188 | 190 |
| 189 static const SortSet set16[] = { | 191 static const SortSet set16[] = { |
| 190 {cubics[17], 4, 0.0682619216, 0, {130.042755f,11417.4131f}}, | 192 {cubics[17], 4, 0.0682619216, 0, {130.042755f,11417.4131f}}, |
| 191 {cubics[16], 4, 0.812302088, 1, {130,11417}}, | 193 {cubics[16], 4, 0.812302088, 1, {130,11417}}, |
| 192 {cubics[17], 4, 0.0682619216, 1, {132,11419}}, | 194 {cubics[17], 4, 0.0682619216, 1, {132,11419}}, |
| 193 }; | 195 }; |
| 194 | 196 |
| 197 static const SortSet set17[] = { |
| 198 {lines[11], 2, 0.888889581, 1, {0, 0}}, |
| 199 {cubics[18], 4, 0.999996241, 0, {0, 0}}, |
| 200 {lines[11], 2, 0.888889581, 0, {0, 0}}, |
| 201 {cubics[18], 4, 0.999996241, 1, {0, 0}}, |
| 202 }; |
| 203 |
| 195 struct SortSetTests { | 204 struct SortSetTests { |
| 196 const char* name; | 205 const char* name; |
| 197 const SortSet* set; | 206 const SortSet* set; |
| 198 size_t count; | 207 size_t count; |
| 199 SkPoint startPt; | 208 SkPoint startPt; |
| 200 }; | 209 }; |
| 201 | 210 |
| 202 #define TEST_ENTRY(name) #name, name, SK_ARRAY_COUNT(name) | 211 #define TEST_ENTRY(name) #name, name, SK_ARRAY_COUNT(name) |
| 203 | 212 |
| 204 static const SortSetTests tests[] = { | 213 static const SortSetTests tests[] = { |
| 214 { TEST_ENTRY(set17), {0, 0}}, |
| 205 { TEST_ENTRY(set16), {130.090179f,11417.5957f} }, | 215 { TEST_ENTRY(set16), {130.090179f,11417.5957f} }, |
| 206 // { TEST_ENTRY(set15), {0, 0}}, | 216 // { TEST_ENTRY(set15), {0, 0}}, |
| 207 { TEST_ENTRY(set14), {0, 0}}, | 217 { TEST_ENTRY(set14), {0, 0}}, |
| 208 { TEST_ENTRY(set13), {0, 0}}, | 218 { TEST_ENTRY(set13), {0, 0}}, |
| 209 { TEST_ENTRY(set12), {0, 0}}, | 219 { TEST_ENTRY(set12), {0, 0}}, |
| 210 { TEST_ENTRY(set11), {0, 0}}, | 220 { TEST_ENTRY(set11), {0, 0}}, |
| 211 { TEST_ENTRY(set10), {0, 0}}, | 221 { TEST_ENTRY(set10), {0, 0}}, |
| 212 { TEST_ENTRY(set9), {0, 0}}, | 222 { TEST_ENTRY(set9), {0, 0}}, |
| 213 { TEST_ENTRY(set6a), {3.55555558f,2.77777767f} }, | 223 { TEST_ENTRY(set6a), {3.55555558f,2.77777767f} }, |
| 214 { TEST_ENTRY(set8a), {1.5f,1} }, | 224 { TEST_ENTRY(set8a), {1.5f,1} }, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 } | 297 } |
| 288 if (seg->t(tIndex) == set[idx].tEnd) { | 298 if (seg->t(tIndex) == set[idx].tEnd) { |
| 289 ts[1] = tIndex; | 299 ts[1] = tIndex; |
| 290 } | 300 } |
| 291 if (seg->t(tIndex) >= 1) { | 301 if (seg->t(tIndex) >= 1) { |
| 292 break; | 302 break; |
| 293 } | 303 } |
| 294 } while (++tIndex); | 304 } while (++tIndex); |
| 295 } | 305 } |
| 296 | 306 |
| 307 static void testOne(skiatest::Reporter* reporter, const SortSetTests& test) { |
| 308 SkTDArray<SkOpAngle> angles; |
| 309 bool unsortable = false; |
| 310 bool unorderable = false; |
| 311 SkTArray<SkOpSegment> segs; |
| 312 for (size_t idx = 0; idx < test.count; ++idx) { |
| 313 int ts[2]; |
| 314 const SortSet* set = test.set; |
| 315 SkOpSegment& seg = segs.push_back(); |
| 316 setup(set, idx, &seg, ts, test.startPt); |
| 317 SkOpAngle* angle = angles.append(); |
| 318 angle->set(&seg, ts[0], ts[1]); |
| 319 #if DEBUG_ANGLE |
| 320 angle->setID(idx); |
| 321 #endif |
| 322 if (angle->unsortable()) { |
| 323 #if DEBUG_ANGLE |
| 324 SkDebugf("%s test[%s]: angle[%d] unsortable\n", __FUNCTION__, test.
name, idx); |
| 325 #endif |
| 326 unsortable = true; |
| 327 } |
| 328 if (angle->unorderable()) { |
| 329 #if DEBUG_ANGLE |
| 330 SkDebugf("%s test[%s]: angle[%d] unorderable\n", __FUNCTION__, test
.name, idx); |
| 331 #endif |
| 332 unorderable = true; |
| 333 } |
| 334 reporter->bumpTestCount(); |
| 335 } |
| 336 if (unsortable || unorderable) { |
| 337 return; |
| 338 } |
| 339 #if DEBUG_ANGLE |
| 340 SkDebugf("%s test[%s]\n", __FUNCTION__, test.name); |
| 341 #endif |
| 342 for (size_t idxL = 0; idxL < test.count; ++idxL) { |
| 343 const SkOpAngle& first = angles[idxL]; |
| 344 for (size_t idxG = 0; idxG < test.count; ++idxG) { |
| 345 if (idxL == idxG) { |
| 346 continue; |
| 347 } |
| 348 const SkOpAngle& second = angles[idxG]; |
| 349 bool compare = first < second; |
| 350 if (idxL < idxG) { |
| 351 if (!compare) { |
| 352 SkDebugf("%s test[%s]: first[%d] > second[%d]\n", __FUNCTIO
N__, |
| 353 test.name, idxL, idxG); |
| 354 compare = first < second; |
| 355 } |
| 356 REPORTER_ASSERT(reporter, compare); |
| 357 } else { |
| 358 SkASSERT(idxL > idxG); |
| 359 if (compare) { |
| 360 SkDebugf("%s test[%s]: first[%d] < second[%d]\n", __FUNCTIO
N__, |
| 361 test.name, idxL, idxG); |
| 362 compare = first < second; |
| 363 } |
| 364 REPORTER_ASSERT(reporter, !compare); |
| 365 } |
| 366 compare = second < first; |
| 367 if (idxL < idxG) { |
| 368 if (compare) { |
| 369 SkDebugf("%s test[%s]: second[%d] < first[%d]\n", __FUNCTIO
N__, |
| 370 test.name, idxL, idxG); |
| 371 compare = second < first; |
| 372 } |
| 373 REPORTER_ASSERT(reporter, !compare); |
| 374 } else { |
| 375 SkASSERT(idxL > idxG); |
| 376 if (!compare) { |
| 377 SkDebugf("%s test[%s]: second[%d] > first[%d]\n", __FUNCTIO
N__, |
| 378 test.name, idxL, idxG); |
| 379 compare = second < first; |
| 380 } |
| 381 REPORTER_ASSERT(reporter, compare); |
| 382 } |
| 383 } |
| 384 } |
| 385 } |
| 386 |
| 297 static void PathOpsAngleTest(skiatest::Reporter* reporter) { | 387 static void PathOpsAngleTest(skiatest::Reporter* reporter) { |
| 298 for (size_t index = 0; index < SK_ARRAY_COUNT(tests); ++index) { | 388 for (size_t index = 0; index < SK_ARRAY_COUNT(tests); ++index) { |
| 299 const SortSetTests& test = tests[index]; | 389 const SortSetTests& test = tests[index]; |
| 300 SkTDArray<SkOpAngle> angles; | 390 testOne(reporter, test); |
| 301 bool unsortable = false; | |
| 302 bool unorderable = false; | |
| 303 SkTArray<SkOpSegment> segs; | |
| 304 for (size_t idx = 0; idx < test.count; ++idx) { | |
| 305 int ts[2]; | |
| 306 const SortSet* set = test.set; | |
| 307 SkOpSegment& seg = segs.push_back(); | |
| 308 setup(set, idx, &seg, ts, test.startPt); | |
| 309 SkOpAngle* angle = angles.append(); | |
| 310 angle->set(&seg, ts[0], ts[1]); | |
| 311 #if DEBUG_ANGLE | |
| 312 angle->setID(idx); | |
| 313 #endif | |
| 314 if (angle->unsortable()) { | |
| 315 #if DEBUG_ANGLE | |
| 316 SkDebugf("%s test[%s]: angle[%d] unsortable\n", __FUNCTION__, t
est.name, idx); | |
| 317 #endif | |
| 318 unsortable = true; | |
| 319 } | |
| 320 if (angle->unorderable()) { | |
| 321 #if DEBUG_ANGLE | |
| 322 SkDebugf("%s test[%s]: angle[%d] unorderable\n", __FUNCTION__,
test.name, idx); | |
| 323 #endif | |
| 324 unorderable = true; | |
| 325 } | |
| 326 reporter->bumpTestCount(); | |
| 327 } | |
| 328 if (unsortable || unorderable) { | |
| 329 continue; | |
| 330 } | |
| 331 #if DEBUG_ANGLE | |
| 332 SkDebugf("%s test[%s]\n", __FUNCTION__, test.name); | |
| 333 #endif | |
| 334 for (size_t idxL = 0; idxL < test.count; ++idxL) { | |
| 335 const SkOpAngle& first = angles[idxL]; | |
| 336 for (size_t idxG = 0; idxG < test.count; ++idxG) { | |
| 337 if (idxL == idxG) { | |
| 338 continue; | |
| 339 } | |
| 340 const SkOpAngle& second = angles[idxG]; | |
| 341 bool compare = first < second; | |
| 342 if (idxL < idxG) { | |
| 343 if (!compare) { | |
| 344 SkDebugf("%s test[%s]: first[%d] > second[%d]\n", __FUN
CTION__, | |
| 345 test.name, idxL, idxG); | |
| 346 compare = first < second; | |
| 347 } | |
| 348 REPORTER_ASSERT(reporter, compare); | |
| 349 } else { | |
| 350 SkASSERT(idxL > idxG); | |
| 351 if (compare) { | |
| 352 SkDebugf("%s test[%s]: first[%d] < second[%d]\n", __FUN
CTION__, | |
| 353 test.name, idxL, idxG); | |
| 354 compare = first < second; | |
| 355 } | |
| 356 REPORTER_ASSERT(reporter, !compare); | |
| 357 } | |
| 358 compare = second < first; | |
| 359 if (idxL < idxG) { | |
| 360 if (compare) { | |
| 361 SkDebugf("%s test[%s]: second[%d] < first[%d]\n", __FUN
CTION__, | |
| 362 test.name, idxL, idxG); | |
| 363 compare = second < first; | |
| 364 } | |
| 365 REPORTER_ASSERT(reporter, !compare); | |
| 366 } else { | |
| 367 SkASSERT(idxL > idxG); | |
| 368 if (!compare) { | |
| 369 SkDebugf("%s test[%s]: second[%d] > first[%d]\n", __FUN
CTION__, | |
| 370 test.name, idxL, idxG); | |
| 371 compare = second < first; | |
| 372 } | |
| 373 REPORTER_ASSERT(reporter, compare); | |
| 374 } | |
| 375 } | |
| 376 } | |
| 377 reporter->bumpTestCount(); | 391 reporter->bumpTestCount(); |
| 378 } | 392 } |
| 379 } | 393 } |
| 380 | 394 |
| 395 static void PathOpsAngleTestOne(skiatest::Reporter* reporter) { |
| 396 size_t index = 0; |
| 397 const SortSetTests& test = tests[index]; |
| 398 testOne(reporter, test); |
| 399 } |
| 400 |
| 381 #if 0 | 401 #if 0 |
| 382 static int find_slop(double x, double y, double rx, double ry) { | 402 static int find_slop(double x, double y, double rx, double ry) { |
| 383 int slopBits = 0; | 403 int slopBits = 0; |
| 384 bool less1, less2; | 404 bool less1, less2; |
| 385 double absX = fabs(x); | 405 double absX = fabs(x); |
| 386 double absY = fabs(y); | 406 double absY = fabs(y); |
| 387 double length = absX < absY ? absX / 2 + absY : absX + absY / 2; | 407 double length = absX < absY ? absX / 2 + absY : absX + absY / 2; |
| 388 int exponent; | 408 int exponent; |
| 389 (void) frexp(length, &exponent); | 409 (void) frexp(length, &exponent); |
| 390 double epsilon = ldexp(FLT_EPSILON, exponent); | 410 double epsilon = ldexp(FLT_EPSILON, exponent); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 SkDebugf("%s diamond xy=%1.9g rxy=%1.9g diff=%1.9g factor=%d\n", __FUNCT
ION__, | 459 SkDebugf("%s diamond xy=%1.9g rxy=%1.9g diff=%1.9g factor=%d\n", __FUNCT
ION__, |
| 440 angle, rAngle, diff, (int) (diff / FLT_EPSILON)); | 460 angle, rAngle, diff, (int) (diff / FLT_EPSILON)); |
| 441 | 461 |
| 442 } | 462 } |
| 443 } | 463 } |
| 444 #endif | 464 #endif |
| 445 | 465 |
| 446 #include "TestClassDef.h" | 466 #include "TestClassDef.h" |
| 447 DEFINE_TESTCLASS_SHORT(PathOpsAngleTest) | 467 DEFINE_TESTCLASS_SHORT(PathOpsAngleTest) |
| 448 | 468 |
| 469 DEFINE_TESTCLASS_SHORT(PathOpsAngleTestOne) |
| 470 |
| 449 // DEFINE_TESTCLASS_SHORT(PathOpsAngleFindSlop) | 471 // DEFINE_TESTCLASS_SHORT(PathOpsAngleFindSlop) |
| OLD | NEW |