blob: 573a0cecf9b04e3d77b285ad1b82a9f5cea778ce [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"
caryclarkaec25102015-04-29 08:28:30 -07009#include "SkPathOpsCurve.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +000010#include "Test.h"
11
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
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000032DEF_TEST(PathOpsBounds, reporter) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000033 for (size_t index = 0; index < sectTestsCount; ++index) {
34 const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(sectTests[index][0]);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000035 SkASSERT(ValidBounds(bounds1));
caryclark@google.com07393ca2013-04-08 11:47:37 +000036 const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(sectTests[index][1]);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000037 SkASSERT(ValidBounds(bounds2));
caryclark@google.com07393ca2013-04-08 11:47:37 +000038 bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2);
39 REPORTER_ASSERT(reporter, touches);
40 }
41 for (size_t index = 0; index < noSectTestsCount; ++index) {
42 const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(noSectTests[index][0]);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000043 SkASSERT(ValidBounds(bounds1));
caryclark@google.com07393ca2013-04-08 11:47:37 +000044 const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(noSectTests[index][1]);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000045 SkASSERT(ValidBounds(bounds2));
caryclark@google.com07393ca2013-04-08 11:47:37 +000046 bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2);
47 REPORTER_ASSERT(reporter, !touches);
48 }
49 SkPathOpsBounds bounds;
50 bounds.setEmpty();
51 bounds.add(1, 2, 3, 4);
52 SkPathOpsBounds expected;
53 expected.set(0, 0, 3, 4);
54 REPORTER_ASSERT(reporter, bounds == expected);
55 bounds.setEmpty();
56 SkPathOpsBounds ordinal;
57 ordinal.set(1, 2, 3, 4);
58 bounds.add(ordinal);
59 REPORTER_ASSERT(reporter, bounds == expected);
caryclark624637c2015-05-11 07:21:27 -070060 bounds.setEmpty();
caryclarkaec25102015-04-29 08:28:30 -070061 SkDPoint botRight = {3, 4};
caryclark@google.com07393ca2013-04-08 11:47:37 +000062 bounds.add(botRight);
63 REPORTER_ASSERT(reporter, bounds == expected);
caryclark@google.com07393ca2013-04-08 11:47:37 +000064 const SkPoint curvePts[] = {{0, 0}, {1, 2}, {3, 4}, {5, 6}};
caryclarkaec25102015-04-29 08:28:30 -070065 SkDCurve curve;
caryclarkaec25102015-04-29 08:28:30 -070066 curve.fQuad.set(curvePts);
67 curve.setQuadBounds(curvePts, 1, 0, 1, &bounds);
caryclark@google.com07393ca2013-04-08 11:47:37 +000068 expected.set(0, 0, 3, 4);
69 REPORTER_ASSERT(reporter, bounds == expected);
caryclarkaec25102015-04-29 08:28:30 -070070 curve.fCubic.set(curvePts);
71 curve.setCubicBounds(curvePts, 1, 0, 1, &bounds);
caryclark@google.com07393ca2013-04-08 11:47:37 +000072 expected.set(0, 0, 5, 6);
73 REPORTER_ASSERT(reporter, bounds == expected);
caryclark@google.com07393ca2013-04-08 11:47:37 +000074}