1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2012 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci#include "src/pathops/SkPathOpsCubic.h"
8cb93a386Sopenharmony_ci#include "src/pathops/SkPathOpsLine.h"
9cb93a386Sopenharmony_ci#include "src/pathops/SkPathOpsQuad.h"
10cb93a386Sopenharmony_ci#include "src/pathops/SkPathOpsRect.h"
11cb93a386Sopenharmony_ci#include "tests/PathOpsTestCommon.h"
12cb93a386Sopenharmony_ci#include "tests/Test.h"
13cb93a386Sopenharmony_ci
14cb93a386Sopenharmony_cistatic const QuadPts quadTests[] = {
15cb93a386Sopenharmony_ci    {{{1, 1}, {2, 1}, {0, 2}}},
16cb93a386Sopenharmony_ci    {{{0, 0}, {1, 1}, {3, 1}}},
17cb93a386Sopenharmony_ci    {{{2, 0}, {1, 1}, {2, 2}}},
18cb93a386Sopenharmony_ci    {{{4, 0}, {0, 1}, {4, 2}}},
19cb93a386Sopenharmony_ci    {{{0, 0}, {0, 1}, {1, 1}}},
20cb93a386Sopenharmony_ci};
21cb93a386Sopenharmony_ci
22cb93a386Sopenharmony_cistatic const CubicPts cubicTests[] = {
23cb93a386Sopenharmony_ci    {{{2, 0}, {3, 1}, {2, 2}, {1, 1}}},
24cb93a386Sopenharmony_ci    {{{3, 1}, {2, 2}, {1, 1}, {2, 0}}},
25cb93a386Sopenharmony_ci    {{{3, 0}, {2, 1}, {3, 2}, {1, 1}}},
26cb93a386Sopenharmony_ci};
27cb93a386Sopenharmony_ci
28cb93a386Sopenharmony_cistatic const size_t quadTests_count = SK_ARRAY_COUNT(quadTests);
29cb93a386Sopenharmony_cistatic const size_t cubicTests_count = SK_ARRAY_COUNT(cubicTests);
30cb93a386Sopenharmony_ci
31cb93a386Sopenharmony_cistatic void setRawBounds(const SkDQuad& quad, SkDRect* rect) {
32cb93a386Sopenharmony_ci    rect->set(quad[0]);
33cb93a386Sopenharmony_ci    rect->add(quad[1]);
34cb93a386Sopenharmony_ci    rect->add(quad[2]);
35cb93a386Sopenharmony_ci}
36cb93a386Sopenharmony_ci
37cb93a386Sopenharmony_cistatic void setRawBounds(const SkDCubic& cubic, SkDRect* rect) {
38cb93a386Sopenharmony_ci    rect->set(cubic[0]);
39cb93a386Sopenharmony_ci    rect->add(cubic[1]);
40cb93a386Sopenharmony_ci    rect->add(cubic[2]);
41cb93a386Sopenharmony_ci    rect->add(cubic[3]);
42cb93a386Sopenharmony_ci}
43cb93a386Sopenharmony_ci
44cb93a386Sopenharmony_ciDEF_TEST(PathOpsDRect, reporter) {
45cb93a386Sopenharmony_ci    size_t index;
46cb93a386Sopenharmony_ci    SkDRect rect, rect2;
47cb93a386Sopenharmony_ci    for (index = 0; index < quadTests_count; ++index) {
48cb93a386Sopenharmony_ci        const QuadPts& q = quadTests[index];
49cb93a386Sopenharmony_ci        SkDQuad quad;
50cb93a386Sopenharmony_ci        quad.debugSet(q.fPts);
51cb93a386Sopenharmony_ci        SkASSERT(ValidQuad(quad));
52cb93a386Sopenharmony_ci        setRawBounds(quad, &rect);
53cb93a386Sopenharmony_ci        rect2.setBounds(quad);
54cb93a386Sopenharmony_ci        REPORTER_ASSERT(reporter, rect.intersects(rect2));
55cb93a386Sopenharmony_ci        // FIXME: add a recursive box subdivision method to verify that tight bounds is correct
56cb93a386Sopenharmony_ci        SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
57cb93a386Sopenharmony_ci        REPORTER_ASSERT(reporter, rect.contains(leftTop));
58cb93a386Sopenharmony_ci        SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
59cb93a386Sopenharmony_ci        REPORTER_ASSERT(reporter, rect.contains(rightBottom));
60cb93a386Sopenharmony_ci    }
61cb93a386Sopenharmony_ci    for (index = 0; index < cubicTests_count; ++index) {
62cb93a386Sopenharmony_ci        const CubicPts& c = cubicTests[index];
63cb93a386Sopenharmony_ci        SkDCubic cubic;
64cb93a386Sopenharmony_ci        cubic.debugSet(c.fPts);
65cb93a386Sopenharmony_ci        SkASSERT(ValidCubic(cubic));
66cb93a386Sopenharmony_ci        setRawBounds(cubic, &rect);
67cb93a386Sopenharmony_ci        rect2.setBounds(cubic);
68cb93a386Sopenharmony_ci        REPORTER_ASSERT(reporter, rect.intersects(rect2));
69cb93a386Sopenharmony_ci        // FIXME: add a recursive box subdivision method to verify that tight bounds is correct
70cb93a386Sopenharmony_ci        SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
71cb93a386Sopenharmony_ci        REPORTER_ASSERT(reporter, rect.contains(leftTop));
72cb93a386Sopenharmony_ci        SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
73cb93a386Sopenharmony_ci        REPORTER_ASSERT(reporter, rect.contains(rightBottom));
74cb93a386Sopenharmony_ci    }
75cb93a386Sopenharmony_ci}
76