Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: tests/PathOpsQuadIntersectionTest.cpp

Issue 1037573004: cumulative pathops patch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix pathopsinverse gm Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/PathOpsOpTest.cpp ('k') | tests/PathOpsQuadIntersectionTestData.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
53 } 53 }
54 54
55 static const SkDQuad testSet[] = { 55 static const SkDQuad testSet[] = {
56 {{{4981.9990234375, 1590}, {4981.9990234375, 1617.7523193359375}, {4962.375, 163 7.3760986328125}}},
57 {{{4962.3759765625, 1637.3760986328125}, {4982, 1617.7523193359375}, {4982, 1590 }}},
58
59 {{{48.7416f, 7.74160004f}, {96.4831848f, -40}, {164, -40}}},
60 {{{56.9671326f, 0}, {52.7835083f, 3.69968891f}, {48.7416f, 7.74160004f}}},
61
62 {{{138, 80}, {147.15692138671875, 80}, {155.12803649902344, 82.86279296875}}},
63 {{{155.12803649902344, 82.86279296875}, {153.14971923828125, 82.152290344238281} , {151.09841918945312, 81.618133544921875}}},
64
65 {{{88, 130}, {88, 131.54483032226562}, {88.081489562988281, 133.0560302734375}}} ,
66 {{{88.081489562988281, 133.0560302734375}, {88, 131.54483032226562}, {88, 130}}} ,
67
68 {{{0.59987992,2.14448452}, {0.775417507,1.95606446}, {1.00564098,1.79310346}}},
69 {{{1.00564098,1.79310346}, {1.25936198,1.615623}, {1.35901463,1.46834028}}},
70
71 {{{3,0}, {0,1}, {3,2}}},
72 {{{2,0}, {1,1}, {2,2}}},
73
74 {{{38.656852722167969, 38.656852722167969}, {38.651023864746094, 38.662681579589 844}, {38.644744873046875, 38.668937683105469}}},
75 {{{38.656852722167969, 38.656852722167969}, {36.313709259033203, 41}, {33, 41}}} ,
76
77 {{{4914.9990234375, 1523}, {4942.75146484375, 1523}, {4962.375, 1542.62390136718 75}}},
78 {{{4962.3759765625, 1542.6239013671875}, {4942.75244140625, 1523}, {4915, 1523}} },
79
80 {{{4867.623046875, 1637.3760986328125}, {4847.9990234375, 1617.7523193359375}, { 4847.9990234375, 1590}}},
81 {{{4848, 1590}, {4848, 1617.7523193359375}, {4867.6240234375, 1637.3760986328125 }}},
82
83 {{{102.64466094970703, 165.3553466796875}, {110.79246520996094, 173.503143310546 87}, {120.81797790527344, 177.11778259277344}}},
84 {{{113.232177734375, 173.57899475097656}, {116.88026428222656, 175.6980590820312 5}, {120.81797790527344, 177.11778259277344}}},
85
56 {{{-37.3484879,10.0192947}, {-36.4966316,13.2140198}, {-38.1506348,16.0788383}}} , 86 {{{-37.3484879,10.0192947}, {-36.4966316,13.2140198}, {-38.1506348,16.0788383}}} ,
57 {{{-38.1462746,16.08918}, {-36.4904327,13.2193804}, {-37.3484879,10.0192947}}}, 87 {{{-38.1462746,16.08918}, {-36.4904327,13.2193804}, {-37.3484879,10.0192947}}},
58 88
59 {{{-37.3513985,10.0082998}, {-36.4938011,13.2090998}, {-38.1506004,16.0788002}}} , 89 {{{-37.3513985,10.0082998}, {-36.4938011,13.2090998}, {-38.1506004,16.0788002}}} ,
60 {{{-37.3508987,10.0102997}, {-36.4930992,13.2110004}, {-38.1497993,16.0809002}}} , 90 {{{-37.3508987,10.0102997}, {-36.4930992,13.2110004}, {-38.1497993,16.0809002}}} ,
61 91
62 {{{-37.3508987,10.0102997}, {-37.3510017,10.0098}, {-37.3512001,10.0093002}}}, 92 {{{-37.3508987,10.0102997}, {-37.3510017,10.0098}, {-37.3512001,10.0093002}}},
63 {{{-49.0778008,19.0097008}, {-38.2086983,6.80954981}, {-37.3508987,10.0102997}}} , 93 {{{-49.0778008,19.0097008}, {-38.2086983,6.80954981}, {-37.3508987,10.0102997}}} ,
64 94
65 {{{SkBits2Float(0xc22423b2), SkBits2Float(0x40afae2c)}, 95 {{{SkBits2Float(0xc22423b2), SkBits2Float(0x40afae2c)},
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 343
314 static void oneOffTests(skiatest::Reporter* reporter) { 344 static void oneOffTests(skiatest::Reporter* reporter) {
315 for (size_t outer = 0; outer < testSetCount - 1; ++outer) { 345 for (size_t outer = 0; outer < testSetCount - 1; ++outer) {
316 for (size_t inner = outer + 1; inner < testSetCount; ++inner) { 346 for (size_t inner = outer + 1; inner < testSetCount; ++inner) {
317 oneOffTest1(reporter, outer, inner); 347 oneOffTest1(reporter, outer, inner);
318 } 348 }
319 } 349 }
320 } 350 }
321 351
322 static const SkDQuad coincidentTestSet[] = { 352 static const SkDQuad coincidentTestSet[] = {
353 {{{4914.9990234375, 1523}, {4942.75146484375, 1523}, {4962.375, 1542.6239013 671875}}},
354 {{{4962.3759765625, 1542.6239013671875}, {4942.75244140625, 1523}, {4915, 15 23}}},
323 #if 0 355 #if 0
324 {{{97.9337615966796875,100}, {88,112.94264984130859375}, {88,130}}}, 356 {{{97.9337615966796875,100}, {88,112.94264984130859375}, {88,130}}},
325 {{{88,130}, {88,124.80951690673828125}, {88.91983795166015625,120}}}, 357 {{{88,130}, {88,124.80951690673828125}, {88.91983795166015625,120}}},
326 #endif 358 #endif
327 {{{369.850525, 145.675964}, {382.362915, 121.29287}, {406.211273, 121.29287} }}, 359 {{{369.850525, 145.675964}, {382.362915, 121.29287}, {406.211273, 121.29287} }},
328 {{{369.850525, 145.675964}, {382.362915, 121.29287}, {406.211273, 121.29287} }}, 360 {{{369.850525, 145.675964}, {382.362915, 121.29287}, {406.211273, 121.29287} }},
329 {{{8, 8}, {10, 10}, {8, -10}}}, 361 {{{8, 8}, {10, 10}, {8, -10}}},
330 {{{8, -10}, {10, 10}, {8, 8}}}, 362 {{{8, -10}, {10, 10}, {8, 8}}},
331 }; 363 };
332 364
333 static const int coincidentTestSetCount = (int) SK_ARRAY_COUNT(coincidentTestSet ); 365 static const int coincidentTestSetCount = (int) SK_ARRAY_COUNT(coincidentTestSet );
334 366
335 static void coincidentTestOne(skiatest::Reporter* reporter, int test1, int test2 ) { 367 static void coincidentTestOne(skiatest::Reporter* reporter, int test1, int test2 ) {
336 const SkDQuad& quad1 = coincidentTestSet[test1]; 368 const SkDQuad& quad1 = coincidentTestSet[test1];
337 SkASSERT(ValidQuad(quad1)); 369 SkASSERT(ValidQuad(quad1));
338 const SkDQuad& quad2 = coincidentTestSet[test2]; 370 const SkDQuad& quad2 = coincidentTestSet[test2];
339 SkASSERT(ValidQuad(quad2)); 371 SkASSERT(ValidQuad(quad2));
340 SkIntersections intersections2; 372 SkIntersections intersections2;
341 intersections2.intersect(quad1, quad2); 373 intersections2.intersect(quad1, quad2);
342 REPORTER_ASSERT(reporter, intersections2.coincidentUsed() == 2); 374 REPORTER_ASSERT(reporter, intersections2.coincidentUsed() >= 2);
343 REPORTER_ASSERT(reporter, intersections2.used() == 2); 375 REPORTER_ASSERT(reporter, intersections2.used() >= 2);
344 for (int pt = 0; pt < intersections2.coincidentUsed(); ++pt) { 376 for (int pt = 0; pt < intersections2.coincidentUsed(); pt += 2) {
345 double tt1 = intersections2[0][pt]; 377 double tt1 = intersections2[0][pt];
346 double tt2 = intersections2[1][pt]; 378 double tt2 = intersections2[1][pt];
347 SkDPoint pt1 = quad1.ptAtT(tt1); 379 SkDPoint pt1 = quad1.ptAtT(tt1);
348 SkDPoint pt2 = quad2.ptAtT(tt2); 380 SkDPoint pt2 = quad2.ptAtT(tt2);
349 REPORTER_ASSERT(reporter, pt1.approximatelyEqual(pt2)); 381 REPORTER_ASSERT(reporter, pt1.approximatelyEqual(pt2));
350 } 382 }
351 } 383 }
352 384
353 static void coincidentTest(skiatest::Reporter* reporter) { 385 static void coincidentTest(skiatest::Reporter* reporter) {
354 for (int testIndex = 0; testIndex < coincidentTestSetCount - 1; testIndex += 2) { 386 for (int testIndex = 0; testIndex < coincidentTestSetCount - 1; testIndex += 2) {
(...skipping 28 matching lines...) Expand all
383 for (int index = 0; index < 3; ++index) { 415 for (int index = 0; index < 3; ++index) {
384 double t = q1.nearestT(q2[index]); 416 double t = q1.nearestT(q2[index]);
385 SkDPoint onQuad = q1.ptAtT(t); 417 SkDPoint onQuad = q1.ptAtT(t);
386 SkDebugf("%s t=%1.9g (%1.9g,%1.9g) dist=%1.9g\n", __FUNCTION__, t, onQua d.fX, onQuad.fY, 418 SkDebugf("%s t=%1.9g (%1.9g,%1.9g) dist=%1.9g\n", __FUNCTION__, t, onQua d.fX, onQuad.fY,
387 onQuad.distance(q2[index])); 419 onQuad.distance(q2[index]));
388 double left[3]; 420 double left[3];
389 left[0] = ((const SkDLine&) q1[0]).isLeft(q2[index]); 421 left[0] = ((const SkDLine&) q1[0]).isLeft(q2[index]);
390 left[1] = ((const SkDLine&) q1[1]).isLeft(q2[index]); 422 left[1] = ((const SkDLine&) q1[1]).isLeft(q2[index]);
391 SkDLine diag = {{q1[0], q1[2]}}; 423 SkDLine diag = {{q1[0], q1[2]}};
392 left[2] = diag.isLeft(q2[index]); 424 left[2] = diag.isLeft(q2[index]);
393 SkDebugf("%s left=(%d, %d, %d) inHull=%s\n", __FUNCTION__, floatSign(lef t[0]), 425 SkDebugf("%s left=(%d, %d, %d)\n", __FUNCTION__, floatSign(left[0]),
394 floatSign(left[1]), floatSign(left[2]), 426 floatSign(left[1]), floatSign(left[2]));
395 q1.pointInHull(q2[index]) ? "true" : "false");
396 } 427 }
397 SkDebugf("\n"); 428 SkDebugf("\n");
398 } 429 }
399 430
400 static void hullIntersect(const SkDQuad& q1, const SkDQuad& q2) { 431 static void hullIntersect(const SkDQuad& q1, const SkDQuad& q2) {
401 SkDebugf("%s", __FUNCTION__); 432 SkDebugf("%s", __FUNCTION__);
402 SkIntersections ts; 433 SkIntersections ts;
403 for (int i1 = 0; i1 < 3; ++i1) { 434 for (int i1 = 0; i1 < 3; ++i1) {
404 SkDLine l1 = {{q1[i1], q1[(i1 + 1) % 3]}}; 435 SkDLine l1 = {{q1[i1], q1[(i1 + 1) % 3]}};
405 for (int i2 = 0; i2 < 3; ++i2) { 436 for (int i2 = 0; i2 < 3; ++i2) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 SkDPoint p22 = quad2.ptAtT(t22); 543 SkDPoint p22 = quad2.ptAtT(t22);
513 SkDebugf("%s p2=(%1.9g,%1.9g)<(%1.9g,%1.9g)<(%1.9g,%1.9g)\n", __FUNCTION__, 544 SkDebugf("%s p2=(%1.9g,%1.9g)<(%1.9g,%1.9g)<(%1.9g,%1.9g)\n", __FUNCTION__,
514 p20.fX, p20.fY, p2Seed.fX, p2Seed.fY, p22.fX, p22.fY); 545 p20.fX, p20.fY, p2Seed.fX, p2Seed.fY, p22.fX, p22.fY);
515 #endif 546 #endif
516 } 547 }
517 548
518 static void QuadraticIntersection_IntersectionFinder() { 549 static void QuadraticIntersection_IntersectionFinder() {
519 intersectionFinder(0, 1); 550 intersectionFinder(0, 1);
520 } 551 }
521 552
553 DEF_TEST(PathOpsQuadIntersectionOneOff, reporter) {
554 oneOffTest1(reporter, 10, 11);
555 }
556
557 DEF_TEST(PathOpsQuadIntersectionCoincidenceOneOff, reporter) {
558 coincidentTestOne(reporter, 0, 1);
559 }
560
522 DEF_TEST(PathOpsQuadIntersection, reporter) { 561 DEF_TEST(PathOpsQuadIntersection, reporter) {
523 oneOffTests(reporter); 562 oneOffTests(reporter);
524 coincidentTest(reporter); 563 coincidentTest(reporter);
525 standardTestCases(reporter); 564 standardTestCases(reporter);
526 if (false) QuadraticIntersection_IntersectionFinder(); 565 if (false) QuadraticIntersection_IntersectionFinder();
527 if (false) QuadraticIntersection_PointFinder(); 566 if (false) QuadraticIntersection_PointFinder();
528 } 567 }
529 568
530 DEF_TEST(PathOpsQuadIntersectionCoincidenceOneOff, reporter) { 569 #include "SkCommonFlags.h"
531 coincidentTestOne(reporter, 0, 1); 570
571 DEF_TEST(PathOpsQuadBinaryProfile, reporter) {
572 if (!FLAGS_veryVerbose) {
573 return;
574 }
575 SkIntersections intersections;
576 for (int x = 0; x < 100; ++x) {
577 int outer = 0;
578 int inner = outer + 1;
579 do {
580 const SkDQuad& quad1 = testSet[outer];
581 const SkDQuad& quad2 = testSet[inner];
582 (void) intersections.intersect(quad1, quad2);
583 REPORTER_ASSERT(reporter, intersections.used() >= 0); // make sure code isn't tossed
584 inner += 2;
585 outer += 2;
586 } while (outer < (int) testSetCount);
587 }
588 for (int x = 0; x < 100; ++x) {
589 for (size_t test = 0; test < quadraticTests_count; ++test) {
590 const SkDQuad& quad1 = quadraticTests[test][0];
591 const SkDQuad& quad2 = quadraticTests[test][1];
592 (void) intersections.intersect(quad1, quad2);
593 REPORTER_ASSERT(reporter, intersections.used() >= 0); // make sure code isn't tossed
594 }
595 }
532 } 596 }
533
534 DEF_TEST(PathOpsQuadIntersectionOneOff, reporter) {
535 oneOffTest1(reporter, 0, 1);
536 }
OLDNEW
« no previous file with comments | « tests/PathOpsOpTest.cpp ('k') | tests/PathOpsQuadIntersectionTestData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698