1 /*
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 */
7 #include "include/core/SkTypes.h"
8 #include "src/pathops/SkPathOpsCubic.h"
9 #include "src/pathops/SkPathOpsPoint.h"
10 #include "src/pathops/SkPathOpsQuad.h"
11 #include "src/pathops/SkPathOpsRect.h"
12 #include "tests/PathOpsTestCommon.h"
13 #include "tests/Test.h"
14
15 #include <array>
16 #include <cstddef>
17
18 static const QuadPts quadTests[] = {
19 {{{1, 1}, {2, 1}, {0, 2}}},
20 {{{0, 0}, {1, 1}, {3, 1}}},
21 {{{2, 0}, {1, 1}, {2, 2}}},
22 {{{4, 0}, {0, 1}, {4, 2}}},
23 {{{0, 0}, {0, 1}, {1, 1}}},
24 };
25
26 static const CubicPts cubicTests[] = {
27 {{{2, 0}, {3, 1}, {2, 2}, {1, 1}}},
28 {{{3, 1}, {2, 2}, {1, 1}, {2, 0}}},
29 {{{3, 0}, {2, 1}, {3, 2}, {1, 1}}},
30 };
31
32 static const size_t quadTests_count = std::size(quadTests);
33 static const size_t cubicTests_count = std::size(cubicTests);
34
setRawBounds(const SkDQuad & quad,SkDRect * rect)35 static void setRawBounds(const SkDQuad& quad, SkDRect* rect) {
36 rect->set(quad[0]);
37 rect->add(quad[1]);
38 rect->add(quad[2]);
39 }
40
setRawBounds(const SkDCubic & cubic,SkDRect * rect)41 static void setRawBounds(const SkDCubic& cubic, SkDRect* rect) {
42 rect->set(cubic[0]);
43 rect->add(cubic[1]);
44 rect->add(cubic[2]);
45 rect->add(cubic[3]);
46 }
47
DEF_TEST(PathOpsDRect,reporter)48 DEF_TEST(PathOpsDRect, reporter) {
49 size_t index;
50 SkDRect rect, rect2;
51 for (index = 0; index < quadTests_count; ++index) {
52 const QuadPts& q = quadTests[index];
53 SkDQuad quad;
54 quad.debugSet(q.fPts);
55 SkASSERT(ValidQuad(quad));
56 setRawBounds(quad, &rect);
57 rect2.setBounds(quad);
58 REPORTER_ASSERT(reporter, rect.intersects(rect2));
59 // FIXME: add a recursive box subdivision method to verify that tight bounds is correct
60 SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
61 REPORTER_ASSERT(reporter, rect.contains(leftTop));
62 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
63 REPORTER_ASSERT(reporter, rect.contains(rightBottom));
64 }
65 for (index = 0; index < cubicTests_count; ++index) {
66 const CubicPts& c = cubicTests[index];
67 SkDCubic cubic;
68 cubic.debugSet(c.fPts);
69 SkASSERT(ValidCubic(cubic));
70 setRawBounds(cubic, &rect);
71 rect2.setBounds(cubic);
72 REPORTER_ASSERT(reporter, rect.intersects(rect2));
73 // FIXME: add a recursive box subdivision method to verify that tight bounds is correct
74 SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
75 REPORTER_ASSERT(reporter, rect.contains(leftTop));
76 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
77 REPORTER_ASSERT(reporter, rect.contains(rightBottom));
78 }
79 }
80