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

Side by Side Diff: tests/PathOpsQuadIntersectionTest.cpp

Issue 1111333002: compute initial winding from projected rays (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add missing test reference Created 5 years, 7 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/PathOpsSimplifyTest.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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 370
371 static const int coincidentTestSetCount = (int) SK_ARRAY_COUNT(coincidentTestSet ); 371 static const int coincidentTestSetCount = (int) SK_ARRAY_COUNT(coincidentTestSet );
372 372
373 static void coincidentTestOne(skiatest::Reporter* reporter, int test1, int test2 ) { 373 static void coincidentTestOne(skiatest::Reporter* reporter, int test1, int test2 ) {
374 const SkDQuad& quad1 = coincidentTestSet[test1]; 374 const SkDQuad& quad1 = coincidentTestSet[test1];
375 SkASSERT(ValidQuad(quad1)); 375 SkASSERT(ValidQuad(quad1));
376 const SkDQuad& quad2 = coincidentTestSet[test2]; 376 const SkDQuad& quad2 = coincidentTestSet[test2];
377 SkASSERT(ValidQuad(quad2)); 377 SkASSERT(ValidQuad(quad2));
378 SkIntersections intersections2; 378 SkIntersections intersections2;
379 intersections2.intersect(quad1, quad2); 379 intersections2.intersect(quad1, quad2);
380 REPORTER_ASSERT(reporter, intersections2.coincidentUsed() >= 2); 380 REPORTER_ASSERT(reporter, intersections2.debugCoincidentUsed() >= 2);
381 REPORTER_ASSERT(reporter, intersections2.used() >= 2); 381 REPORTER_ASSERT(reporter, intersections2.used() >= 2);
382 for (int pt = 0; pt < intersections2.coincidentUsed(); pt += 2) { 382 for (int pt = 0; pt < intersections2.debugCoincidentUsed(); pt += 2) {
383 double tt1 = intersections2[0][pt]; 383 double tt1 = intersections2[0][pt];
384 double tt2 = intersections2[1][pt]; 384 double tt2 = intersections2[1][pt];
385 SkDPoint pt1 = quad1.ptAtT(tt1); 385 SkDPoint pt1 = quad1.ptAtT(tt1);
386 SkDPoint pt2 = quad2.ptAtT(tt2); 386 SkDPoint pt2 = quad2.ptAtT(tt2);
387 REPORTER_ASSERT(reporter, pt1.approximatelyEqual(pt2)); 387 REPORTER_ASSERT(reporter, pt1.approximatelyEqual(pt2));
388 } 388 }
389 } 389 }
390 390
391 static void coincidentTest(skiatest::Reporter* reporter) { 391 static void coincidentTest(skiatest::Reporter* reporter) {
392 for (int testIndex = 0; testIndex < coincidentTestSetCount - 1; testIndex += 2) { 392 for (int testIndex = 0; testIndex < coincidentTestSetCount - 1; testIndex += 2) {
393 coincidentTestOne(reporter, testIndex, testIndex + 1); 393 coincidentTestOne(reporter, testIndex, testIndex + 1);
394 } 394 }
395 } 395 }
396 396
397 static int floatSign(double x) {
398 return x < 0 ? -1 : x > 0 ? 1 : 0;
399 }
400
401 static const SkDQuad pointFinderTestSet[] = {
402 //>=0.633974464 0.633974 846 <=
403 {{{1.2071879545809394, 0.82163474041730045}, {1.1534203513372994, 0.527908700699 30229},
404 {1.0880000000000001, 0.29599999999999982}}}, //t=0.63155333662549329, 0 .80000000000000004
405 {{{1.2071879545809394, 0.82163474041730045}, {1.2065040319428038, 0.817667532591 19995},
406 {1.2058123269101506, 0.81370135061854221}}}, //t=0.63155333662549329, 0 .6339049773632347
407 {{{1.2058123269101506, 0.81370135061854221}, {1.152376363978022, 0.5244097415381 026},
408 {1.0880000000000001, 0.29599999999999982}}}, //t=0.6339049773632347, 0 .80000000000000004
409 //>=0.633974083 0.633975 227 <=
410 {{{0.33333333333333326, 0.81481481481481488}, {0.63395173631977997, 0.6874413672 6313931},
411 {1.205684411948591, 0.81344322326274499}}}, //t=0.33333333333333331, 0 .63395173631977986
412 {{{0.33333333333333326, 0.81481481481481488}, {0.63396444791444551, 0.6874336836 2444768},
413 {1.205732763658403, 0.81345617746834109}}}, //t=0.33333333333333331, 0 .63396444791444551
414 {{{1.205684411948591, 0.81344322326274499}, {1.2057085875611198, 0.8134496999932 9253},
415 {1.205732763658403, 0.81345617746834109}}}, //t=0.63395173631977986, 0 .63396444791444551
416 {{{1.205732763658403, 0.81345617746834109}, {1.267928895828891, 0.83008534558465 619},
417 {1.3333333333333333, 0.85185185185185175}}}, //t=0.63396444791444551, 0 .66666666666666663
418 };
419
420 static void pointFinder(const SkDQuad& q1, const SkDQuad& q2) {
421 for (int index = 0; index < 3; ++index) {
422 double t = q1.nearestT(q2[index]);
423 SkDPoint onQuad = q1.ptAtT(t);
424 SkDebugf("%s t=%1.9g (%1.9g,%1.9g) dist=%1.9g\n", __FUNCTION__, t, onQua d.fX, onQuad.fY,
425 onQuad.distance(q2[index]));
426 double left[3];
427 left[0] = ((const SkDLine&) q1[0]).isLeft(q2[index]);
428 left[1] = ((const SkDLine&) q1[1]).isLeft(q2[index]);
429 SkDLine diag = {{q1[0], q1[2]}};
430 left[2] = diag.isLeft(q2[index]);
431 SkDebugf("%s left=(%d, %d, %d)\n", __FUNCTION__, floatSign(left[0]),
432 floatSign(left[1]), floatSign(left[2]));
433 }
434 SkDebugf("\n");
435 }
436
437 static void hullIntersect(const SkDQuad& q1, const SkDQuad& q2) {
438 SkDebugf("%s", __FUNCTION__);
439 SkIntersections ts;
440 for (int i1 = 0; i1 < 3; ++i1) {
441 SkDLine l1 = {{q1[i1], q1[(i1 + 1) % 3]}};
442 for (int i2 = 0; i2 < 3; ++i2) {
443 SkDLine l2 = {{q2[i2], q2[(i2 + 1) % 3]}};
444 if (ts.intersect(l1, l2)) {
445 SkDebugf(" [%d,%d]", i1, i2);
446 }
447 }
448 }
449 SkDebugf("\n");
450 }
451
452 static void QuadraticIntersection_PointFinder() {
453 pointFinder(pointFinderTestSet[0], pointFinderTestSet[4]);
454 pointFinder(pointFinderTestSet[4], pointFinderTestSet[0]);
455 pointFinder(pointFinderTestSet[0], pointFinderTestSet[6]);
456 pointFinder(pointFinderTestSet[6], pointFinderTestSet[0]);
457 hullIntersect(pointFinderTestSet[0], pointFinderTestSet[4]);
458 hullIntersect(pointFinderTestSet[0], pointFinderTestSet[6]);
459 }
460
461 static void intersectionFinder(int test1, int test2) { 397 static void intersectionFinder(int test1, int test2) {
462 const SkDQuad& quad1 = testSet[test1]; 398 const SkDQuad& quad1 = testSet[test1];
463 const SkDQuad& quad2 = testSet[test2]; 399 const SkDQuad& quad2 = testSet[test2];
464 400
465 double t1Seed = 0.5; 401 double t1Seed = 0.5;
466 double t2Seed = 0.8; 402 double t2Seed = 0.8;
467 double t1Step = 0.1; 403 double t1Step = 0.1;
468 double t2Step = 0.1; 404 double t2Step = 0.1;
469 SkDPoint t1[3], t2[3]; 405 SkDPoint t1[3], t2[3];
470 bool toggle = true; 406 bool toggle = true;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 498
563 DEF_TEST(PathOpsQuadIntersectionCoincidenceOneOff, reporter) { 499 DEF_TEST(PathOpsQuadIntersectionCoincidenceOneOff, reporter) {
564 coincidentTestOne(reporter, 0, 1); 500 coincidentTestOne(reporter, 0, 1);
565 } 501 }
566 502
567 DEF_TEST(PathOpsQuadIntersection, reporter) { 503 DEF_TEST(PathOpsQuadIntersection, reporter) {
568 oneOffTests(reporter); 504 oneOffTests(reporter);
569 coincidentTest(reporter); 505 coincidentTest(reporter);
570 standardTestCases(reporter); 506 standardTestCases(reporter);
571 if (false) QuadraticIntersection_IntersectionFinder(); 507 if (false) QuadraticIntersection_IntersectionFinder();
572 if (false) QuadraticIntersection_PointFinder();
573 } 508 }
574 509
575 #include "SkCommonFlags.h" 510 #include "SkCommonFlags.h"
576 511
577 DEF_TEST(PathOpsQuadBinaryProfile, reporter) { 512 DEF_TEST(PathOpsQuadBinaryProfile, reporter) {
578 if (!FLAGS_veryVerbose) { 513 if (!FLAGS_veryVerbose) {
579 return; 514 return;
580 } 515 }
581 SkIntersections intersections; 516 SkIntersections intersections;
582 for (int x = 0; x < 100; ++x) { 517 for (int x = 0; x < 100; ++x) {
(...skipping 10 matching lines...) Expand all
593 } 528 }
594 for (int x = 0; x < 100; ++x) { 529 for (int x = 0; x < 100; ++x) {
595 for (size_t test = 0; test < quadraticTests_count; ++test) { 530 for (size_t test = 0; test < quadraticTests_count; ++test) {
596 const SkDQuad& quad1 = quadraticTests[test][0]; 531 const SkDQuad& quad1 = quadraticTests[test][0];
597 const SkDQuad& quad2 = quadraticTests[test][1]; 532 const SkDQuad& quad2 = quadraticTests[test][1];
598 (void) intersections.intersect(quad1, quad2); 533 (void) intersections.intersect(quad1, quad2);
599 REPORTER_ASSERT(reporter, intersections.used() >= 0); // make sure code isn't tossed 534 REPORTER_ASSERT(reporter, intersections.used() >= 0); // make sure code isn't tossed
600 } 535 }
601 } 536 }
602 } 537 }
OLDNEW
« no previous file with comments | « tests/PathOpsOpTest.cpp ('k') | tests/PathOpsSimplifyTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698