2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
13 static void test_hittest(SkCanvas* canvas, const SkPath& path) {
15 SkRect r = path.getBounds();
17 paint.setColor(SK_ColorRED);
18 canvas->drawPath(path, paint);
20 const SkScalar MARGIN = SkIntToScalar(4);
22 paint.setColor(0x800000FF);
23 for (SkScalar y = r.fTop + SK_ScalarHalf - MARGIN; y < r.fBottom + MARGIN; y += SK_Scalar1) {
24 for (SkScalar x = r.fLeft + SK_ScalarHalf - MARGIN; x < r.fRight + MARGIN; x += SK_Scalar1) {
25 if (path.contains(x, y)) {
26 canvas->drawPoint(x, y, paint);
32 DEF_SIMPLE_GM(hittestpath, canvas, 700, 460) {
37 for (int i = 0; i < 4; ++i) {
38 // get the random values deterministically
40 for (int index = 0; index < (int) SK_ARRAY_COUNT(randoms); ++index) {
41 randoms[index] = rand.nextUScalar1();
43 path.lineTo(randoms[0] * scale, randoms[1] * scale);
44 path.quadTo(randoms[2] * scale, randoms[3] * scale,
45 randoms[4] * scale, randoms[5] * scale);
46 path.cubicTo(randoms[6] * scale, randoms[7] * scale,
47 randoms[8] * scale, randoms[9] * scale,
48 randoms[10] * scale, randoms[11] * scale);
51 path.setFillType(SkPath::kEvenOdd_FillType);
52 path.offset(SkIntToScalar(20), SkIntToScalar(20));
54 test_hittest(canvas, path);
56 canvas->translate(SkIntToScalar(scale), 0);
57 path.setFillType(SkPath::kWinding_FillType);
59 test_hittest(canvas, path);