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

Side by Side Diff: tests/PathTest.cpp

Issue 1532003004: fix bugs in path contains (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
« src/core/SkPath.cpp ('K') | « 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 "SkGeometry.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
(...skipping 3573 matching lines...) Expand 10 before | Expand all | Expand 10 after
3584 p.moveTo(4, 4); 3584 p.moveTo(4, 4);
3585 p.quadTo(6, 6, 8, 8); 3585 p.quadTo(6, 6, 8, 8);
3586 p.quadTo(6, 8, 4, 8); 3586 p.quadTo(6, 8, 4, 8);
3587 p.quadTo(4, 6, 4, 4); 3587 p.quadTo(4, 6, 4, 4);
3588 REPORTER_ASSERT(reporter, p.contains(5, 6)); 3588 REPORTER_ASSERT(reporter, p.contains(5, 6));
3589 REPORTER_ASSERT(reporter, !p.contains(6, 5)); 3589 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3590 // test quad edge 3590 // test quad edge
3591 REPORTER_ASSERT(reporter, p.contains(5, 5)); 3591 REPORTER_ASSERT(reporter, p.contains(5, 5));
3592 REPORTER_ASSERT(reporter, p.contains(5, 8)); 3592 REPORTER_ASSERT(reporter, p.contains(5, 8));
3593 REPORTER_ASSERT(reporter, p.contains(4, 5)); 3593 REPORTER_ASSERT(reporter, p.contains(4, 5));
3594 // test quad endpoints
3595 REPORTER_ASSERT(reporter, p.contains(4, 4));
3596 REPORTER_ASSERT(reporter, p.contains(8, 8));
3597 REPORTER_ASSERT(reporter, p.contains(4, 8));
3594 3598
3595 p.reset(); 3599 p.reset();
3596 const SkPoint qPts[] = {{6, 6}, {8, 8}, {6, 8}, {4, 8}, {4, 6}, {4, 4}, {6, 6}}; 3600 const SkPoint qPts[] = {{6, 6}, {8, 8}, {6, 8}, {4, 8}, {4, 6}, {4, 4}, {6, 6}};
3597 p.moveTo(qPts[0]); 3601 p.moveTo(qPts[0]);
3598 for (int index = 1; index < (int) SK_ARRAY_COUNT(qPts); index += 2) { 3602 for (int index = 1; index < (int) SK_ARRAY_COUNT(qPts); index += 2) {
3599 p.quadTo(qPts[index], qPts[index + 1]); 3603 p.quadTo(qPts[index], qPts[index + 1]);
3600 } 3604 }
3601 REPORTER_ASSERT(reporter, p.contains(5, 6)); 3605 REPORTER_ASSERT(reporter, p.contains(5, 6));
3602 REPORTER_ASSERT(reporter, !p.contains(6, 5)); 3606 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3603 // test quad edge 3607 // test quad edge
(...skipping 11 matching lines...) Expand all
3615 p.conicTo(kPts[index], kPts[index + 1], 0.5f); 3619 p.conicTo(kPts[index], kPts[index + 1], 0.5f);
3616 } 3620 }
3617 REPORTER_ASSERT(reporter, p.contains(5, 6)); 3621 REPORTER_ASSERT(reporter, p.contains(5, 6));
3618 REPORTER_ASSERT(reporter, !p.contains(6, 5)); 3622 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3619 // test conic edge 3623 // test conic edge
3620 for (int index = 0; index < (int) SK_ARRAY_COUNT(kPts) - 2; index += 2) { 3624 for (int index = 0; index < (int) SK_ARRAY_COUNT(kPts) - 2; index += 2) {
3621 SkConic conic(&kPts[index], 0.5f); 3625 SkConic conic(&kPts[index], 0.5f);
3622 halfway = conic.evalAt(0.5f); 3626 halfway = conic.evalAt(0.5f);
3623 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY)); 3627 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY));
3624 } 3628 }
3629 // test conic end points
3630 REPORTER_ASSERT(reporter, p.contains(4, 4));
3631 REPORTER_ASSERT(reporter, p.contains(8, 8));
3632 REPORTER_ASSERT(reporter, p.contains(4, 8));
3625 3633
3626 // test cubics 3634 // test cubics
3627 SkPoint pts[] = {{5, 4}, {6, 5}, {7, 6}, {6, 6}, {4, 6}, {5, 7}, {5, 5}, {5, 4}, {6, 5}, {7, 6}}; 3635 SkPoint pts[] = {{5, 4}, {6, 5}, {7, 6}, {6, 6}, {4, 6}, {5, 7}, {5, 5}, {5, 4}, {6, 5}, {7, 6}};
3628 for (int i = 0; i < 3; ++i) { 3636 for (int i = 0; i < 3; ++i) {
3629 p.reset(); 3637 p.reset();
3630 p.setFillType(SkPath::kEvenOdd_FillType); 3638 p.setFillType(SkPath::kEvenOdd_FillType);
3631 p.moveTo(pts[i].fX, pts[i].fY); 3639 p.moveTo(pts[i].fX, pts[i].fY);
3632 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); 3640 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);
3633 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); 3641 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);
3634 p.close(); 3642 p.close();
3635 REPORTER_ASSERT(reporter, p.contains(5.5f, 5.5f)); 3643 REPORTER_ASSERT(reporter, p.contains(5.5f, 5.5f));
3636 REPORTER_ASSERT(reporter, !p.contains(4.5f, 5.5f)); 3644 REPORTER_ASSERT(reporter, !p.contains(4.5f, 5.5f));
3637 // test cubic edge 3645 // test cubic edge
3638 SkEvalCubicAt(&pts[i], 0.5f, &halfway, nullptr, nullptr); 3646 SkEvalCubicAt(&pts[i], 0.5f, &halfway, nullptr, nullptr);
3639 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY)); 3647 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY));
3640 SkEvalCubicAt(&pts[i + 3], 0.5f, &halfway, nullptr, nullptr); 3648 SkEvalCubicAt(&pts[i + 3], 0.5f, &halfway, nullptr, nullptr);
3641 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY)); 3649 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY));
3650 // test cubic end points
3651 REPORTER_ASSERT(reporter, p.contains(pts[i].fX, pts[i].fY));
3652 REPORTER_ASSERT(reporter, p.contains(pts[i + 3].fX, pts[i + 3].fY));
3653 REPORTER_ASSERT(reporter, p.contains(pts[i + 6].fX, pts[i + 6].fY));
3642 } 3654 }
3643 } 3655 }
3644 3656
3645 class PathRefTest_Private { 3657 class PathRefTest_Private {
3646 public: 3658 public:
3647 static void TestPathRef(skiatest::Reporter* reporter) { 3659 static void TestPathRef(skiatest::Reporter* reporter) {
3648 static const int kRepeatCnt = 10; 3660 static const int kRepeatCnt = 10;
3649 3661
3650 SkAutoTUnref<SkPathRef> pathRef(new SkPathRef); 3662 SkAutoTUnref<SkPathRef> pathRef(new SkPathRef);
3651 3663
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
4014 PathTest_Private::TestPathTo(reporter); 4026 PathTest_Private::TestPathTo(reporter);
4015 PathRefTest_Private::TestPathRef(reporter); 4027 PathRefTest_Private::TestPathRef(reporter);
4016 PathTest_Private::TestPathrefListeners(reporter); 4028 PathTest_Private::TestPathrefListeners(reporter);
4017 test_dump(reporter); 4029 test_dump(reporter);
4018 test_path_crbug389050(reporter); 4030 test_path_crbug389050(reporter);
4019 test_path_crbugskia2820(reporter); 4031 test_path_crbugskia2820(reporter);
4020 test_skbug_3469(reporter); 4032 test_skbug_3469(reporter);
4021 test_skbug_3239(reporter); 4033 test_skbug_3239(reporter);
4022 test_bounds_crbug_513799(reporter); 4034 test_bounds_crbug_513799(reporter);
4023 } 4035 }
OLDNEW
« src/core/SkPath.cpp ('K') | « src/core/SkPath.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698