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

Side by Side Diff: tests/PathTest.cpp

Issue 1517883002: fix SkPath::contains() for points on edge, conics (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add comment Created 5 years 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 | « src/core/SkPath.cpp ('k') | no next file » | 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 2011 Google Inc. 2 * Copyright 2011 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 7
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkGeometry.h"
9 #include "SkPaint.h" 10 #include "SkPaint.h"
10 #include "SkParse.h" 11 #include "SkParse.h"
11 #include "SkParsePath.h" 12 #include "SkParsePath.h"
12 #include "SkPathPriv.h" 13 #include "SkPathPriv.h"
13 #include "SkPathEffect.h" 14 #include "SkPathEffect.h"
14 #include "SkRRect.h" 15 #include "SkRRect.h"
15 #include "SkRandom.h" 16 #include "SkRandom.h"
16 #include "SkReader32.h" 17 #include "SkReader32.h"
17 #include "SkSize.h" 18 #include "SkSize.h"
18 #include "SkStream.h" 19 #include "SkStream.h"
(...skipping 3488 matching lines...) Expand 10 before | Expand all | Expand 10 after
3507 3508
3508 static void test_contains(skiatest::Reporter* reporter) { 3509 static void test_contains(skiatest::Reporter* reporter) {
3509 SkPath p; 3510 SkPath p;
3510 p.setFillType(SkPath::kInverseWinding_FillType); 3511 p.setFillType(SkPath::kInverseWinding_FillType);
3511 REPORTER_ASSERT(reporter, p.contains(0, 0)); 3512 REPORTER_ASSERT(reporter, p.contains(0, 0));
3512 p.setFillType(SkPath::kWinding_FillType); 3513 p.setFillType(SkPath::kWinding_FillType);
3513 REPORTER_ASSERT(reporter, !p.contains(0, 0)); 3514 REPORTER_ASSERT(reporter, !p.contains(0, 0));
3514 p.moveTo(4, 4); 3515 p.moveTo(4, 4);
3515 p.lineTo(6, 8); 3516 p.lineTo(6, 8);
3516 p.lineTo(8, 4); 3517 p.lineTo(8, 4);
3518 // test on edge
3519 REPORTER_ASSERT(reporter, p.contains(6, 4));
3520 REPORTER_ASSERT(reporter, p.contains(5, 6));
3521 REPORTER_ASSERT(reporter, p.contains(7, 6));
3517 // test quick reject 3522 // test quick reject
3518 REPORTER_ASSERT(reporter, !p.contains(4, 0)); 3523 REPORTER_ASSERT(reporter, !p.contains(4, 0));
3519 REPORTER_ASSERT(reporter, !p.contains(0, 4)); 3524 REPORTER_ASSERT(reporter, !p.contains(0, 4));
3520 REPORTER_ASSERT(reporter, !p.contains(4, 10)); 3525 REPORTER_ASSERT(reporter, !p.contains(4, 10));
3521 REPORTER_ASSERT(reporter, !p.contains(10, 4)); 3526 REPORTER_ASSERT(reporter, !p.contains(10, 4));
3522 // test various crossings in x 3527 // test various crossings in x
3523 REPORTER_ASSERT(reporter, !p.contains(5, 7)); 3528 REPORTER_ASSERT(reporter, !p.contains(5, 7));
3524 REPORTER_ASSERT(reporter, p.contains(6, 7)); 3529 REPORTER_ASSERT(reporter, p.contains(6, 7));
3525 REPORTER_ASSERT(reporter, !p.contains(7, 7)); 3530 REPORTER_ASSERT(reporter, !p.contains(7, 7));
3526 p.reset(); 3531 p.reset();
3527 p.moveTo(4, 4); 3532 p.moveTo(4, 4);
3528 p.lineTo(8, 6); 3533 p.lineTo(8, 6);
3529 p.lineTo(4, 8); 3534 p.lineTo(4, 8);
3535 // test on edge
3536 REPORTER_ASSERT(reporter, p.contains(4, 6));
3537 REPORTER_ASSERT(reporter, p.contains(6, 5));
3538 REPORTER_ASSERT(reporter, p.contains(6, 7));
3530 // test various crossings in y 3539 // test various crossings in y
3531 REPORTER_ASSERT(reporter, !p.contains(7, 5)); 3540 REPORTER_ASSERT(reporter, !p.contains(7, 5));
3532 REPORTER_ASSERT(reporter, p.contains(7, 6)); 3541 REPORTER_ASSERT(reporter, p.contains(7, 6));
3533 REPORTER_ASSERT(reporter, !p.contains(7, 7)); 3542 REPORTER_ASSERT(reporter, !p.contains(7, 7));
3543 p.reset();
3544 p.moveTo(4, 4);
3545 p.lineTo(6, 8);
3546 p.lineTo(2, 8);
3547 // test on edge
3548 REPORTER_ASSERT(reporter, p.contains(5, 6));
3549 REPORTER_ASSERT(reporter, p.contains(4, 8));
3550 REPORTER_ASSERT(reporter, p.contains(3, 6));
3551 p.reset();
3552 p.moveTo(4, 4);
3553 p.lineTo(0, 6);
3554 p.lineTo(4, 8);
3555 // test on edge
3556 REPORTER_ASSERT(reporter, p.contains(2, 5));
3557 REPORTER_ASSERT(reporter, p.contains(2, 7));
3558 REPORTER_ASSERT(reporter, p.contains(4, 6));
3559 // test canceling coincident edge (a smaller triangle is coincident with a l arger one)
3560 p.reset();
3561 p.moveTo(4, 0);
3562 p.lineTo(6, 4);
3563 p.lineTo(2, 4);
3564 p.moveTo(4, 0);
3565 p.lineTo(0, 8);
3566 p.lineTo(8, 8);
3567 REPORTER_ASSERT(reporter, !p.contains(1, 2));
3568 REPORTER_ASSERT(reporter, !p.contains(3, 2));
3569 REPORTER_ASSERT(reporter, !p.contains(4, 0));
3570 REPORTER_ASSERT(reporter, p.contains(4, 4));
3571
3534 // test quads 3572 // test quads
3535 p.reset(); 3573 p.reset();
3536 p.moveTo(4, 4); 3574 p.moveTo(4, 4);
3537 p.quadTo(6, 6, 8, 8); 3575 p.quadTo(6, 6, 8, 8);
3538 p.quadTo(6, 8, 4, 8); 3576 p.quadTo(6, 8, 4, 8);
3539 p.quadTo(4, 6, 4, 4); 3577 p.quadTo(4, 6, 4, 4);
3540 REPORTER_ASSERT(reporter, p.contains(5, 6)); 3578 REPORTER_ASSERT(reporter, p.contains(5, 6));
3541 REPORTER_ASSERT(reporter, !p.contains(6, 5)); 3579 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3580 // test quad edge
3581 REPORTER_ASSERT(reporter, p.contains(5, 5));
3582 REPORTER_ASSERT(reporter, p.contains(5, 8));
3583 REPORTER_ASSERT(reporter, p.contains(4, 5));
3542 3584
3543 p.reset(); 3585 p.reset();
3544 p.moveTo(6, 6); 3586 const SkPoint qPts[] = {{6, 6}, {8, 8}, {6, 8}, {4, 8}, {4, 6}, {4, 4}, {6, 6}};
3545 p.quadTo(8, 8, 6, 8); 3587 p.moveTo(qPts[0]);
3546 p.quadTo(4, 8, 4, 6); 3588 for (int index = 1; index < (int) SK_ARRAY_COUNT(qPts); index += 2) {
3547 p.quadTo(4, 4, 6, 6); 3589 p.quadTo(qPts[index], qPts[index + 1]);
3590 }
3548 REPORTER_ASSERT(reporter, p.contains(5, 6)); 3591 REPORTER_ASSERT(reporter, p.contains(5, 6));
3549 REPORTER_ASSERT(reporter, !p.contains(6, 5)); 3592 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3593 // test quad edge
3594 SkPoint halfway;
3595 for (int index = 0; index < (int) SK_ARRAY_COUNT(qPts) - 2; index += 2) {
3596 SkEvalQuadAt(&qPts[index], 0.5f, &halfway, nullptr);
3597 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY));
3598 }
3550 3599
3551 #define CONIC_CONTAINS_BUG_FIXED 0 3600 // test conics
3552 #if CONIC_CONTAINS_BUG_FIXED
3553 p.reset(); 3601 p.reset();
3554 p.moveTo(4, 4); 3602 const SkPoint kPts[] = {{4, 4}, {6, 6}, {8, 8}, {6, 8}, {4, 8}, {4, 6}, {4, 4}};
3555 p.conicTo(6, 6, 8, 8, 0.5f); 3603 p.moveTo(kPts[0]);
3556 p.conicTo(6, 8, 4, 8, 0.5f); 3604 for (int index = 1; index < (int) SK_ARRAY_COUNT(kPts); index += 2) {
3557 p.conicTo(4, 6, 4, 4, 0.5f); 3605 p.conicTo(kPts[index], kPts[index + 1], 0.5f);
3606 }
3558 REPORTER_ASSERT(reporter, p.contains(5, 6)); 3607 REPORTER_ASSERT(reporter, p.contains(5, 6));
3559 REPORTER_ASSERT(reporter, !p.contains(6, 5)); 3608 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3560 #endif 3609 // test conic edge
3610 for (int index = 0; index < (int) SK_ARRAY_COUNT(kPts) - 2; index += 2) {
3611 SkConic conic(&kPts[index], 0.5f);
3612 halfway = conic.evalAt(0.5f);
3613 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY));
3614 }
3561 3615
3562 // test cubics 3616 // test cubics
3563 SkPoint pts[] = {{5, 4}, {6, 5}, {7, 6}, {6, 6}, {4, 6}, {5, 7}, {5, 5}, {5, 4}, {6, 5}, {7, 6}}; 3617 SkPoint pts[] = {{5, 4}, {6, 5}, {7, 6}, {6, 6}, {4, 6}, {5, 7}, {5, 5}, {5, 4}, {6, 5}, {7, 6}};
3564 for (int i = 0; i < 3; ++i) { 3618 for (int i = 0; i < 3; ++i) {
3565 p.reset(); 3619 p.reset();
3566 p.setFillType(SkPath::kEvenOdd_FillType); 3620 p.setFillType(SkPath::kEvenOdd_FillType);
3567 p.moveTo(pts[i].fX, pts[i].fY); 3621 p.moveTo(pts[i].fX, pts[i].fY);
3568 p.cubicTo(pts[i + 1].fX, pts[i + 1].fY, pts[i + 2].fX, pts[i + 2].fY, pt s[i + 3].fX, pts[i + 3].fY); 3622 p.cubicTo(pts[i + 1].fX, pts[i + 1].fY, pts[i + 2].fX, pts[i + 2].fY, pt s[i + 3].fX, pts[i + 3].fY);
3569 p.cubicTo(pts[i + 4].fX, pts[i + 4].fY, pts[i + 5].fX, pts[i + 5].fY, pt s[i + 6].fX, pts[i + 6].fY); 3623 p.cubicTo(pts[i + 4].fX, pts[i + 4].fY, pts[i + 5].fX, pts[i + 5].fY, pt s[i + 6].fX, pts[i + 6].fY);
3570 p.close(); 3624 p.close();
3571 REPORTER_ASSERT(reporter, p.contains(5.5f, 5.5f)); 3625 REPORTER_ASSERT(reporter, p.contains(5.5f, 5.5f));
3572 REPORTER_ASSERT(reporter, !p.contains(4.5f, 5.5f)); 3626 REPORTER_ASSERT(reporter, !p.contains(4.5f, 5.5f));
3627 // test cubic edge
3628 SkEvalCubicAt(&pts[i], 0.5f, &halfway, nullptr, nullptr);
3629 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY));
3630 SkEvalCubicAt(&pts[i + 3], 0.5f, &halfway, nullptr, nullptr);
3631 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY));
3573 } 3632 }
3574 } 3633 }
3575 3634
3576 class PathRefTest_Private { 3635 class PathRefTest_Private {
3577 public: 3636 public:
3578 static void TestPathRef(skiatest::Reporter* reporter) { 3637 static void TestPathRef(skiatest::Reporter* reporter) {
3579 static const int kRepeatCnt = 10; 3638 static const int kRepeatCnt = 10;
3580 3639
3581 SkAutoTUnref<SkPathRef> pathRef(new SkPathRef); 3640 SkAutoTUnref<SkPathRef> pathRef(new SkPathRef);
3582 3641
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
3789 SkPath q; 3848 SkPath q;
3790 q.moveTo(10, 10); 3849 q.moveTo(10, 10);
3791 SkPathPriv::AddGenIDChangeListener(q, new ChangeListener(&changed)); 3850 SkPathPriv::AddGenIDChangeListener(q, new ChangeListener(&changed));
3792 REPORTER_ASSERT(reporter, !changed); 3851 REPORTER_ASSERT(reporter, !changed);
3793 } 3852 }
3794 // q went out of scope. 3853 // q went out of scope.
3795 REPORTER_ASSERT(reporter, changed); 3854 REPORTER_ASSERT(reporter, changed);
3796 } 3855 }
3797 }; 3856 };
3798 3857
3858 DEF_TEST(PathContains, reporter) {
3859 test_contains(reporter);
3860 }
3861
3799 DEF_TEST(Paths, reporter) { 3862 DEF_TEST(Paths, reporter) {
3800 test_path_crbug364224(); 3863 test_path_crbug364224();
3801 3864
3802 SkTSize<SkScalar>::Make(3,4); 3865 SkTSize<SkScalar>::Make(3,4);
3803 3866
3804 SkPath p, empty; 3867 SkPath p, empty;
3805 SkRect bounds, bounds2; 3868 SkRect bounds, bounds2;
3806 test_empty(reporter, p); 3869 test_empty(reporter, p);
3807 3870
3808 REPORTER_ASSERT(reporter, p.getBounds().isEmpty()); 3871 REPORTER_ASSERT(reporter, p.getBounds().isEmpty());
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
3941 PathTest_Private::TestPathTo(reporter); 4004 PathTest_Private::TestPathTo(reporter);
3942 PathRefTest_Private::TestPathRef(reporter); 4005 PathRefTest_Private::TestPathRef(reporter);
3943 PathTest_Private::TestPathrefListeners(reporter); 4006 PathTest_Private::TestPathrefListeners(reporter);
3944 test_dump(reporter); 4007 test_dump(reporter);
3945 test_path_crbug389050(reporter); 4008 test_path_crbug389050(reporter);
3946 test_path_crbugskia2820(reporter); 4009 test_path_crbugskia2820(reporter);
3947 test_skbug_3469(reporter); 4010 test_skbug_3469(reporter);
3948 test_skbug_3239(reporter); 4011 test_skbug_3239(reporter);
3949 test_bounds_crbug_513799(reporter); 4012 test_bounds_crbug_513799(reporter);
3950 } 4013 }
OLDNEW
« no previous file with comments | « src/core/SkPath.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698