Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
PathOpsDRectTest.cpp
Go to the documentation of this file.
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 */
13#include "tests/Test.h"
14
15#include <array>
16#include <cstddef>
17
18static 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
26static 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
32static const size_t quadTests_count = std::size(quadTests);
33static const size_t cubicTests_count = std::size(cubicTests);
34
35static void setRawBounds(const SkDQuad& quad, SkDRect* rect) {
36 rect->set(quad[0]);
37 rect->add(quad[1]);
38 rect->add(quad[2]);
39}
40
41static 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
48DEF_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}
reporter
static void setRawBounds(const SkDQuad &quad, SkDRect *rect)
static const size_t cubicTests_count
static const QuadPts quadTests[]
static const size_t quadTests_count
static const CubicPts cubicTests[]
bool ValidCubic(const SkDCubic &cubic)
bool ValidQuad(const SkDQuad &quad)
#define SkASSERT(cond)
Definition SkAssert.h:116
#define DEF_TEST(name, reporter)
Definition Test.h:312
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
SkDPoint fPts[kPointCount]
SkDPoint fPts[kPointCount]
void debugSet(const SkDPoint *pts)
double fTop
double fRight
double fBottom
void setBounds(const SkDConic &curve)
double fLeft