blob: 21c5f2a34c465d6063cba1d327c7990224ae5e3e [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 "SkPathOpsCubic.h"
9#include "SkPathOpsLine.h"
10#include "SkPathOpsQuad.h"
11#include "SkPathOpsRect.h"
12#include "Test.h"
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000013#include "TestClassDef.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +000014
15static const SkDLine lineTests[] = {
16 {{{2, 1}, {2, 1}}},
17 {{{2, 1}, {1, 1}}},
18 {{{2, 1}, {2, 2}}},
19 {{{1, 1}, {2, 2}}},
20 {{{3, 0}, {2, 1}}},
21 {{{3, 2}, {1, 1}}},
22};
23
24static const SkDQuad quadTests[] = {
25 {{{1, 1}, {2, 1}, {0, 2}}},
26 {{{0, 0}, {1, 1}, {3, 1}}},
27 {{{2, 0}, {1, 1}, {2, 2}}},
28 {{{4, 0}, {0, 1}, {4, 2}}},
29 {{{0, 0}, {0, 1}, {1, 1}}},
30};
31
32static const SkDCubic cubicTests[] = {
33 {{{2, 0}, {3, 1}, {2, 2}, {1, 1}}},
34 {{{3, 1}, {2, 2}, {1, 1}, {2, 0}}},
35 {{{3, 0}, {2, 1}, {3, 2}, {1, 1}}},
36};
37
caryclark@google.comad65a3e2013-04-15 19:13:59 +000038static const size_t lineTests_count = SK_ARRAY_COUNT(lineTests);
39static const size_t quadTests_count = SK_ARRAY_COUNT(quadTests);
40static const size_t cubicTests_count = SK_ARRAY_COUNT(cubicTests);
caryclark@google.com07393ca2013-04-08 11:47:37 +000041
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000042DEF_TEST(PathOpsDRect, reporter) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000043 size_t index;
44 SkDRect rect, rect2;
45 for (index = 0; index < lineTests_count; ++index) {
46 const SkDLine& line = lineTests[index];
caryclark@google.com8d0a5242013-07-16 16:11:16 +000047 SkASSERT(ValidLine(line));
caryclark@google.com07393ca2013-04-08 11:47:37 +000048 rect.setBounds(line);
caryclark@google.com3b97af52013-04-23 11:56:44 +000049 REPORTER_ASSERT(reporter, rect.fLeft == SkTMin(line[0].fX, line[1].fX));
50 REPORTER_ASSERT(reporter, rect.fTop == SkTMin(line[0].fY, line[1].fY));
51 REPORTER_ASSERT(reporter, rect.fRight == SkTMax(line[0].fX, line[1].fX));
52 REPORTER_ASSERT(reporter, rect.fBottom == SkTMax(line[0].fY, line[1].fY));
caryclark@google.com07393ca2013-04-08 11:47:37 +000053 rect2.set(line[0]);
54 rect2.add(line[1]);
caryclark@google.com3b97af52013-04-23 11:56:44 +000055 REPORTER_ASSERT(reporter, rect2.fLeft == SkTMin(line[0].fX, line[1].fX));
56 REPORTER_ASSERT(reporter, rect2.fTop == SkTMin(line[0].fY, line[1].fY));
57 REPORTER_ASSERT(reporter, rect2.fRight == SkTMax(line[0].fX, line[1].fX));
58 REPORTER_ASSERT(reporter, rect2.fBottom == SkTMax(line[0].fY, line[1].fY));
caryclark@google.com07393ca2013-04-08 11:47:37 +000059 REPORTER_ASSERT(reporter, rect.contains(line[0]));
60 REPORTER_ASSERT(reporter, rect.intersects(&rect2));
61 }
62 for (index = 0; index < quadTests_count; ++index) {
63 const SkDQuad& quad = quadTests[index];
caryclark@google.com8d0a5242013-07-16 16:11:16 +000064 SkASSERT(ValidQuad(quad));
caryclark@google.com07393ca2013-04-08 11:47:37 +000065 rect.setRawBounds(quad);
caryclark@google.com3b97af52013-04-23 11:56:44 +000066 REPORTER_ASSERT(reporter, rect.fLeft == SkTMin(quad[0].fX,
67 SkTMin(quad[1].fX, quad[2].fX)));
68 REPORTER_ASSERT(reporter, rect.fTop == SkTMin(quad[0].fY,
69 SkTMin(quad[1].fY, quad[2].fY)));
70 REPORTER_ASSERT(reporter, rect.fRight == SkTMax(quad[0].fX,
71 SkTMax(quad[1].fX, quad[2].fX)));
72 REPORTER_ASSERT(reporter, rect.fBottom == SkTMax(quad[0].fY,
73 SkTMax(quad[1].fY, quad[2].fY)));
caryclark@google.com07393ca2013-04-08 11:47:37 +000074 rect2.setBounds(quad);
75 REPORTER_ASSERT(reporter, rect.intersects(&rect2));
76 // FIXME: add a recursive box subdivision method to verify that tight bounds is correct
77 SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
78 REPORTER_ASSERT(reporter, rect.contains(leftTop));
79 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
80 REPORTER_ASSERT(reporter, rect.contains(rightBottom));
81 }
82 for (index = 0; index < cubicTests_count; ++index) {
83 const SkDCubic& cubic = cubicTests[index];
caryclark@google.com8d0a5242013-07-16 16:11:16 +000084 SkASSERT(ValidCubic(cubic));
caryclark@google.com07393ca2013-04-08 11:47:37 +000085 rect.setRawBounds(cubic);
caryclark@google.com3b97af52013-04-23 11:56:44 +000086 REPORTER_ASSERT(reporter, rect.fLeft == SkTMin(cubic[0].fX,
87 SkTMin(cubic[1].fX, SkTMin(cubic[2].fX, cubic[3].fX))));
88 REPORTER_ASSERT(reporter, rect.fTop == SkTMin(cubic[0].fY,
89 SkTMin(cubic[1].fY, SkTMin(cubic[2].fY, cubic[3].fY))));
90 REPORTER_ASSERT(reporter, rect.fRight == SkTMax(cubic[0].fX,
91 SkTMax(cubic[1].fX, SkTMax(cubic[2].fX, cubic[3].fX))));
92 REPORTER_ASSERT(reporter, rect.fBottom == SkTMax(cubic[0].fY,
93 SkTMax(cubic[1].fY, SkTMax(cubic[2].fY, cubic[3].fY))));
caryclark@google.com07393ca2013-04-08 11:47:37 +000094 rect2.setBounds(cubic);
95 REPORTER_ASSERT(reporter, rect.intersects(&rect2));
96 // FIXME: add a recursive box subdivision method to verify that tight bounds is correct
97 SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
98 REPORTER_ASSERT(reporter, rect.contains(leftTop));
99 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
100 REPORTER_ASSERT(reporter, rect.contains(rightBottom));
101 }
102}