OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "PathOpsQuadIntersectionTestData.h" | 7 #include "PathOpsQuadIntersectionTestData.h" |
8 #include "PathOpsTestCommon.h" | 8 #include "PathOpsTestCommon.h" |
9 #include "SkIntersections.h" | 9 #include "SkIntersections.h" |
10 #include "SkPathOpsRect.h" | 10 #include "SkPathOpsRect.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 if (showSkipped) { | 30 if (showSkipped) { |
31 SkDebugf("[%d] quad2 order=%d\n", static_cast<int>(index), order
2); | 31 SkDebugf("[%d] quad2 order=%d\n", static_cast<int>(index), order
2); |
32 } | 32 } |
33 } | 33 } |
34 if (order1 == 3 && order2 == 3) { | 34 if (order1 == 3 && order2 == 3) { |
35 SkIntersections intersections; | 35 SkIntersections intersections; |
36 intersections.intersect(quad1, quad2); | 36 intersections.intersect(quad1, quad2); |
37 if (intersections.used() > 0) { | 37 if (intersections.used() > 0) { |
38 for (int pt = 0; pt < intersections.used(); ++pt) { | 38 for (int pt = 0; pt < intersections.used(); ++pt) { |
39 double tt1 = intersections[0][pt]; | 39 double tt1 = intersections[0][pt]; |
40 SkDPoint xy1 = quad1.xyAtT(tt1); | 40 SkDPoint xy1 = quad1.ptAtT(tt1); |
41 double tt2 = intersections[1][pt]; | 41 double tt2 = intersections[1][pt]; |
42 SkDPoint xy2 = quad2.xyAtT(tt2); | 42 SkDPoint xy2 = quad2.ptAtT(tt2); |
43 if (!xy1.approximatelyEqual(xy2)) { | 43 if (!xy1.approximatelyEqual(xy2)) { |
44 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", | 44 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", |
45 __FUNCTION__, static_cast<int>(index), pt, tt1,
xy1.fX, xy1.fY, | 45 __FUNCTION__, static_cast<int>(index), pt, tt1,
xy1.fX, xy1.fY, |
46 tt2, xy2.fX, xy2.fY); | 46 tt2, xy2.fX, xy2.fY); |
47 REPORTER_ASSERT(reporter, 0); | 47 REPORTER_ASSERT(reporter, 0); |
48 } | 48 } |
49 } | 49 } |
50 } | 50 } |
51 } | 51 } |
52 } | 52 } |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 249 |
250 static void oneOffTest1(skiatest::Reporter* reporter, size_t outer, size_t inner
) { | 250 static void oneOffTest1(skiatest::Reporter* reporter, size_t outer, size_t inner
) { |
251 const SkDQuad& quad1 = testSet[outer]; | 251 const SkDQuad& quad1 = testSet[outer]; |
252 SkASSERT(ValidQuad(quad1)); | 252 SkASSERT(ValidQuad(quad1)); |
253 const SkDQuad& quad2 = testSet[inner]; | 253 const SkDQuad& quad2 = testSet[inner]; |
254 SkASSERT(ValidQuad(quad2)); | 254 SkASSERT(ValidQuad(quad2)); |
255 SkIntersections intersections2; | 255 SkIntersections intersections2; |
256 intersections2.intersect(quad1, quad2); | 256 intersections2.intersect(quad1, quad2); |
257 for (int pt = 0; pt < intersections2.used(); ++pt) { | 257 for (int pt = 0; pt < intersections2.used(); ++pt) { |
258 double tt1 = intersections2[0][pt]; | 258 double tt1 = intersections2[0][pt]; |
259 SkDPoint xy1 = quad1.xyAtT(tt1); | 259 SkDPoint xy1 = quad1.ptAtT(tt1); |
260 double tt2 = intersections2[1][pt]; | 260 double tt2 = intersections2[1][pt]; |
261 SkDPoint xy2 = quad2.xyAtT(tt2); | 261 SkDPoint xy2 = quad2.ptAtT(tt2); |
262 if (!xy1.approximatelyEqual(xy2)) { | 262 if (!xy1.approximatelyEqual(xy2)) { |
263 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", | 263 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", |
264 __FUNCTION__, static_cast<int>(outer), static_cast<int>(inne
r), | 264 __FUNCTION__, static_cast<int>(outer), static_cast<int>(inne
r), |
265 tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY); | 265 tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY); |
266 REPORTER_ASSERT(reporter, 0); | 266 REPORTER_ASSERT(reporter, 0); |
267 } | 267 } |
268 #if ONE_OFF_DEBUG | 268 #if ONE_OFF_DEBUG |
269 SkDebugf("%s [%d][%d] t1=%1.9g (%1.9g, %1.9g) t2=%1.9g\n", __FUNCTION__, | 269 SkDebugf("%s [%d][%d] t1=%1.9g (%1.9g, %1.9g) t2=%1.9g\n", __FUNCTION__, |
270 outer, inner, tt1, xy1.fX, xy1.fY, tt2); | 270 outer, inner, tt1, xy1.fX, xy1.fY, tt2); |
271 #endif | 271 #endif |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 {1.205732763658403, 0.81345617746834109}}}, //t=0.33333333333333331, 0
.63396444791444551 | 331 {1.205732763658403, 0.81345617746834109}}}, //t=0.33333333333333331, 0
.63396444791444551 |
332 {{{1.205684411948591, 0.81344322326274499}, {1.2057085875611198, 0.8134496999932
9253}, | 332 {{{1.205684411948591, 0.81344322326274499}, {1.2057085875611198, 0.8134496999932
9253}, |
333 {1.205732763658403, 0.81345617746834109}}}, //t=0.63395173631977986, 0
.63396444791444551 | 333 {1.205732763658403, 0.81345617746834109}}}, //t=0.63395173631977986, 0
.63396444791444551 |
334 {{{1.205732763658403, 0.81345617746834109}, {1.267928895828891, 0.83008534558465
619}, | 334 {{{1.205732763658403, 0.81345617746834109}, {1.267928895828891, 0.83008534558465
619}, |
335 {1.3333333333333333, 0.85185185185185175}}}, //t=0.63396444791444551, 0
.66666666666666663 | 335 {1.3333333333333333, 0.85185185185185175}}}, //t=0.63396444791444551, 0
.66666666666666663 |
336 }; | 336 }; |
337 | 337 |
338 static void pointFinder(const SkDQuad& q1, const SkDQuad& q2) { | 338 static void pointFinder(const SkDQuad& q1, const SkDQuad& q2) { |
339 for (int index = 0; index < 3; ++index) { | 339 for (int index = 0; index < 3; ++index) { |
340 double t = q1.nearestT(q2[index]); | 340 double t = q1.nearestT(q2[index]); |
341 SkDPoint onQuad = q1.xyAtT(t); | 341 SkDPoint onQuad = q1.ptAtT(t); |
342 SkDebugf("%s t=%1.9g (%1.9g,%1.9g) dist=%1.9g\n", __FUNCTION__, t, onQua
d.fX, onQuad.fY, | 342 SkDebugf("%s t=%1.9g (%1.9g,%1.9g) dist=%1.9g\n", __FUNCTION__, t, onQua
d.fX, onQuad.fY, |
343 onQuad.distance(q2[index])); | 343 onQuad.distance(q2[index])); |
344 double left[3]; | 344 double left[3]; |
345 left[0] = ((const SkDLine&) q1[0]).isLeft(q2[index]); | 345 left[0] = ((const SkDLine&) q1[0]).isLeft(q2[index]); |
346 left[1] = ((const SkDLine&) q1[1]).isLeft(q2[index]); | 346 left[1] = ((const SkDLine&) q1[1]).isLeft(q2[index]); |
347 SkDLine diag = {{q1[0], q1[2]}}; | 347 SkDLine diag = {{q1[0], q1[2]}}; |
348 left[2] = diag.isLeft(q2[index]); | 348 left[2] = diag.isLeft(q2[index]); |
349 SkDebugf("%s left=(%d, %d, %d) inHull=%s\n", __FUNCTION__, floatSign(lef
t[0]), | 349 SkDebugf("%s left=(%d, %d, %d) inHull=%s\n", __FUNCTION__, floatSign(lef
t[0]), |
350 floatSign(left[1]), floatSign(left[2]), | 350 floatSign(left[1]), floatSign(left[2]), |
351 q1.pointInHull(q2[index]) ? "true" : "false"); | 351 q1.pointInHull(q2[index]) ? "true" : "false"); |
(...skipping 29 matching lines...) Expand all Loading... |
381 const SkDQuad& quad1 = testSet[test1]; | 381 const SkDQuad& quad1 = testSet[test1]; |
382 const SkDQuad& quad2 = testSet[test2]; | 382 const SkDQuad& quad2 = testSet[test2]; |
383 | 383 |
384 double t1Seed = 0.5; | 384 double t1Seed = 0.5; |
385 double t2Seed = 0.8; | 385 double t2Seed = 0.8; |
386 double t1Step = 0.1; | 386 double t1Step = 0.1; |
387 double t2Step = 0.1; | 387 double t2Step = 0.1; |
388 SkDPoint t1[3], t2[3]; | 388 SkDPoint t1[3], t2[3]; |
389 bool toggle = true; | 389 bool toggle = true; |
390 do { | 390 do { |
391 t1[0] = quad1.xyAtT(t1Seed - t1Step); | 391 t1[0] = quad1.ptAtT(t1Seed - t1Step); |
392 t1[1] = quad1.xyAtT(t1Seed); | 392 t1[1] = quad1.ptAtT(t1Seed); |
393 t1[2] = quad1.xyAtT(t1Seed + t1Step); | 393 t1[2] = quad1.ptAtT(t1Seed + t1Step); |
394 t2[0] = quad2.xyAtT(t2Seed - t2Step); | 394 t2[0] = quad2.ptAtT(t2Seed - t2Step); |
395 t2[1] = quad2.xyAtT(t2Seed); | 395 t2[1] = quad2.ptAtT(t2Seed); |
396 t2[2] = quad2.xyAtT(t2Seed + t2Step); | 396 t2[2] = quad2.ptAtT(t2Seed + t2Step); |
397 double dist[3][3]; | 397 double dist[3][3]; |
398 dist[1][1] = t1[1].distance(t2[1]); | 398 dist[1][1] = t1[1].distance(t2[1]); |
399 int best_i = 1, best_j = 1; | 399 int best_i = 1, best_j = 1; |
400 for (int i = 0; i < 3; ++i) { | 400 for (int i = 0; i < 3; ++i) { |
401 for (int j = 0; j < 3; ++j) { | 401 for (int j = 0; j < 3; ++j) { |
402 if (i == 1 && j == 1) { | 402 if (i == 1 && j == 1) { |
403 continue; | 403 continue; |
404 } | 404 } |
405 dist[i][j] = t1[i].distance(t2[j]); | 405 dist[i][j] = t1[i].distance(t2[j]); |
406 if (dist[best_i][best_j] > dist[i][j]) { | 406 if (dist[best_i][best_j] > dist[i][j]) { |
(...skipping 20 matching lines...) Expand all Loading... |
427 } | 427 } |
428 } | 428 } |
429 } while (!t1[1].approximatelyEqual(t2[1])); | 429 } while (!t1[1].approximatelyEqual(t2[1])); |
430 t1Step = t2Step = 0.1; | 430 t1Step = t2Step = 0.1; |
431 double t10 = t1Seed - t1Step * 2; | 431 double t10 = t1Seed - t1Step * 2; |
432 double t12 = t1Seed + t1Step * 2; | 432 double t12 = t1Seed + t1Step * 2; |
433 double t20 = t2Seed - t2Step * 2; | 433 double t20 = t2Seed - t2Step * 2; |
434 double t22 = t2Seed + t2Step * 2; | 434 double t22 = t2Seed + t2Step * 2; |
435 SkDPoint test; | 435 SkDPoint test; |
436 while (!approximately_zero(t1Step)) { | 436 while (!approximately_zero(t1Step)) { |
437 test = quad1.xyAtT(t10); | 437 test = quad1.ptAtT(t10); |
438 t10 += t1[1].approximatelyEqual(test) ? -t1Step : t1Step; | 438 t10 += t1[1].approximatelyEqual(test) ? -t1Step : t1Step; |
439 t1Step /= 2; | 439 t1Step /= 2; |
440 } | 440 } |
441 t1Step = 0.1; | 441 t1Step = 0.1; |
442 while (!approximately_zero(t1Step)) { | 442 while (!approximately_zero(t1Step)) { |
443 test = quad1.xyAtT(t12); | 443 test = quad1.ptAtT(t12); |
444 t12 -= t1[1].approximatelyEqual(test) ? -t1Step : t1Step; | 444 t12 -= t1[1].approximatelyEqual(test) ? -t1Step : t1Step; |
445 t1Step /= 2; | 445 t1Step /= 2; |
446 } | 446 } |
447 while (!approximately_zero(t2Step)) { | 447 while (!approximately_zero(t2Step)) { |
448 test = quad2.xyAtT(t20); | 448 test = quad2.ptAtT(t20); |
449 t20 += t2[1].approximatelyEqual(test) ? -t2Step : t2Step; | 449 t20 += t2[1].approximatelyEqual(test) ? -t2Step : t2Step; |
450 t2Step /= 2; | 450 t2Step /= 2; |
451 } | 451 } |
452 t2Step = 0.1; | 452 t2Step = 0.1; |
453 while (!approximately_zero(t2Step)) { | 453 while (!approximately_zero(t2Step)) { |
454 test = quad2.xyAtT(t22); | 454 test = quad2.ptAtT(t22); |
455 t22 -= t2[1].approximatelyEqual(test) ? -t2Step : t2Step; | 455 t22 -= t2[1].approximatelyEqual(test) ? -t2Step : t2Step; |
456 t2Step /= 2; | 456 t2Step /= 2; |
457 } | 457 } |
458 #if ONE_OFF_DEBUG | 458 #if ONE_OFF_DEBUG |
459 SkDebugf("%s t1=(%1.9g<%1.9g<%1.9g) t2=(%1.9g<%1.9g<%1.9g)\n", __FUNCTION__, | 459 SkDebugf("%s t1=(%1.9g<%1.9g<%1.9g) t2=(%1.9g<%1.9g<%1.9g)\n", __FUNCTION__, |
460 t10, t1Seed, t12, t20, t2Seed, t22); | 460 t10, t1Seed, t12, t20, t2Seed, t22); |
461 SkDPoint p10 = quad1.xyAtT(t10); | 461 SkDPoint p10 = quad1.ptAtT(t10); |
462 SkDPoint p1Seed = quad1.xyAtT(t1Seed); | 462 SkDPoint p1Seed = quad1.ptAtT(t1Seed); |
463 SkDPoint p12 = quad1.xyAtT(t12); | 463 SkDPoint p12 = quad1.ptAtT(t12); |
464 SkDebugf("%s p1=(%1.9g,%1.9g)<(%1.9g,%1.9g)<(%1.9g,%1.9g)\n", __FUNCTION__, | 464 SkDebugf("%s p1=(%1.9g,%1.9g)<(%1.9g,%1.9g)<(%1.9g,%1.9g)\n", __FUNCTION__, |
465 p10.fX, p10.fY, p1Seed.fX, p1Seed.fY, p12.fX, p12.fY); | 465 p10.fX, p10.fY, p1Seed.fX, p1Seed.fY, p12.fX, p12.fY); |
466 SkDPoint p20 = quad2.xyAtT(t20); | 466 SkDPoint p20 = quad2.ptAtT(t20); |
467 SkDPoint p2Seed = quad2.xyAtT(t2Seed); | 467 SkDPoint p2Seed = quad2.ptAtT(t2Seed); |
468 SkDPoint p22 = quad2.xyAtT(t22); | 468 SkDPoint p22 = quad2.ptAtT(t22); |
469 SkDebugf("%s p2=(%1.9g,%1.9g)<(%1.9g,%1.9g)<(%1.9g,%1.9g)\n", __FUNCTION__, | 469 SkDebugf("%s p2=(%1.9g,%1.9g)<(%1.9g,%1.9g)<(%1.9g,%1.9g)\n", __FUNCTION__, |
470 p20.fX, p20.fY, p2Seed.fX, p2Seed.fY, p22.fX, p22.fY); | 470 p20.fX, p20.fY, p2Seed.fX, p2Seed.fY, p22.fX, p22.fY); |
471 #endif | 471 #endif |
472 } | 472 } |
473 | 473 |
474 static void QuadraticIntersection_IntersectionFinder() { | 474 static void QuadraticIntersection_IntersectionFinder() { |
475 intersectionFinder(0, 1); | 475 intersectionFinder(0, 1); |
476 } | 476 } |
477 | 477 |
478 static void PathOpsQuadIntersectionTest(skiatest::Reporter* reporter) { | 478 static void PathOpsQuadIntersectionTest(skiatest::Reporter* reporter) { |
479 oneOffTests(reporter); | 479 oneOffTests(reporter); |
480 coincidentTest(reporter); | 480 coincidentTest(reporter); |
481 standardTestCases(reporter); | 481 standardTestCases(reporter); |
482 if (false) QuadraticIntersection_IntersectionFinder(); | 482 if (false) QuadraticIntersection_IntersectionFinder(); |
483 if (false) QuadraticIntersection_PointFinder(); | 483 if (false) QuadraticIntersection_PointFinder(); |
484 } | 484 } |
485 | 485 |
486 | 486 |
487 #include "TestClassDef.h" | 487 #include "TestClassDef.h" |
488 DEFINE_TESTCLASS_SHORT(PathOpsQuadIntersectionTest) | 488 DEFINE_TESTCLASS_SHORT(PathOpsQuadIntersectionTest) |
489 | 489 |
490 DEFINE_TESTCLASS_SHORT(PathOpsQuadIntersectionOneOffTest) | 490 DEFINE_TESTCLASS_SHORT(PathOpsQuadIntersectionOneOffTest) |
OLD | NEW |