blob: 0e813d2a8ee02ef15cb1ed0e953af7700326341b [file] [log] [blame]
caryclark@google.com07393ca2013-04-08 11:47:37 +00001/*
2 * Copyright 2013 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 "SkPathOpsBounds.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 SkRect sectTests[][2] = {
13 {{2, 0, 4, 1}, {4, 0, 6, 1}},
14 {{2, 0, 4, 1}, {3, 0, 5, 1}},
15 {{2, 0, 4, 1}, {3, 0, 5, 0}},
16 {{2, 0, 4, 1}, {3, 1, 5, 2}},
17 {{2, 1, 4, 2}, {1, 0, 5, 3}},
18 {{2, 1, 5, 3}, {3, 1, 4, 2}},
19 {{2, 0, 4, 1}, {3, 0, 3, 0}}, // intersecting an empty bounds is OK
20 {{2, 0, 4, 1}, {4, 1, 5, 2}}, // touching just on a corner is OK
21};
22
caryclark@google.comad65a3e2013-04-15 19:13:59 +000023static const size_t sectTestsCount = SK_ARRAY_COUNT(sectTests);
caryclark@google.com07393ca2013-04-08 11:47:37 +000024
25static const SkRect noSectTests[][2] = {
26 {{2, 0, 4, 1}, {5, 0, 6, 1}},
27 {{2, 0, 4, 1}, {3, 2, 5, 2}},
28};
29
caryclark@google.comad65a3e2013-04-15 19:13:59 +000030static const size_t noSectTestsCount = SK_ARRAY_COUNT(noSectTests);
caryclark@google.com07393ca2013-04-08 11:47:37 +000031
32static const SkRect reallyEmpty[] = {
33 {0, 0, 0, 0},
34 {1, 1, 1, 0},
35 {1, 1, 0, 1},
36 {1, 1, 0, 0},
37 {1, 2, 3, SK_ScalarNaN},
38};
39
caryclark@google.comad65a3e2013-04-15 19:13:59 +000040static const size_t emptyTestsCount = SK_ARRAY_COUNT(reallyEmpty);
caryclark@google.com07393ca2013-04-08 11:47:37 +000041
42static const SkRect notReallyEmpty[] = {
43 {0, 0, 1, 0},
44 {0, 0, 0, 1},
45 {0, 0, 1, 1},
46};
47
caryclark@google.comad65a3e2013-04-15 19:13:59 +000048static const size_t notEmptyTestsCount = SK_ARRAY_COUNT(notReallyEmpty);
caryclark@google.com07393ca2013-04-08 11:47:37 +000049
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000050DEF_TEST(PathOpsBounds, reporter) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000051 for (size_t index = 0; index < sectTestsCount; ++index) {
52 const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(sectTests[index][0]);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000053 SkASSERT(ValidBounds(bounds1));
caryclark@google.com07393ca2013-04-08 11:47:37 +000054 const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(sectTests[index][1]);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000055 SkASSERT(ValidBounds(bounds2));
caryclark@google.com07393ca2013-04-08 11:47:37 +000056 bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2);
57 REPORTER_ASSERT(reporter, touches);
58 }
59 for (size_t index = 0; index < noSectTestsCount; ++index) {
60 const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(noSectTests[index][0]);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000061 SkASSERT(ValidBounds(bounds1));
caryclark@google.com07393ca2013-04-08 11:47:37 +000062 const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(noSectTests[index][1]);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000063 SkASSERT(ValidBounds(bounds2));
caryclark@google.com07393ca2013-04-08 11:47:37 +000064 bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2);
65 REPORTER_ASSERT(reporter, !touches);
66 }
67 SkPathOpsBounds bounds;
68 bounds.setEmpty();
69 bounds.add(1, 2, 3, 4);
70 SkPathOpsBounds expected;
71 expected.set(0, 0, 3, 4);
72 REPORTER_ASSERT(reporter, bounds == expected);
73 bounds.setEmpty();
74 SkPathOpsBounds ordinal;
75 ordinal.set(1, 2, 3, 4);
76 bounds.add(ordinal);
77 REPORTER_ASSERT(reporter, bounds == expected);
78 SkPoint topLeft = {0, 0};
79 bounds.setPointBounds(topLeft);
80 SkPoint botRight = {3, 4};
81 bounds.add(botRight);
82 REPORTER_ASSERT(reporter, bounds == expected);
83 for (size_t index = 0; index < emptyTestsCount; ++index) {
84 const SkPathOpsBounds& bounds = static_cast<const SkPathOpsBounds&>(reallyEmpty[index]);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000085 // SkASSERT(ValidBounds(bounds)); // don't check because test may contain nan
caryclark@google.com07393ca2013-04-08 11:47:37 +000086 bool empty = bounds.isReallyEmpty();
87 REPORTER_ASSERT(reporter, empty);
88 }
89 for (size_t index = 0; index < notEmptyTestsCount; ++index) {
90 const SkPathOpsBounds& bounds = static_cast<const SkPathOpsBounds&>(notReallyEmpty[index]);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000091 SkASSERT(ValidBounds(bounds));
caryclark@google.com07393ca2013-04-08 11:47:37 +000092 bool empty = bounds.isReallyEmpty();
93 REPORTER_ASSERT(reporter, !empty);
94 }
95 const SkPoint curvePts[] = {{0, 0}, {1, 2}, {3, 4}, {5, 6}};
96 bounds.setLineBounds(curvePts);
97 expected.set(0, 0, 1, 2);
98 REPORTER_ASSERT(reporter, bounds == expected);
99 (bounds.*SetCurveBounds[1])(curvePts);
100 REPORTER_ASSERT(reporter, bounds == expected);
101 bounds.setQuadBounds(curvePts);
102 expected.set(0, 0, 3, 4);
103 REPORTER_ASSERT(reporter, bounds == expected);
104 (bounds.*SetCurveBounds[2])(curvePts);
105 REPORTER_ASSERT(reporter, bounds == expected);
106 bounds.setCubicBounds(curvePts);
107 expected.set(0, 0, 5, 6);
108 REPORTER_ASSERT(reporter, bounds == expected);
109 (bounds.*SetCurveBounds[3])(curvePts);
110 REPORTER_ASSERT(reporter, bounds == expected);
111}