From bad1b2ff1d34ff86693b776f89d7b46995746127 Mon Sep 17 00:00:00 2001 From: "mike@reedtribe.org" Date: Wed, 11 Jul 2012 01:51:33 +0000 Subject: add SkPath::contains(x, y) git-svn-id: http://skia.googlecode.com/svn/trunk@4526 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gm/hittestpath.cpp | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'gm/hittestpath.cpp') diff --git a/gm/hittestpath.cpp b/gm/hittestpath.cpp index 06f89e4dd2..83f3507da1 100644 --- a/gm/hittestpath.cpp +++ b/gm/hittestpath.cpp @@ -10,7 +10,7 @@ #include "SkCullPoints.h" #include "SkRandom.h" -static void test_hittest(SkCanvas* canvas, const SkPath& path, bool hires) { +static void test_hittest(SkCanvas* canvas, const SkPath& path) { SkPaint paint; SkRect r = path.getBounds(); @@ -22,14 +22,8 @@ static void test_hittest(SkCanvas* canvas, const SkPath& path, bool hires) { paint.setColor(0x800000FF); for (SkScalar y = r.fTop + SK_ScalarHalf - MARGIN; y < r.fBottom + MARGIN; y += SK_Scalar1) { for (SkScalar x = r.fLeft + SK_ScalarHalf - MARGIN; x < r.fRight + MARGIN; x += SK_Scalar1) { - if (hires) { - if (SkHitTestPathEx(path, x, y)) { - canvas->drawPoint(x, y, paint); - } - } else { - if (SkHitTestPath(path, x, y, false)) { - canvas->drawPoint(x, y, paint); - } + if (path.contains(x, y)) { + canvas->drawPoint(x, y, paint); } } } @@ -50,25 +44,25 @@ protected: SkPath path; SkRandom rand; - for (int i = 0; i < 5; ++i) { - path.lineTo(rand.nextUScalar1() * 150, rand.nextUScalar1() * 150); - path.quadTo(rand.nextUScalar1() * 150, rand.nextUScalar1() * 150, - rand.nextUScalar1() * 150, rand.nextUScalar1() * 150); + int scale = 300; + for (int i = 0; i < 4; ++i) { + path.lineTo(rand.nextUScalar1() * scale, rand.nextUScalar1() * scale); + path.quadTo(rand.nextUScalar1() * scale, rand.nextUScalar1() * scale, + rand.nextUScalar1() * scale, rand.nextUScalar1() * scale); + path.cubicTo(rand.nextUScalar1() * scale, rand.nextUScalar1() * scale, + rand.nextUScalar1() * scale, rand.nextUScalar1() * scale, + rand.nextUScalar1() * scale, rand.nextUScalar1() * scale); } path.setFillType(SkPath::kEvenOdd_FillType); path.offset(SkIntToScalar(20), SkIntToScalar(20)); - test_hittest(canvas, path, false); - canvas->translate(SkIntToScalar(200), 0); - test_hittest(canvas, path, true); - - canvas->translate(-SkIntToScalar(200), SkIntToScalar(200)); + test_hittest(canvas, path); + + canvas->translate(SkIntToScalar(scale), 0); path.setFillType(SkPath::kWinding_FillType); - test_hittest(canvas, path, false); - canvas->translate(SkIntToScalar(200), 0); - test_hittest(canvas, path, true); + test_hittest(canvas, path); } private: -- cgit v1.2.3