blob: 1a06287c2f7e05b54f4be299337b59abb159066e [file] [log] [blame]
caryclark@google.com07393ca2013-04-08 11:47:37 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
caryclark@google.com8d0a5242013-07-16 16:11:16 +00007#include "PathOpsTestCommon.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +00008#include "SkPathOpsTriangle.h"
9#include "Test.h"
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000010#include "TestClassDef.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +000011
12static const SkDTriangle tests[] = {
13 {{{2, 0}, {3, 1}, {2, 2}}},
14 {{{3, 1}, {2, 2}, {1, 1}}},
15 {{{3, 0}, {2, 1}, {3, 2}}},
16};
17
18static const SkDPoint inPoint[] = {
19 {2.5, 1},
20 {2, 1.5},
21 {2.5, 1},
22};
23
24static const SkDPoint outPoint[] = {
25 {3, 0},
26 {2.5, 2},
27 {2.5, 2},
28};
29
caryclark@google.comad65a3e2013-04-15 19:13:59 +000030static const size_t tests_count = SK_ARRAY_COUNT(tests);
caryclark@google.com07393ca2013-04-08 11:47:37 +000031
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000032DEF_TEST(PathOpsTriangleUtilities, reporter) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000033 for (size_t index = 0; index < tests_count; ++index) {
34 const SkDTriangle& triangle = tests[index];
caryclark@google.com8d0a5242013-07-16 16:11:16 +000035 SkASSERT(ValidTriangle(triangle));
caryclark@google.com07393ca2013-04-08 11:47:37 +000036 bool result = triangle.contains(inPoint[index]);
37 if (!result) {
38 SkDebugf("%s [%d] expected point in triangle\n", __FUNCTION__, index);
39 REPORTER_ASSERT(reporter, 0);
40 }
41 result = triangle.contains(outPoint[index]);
42 if (result) {
43 SkDebugf("%s [%d] expected point outside triangle\n", __FUNCTION__, index);
44 REPORTER_ASSERT(reporter, 0);
45 }
46 }
47}
48
skia.committer@gmail.comf54ad6f2013-11-02 07:02:02 +000049static const SkDTriangle oneOff[] = {
50 {{{271.03291625750461, 5.0402503630087025e-05}, {275.21652430019037, 3.6997300650817753},
51 {279.25839233398438, 7.7416000366210938}}},
52
53 {{{271.03291625750461, 5.0402503617874572e-05}, {275.21652430019037, 3.6997300650817877},
54 {279.25839233398438, 7.7416000366210938}}}
55};
56
57static const size_t oneOff_count = SK_ARRAY_COUNT(oneOff);
58
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000059DEF_TEST(PathOpsTriangleOneOff, reporter) {
skia.committer@gmail.comf54ad6f2013-11-02 07:02:02 +000060 for (size_t index = 0; index < oneOff_count; ++index) {
61 const SkDTriangle& triangle = oneOff[index];
62 SkASSERT(ValidTriangle(triangle));
63 for (int inner = 0; inner < 3; ++inner) {
64 bool result = triangle.contains(triangle.fPts[inner]);
65 if (result) {
66 SkDebugf("%s [%d][%d] point on triangle is not in\n", __FUNCTION__, index, inner);
67 REPORTER_ASSERT(reporter, 0);
68 }
69 }
70 }
71}