blob: 70d39d15c03ebc0e4ed57a7694d4b4c1ad0d19c4 [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"
13
caryclark@google.com07393ca2013-04-08 11:47:37 +000014static const SkDQuad quadTests[] = {
15 {{{1, 1}, {2, 1}, {0, 2}}},
16 {{{0, 0}, {1, 1}, {3, 1}}},
17 {{{2, 0}, {1, 1}, {2, 2}}},
18 {{{4, 0}, {0, 1}, {4, 2}}},
19 {{{0, 0}, {0, 1}, {1, 1}}},
20};
21
22static const SkDCubic cubicTests[] = {
23 {{{2, 0}, {3, 1}, {2, 2}, {1, 1}}},
24 {{{3, 1}, {2, 2}, {1, 1}, {2, 0}}},
25 {{{3, 0}, {2, 1}, {3, 2}, {1, 1}}},
26};
27
caryclark@google.comad65a3e2013-04-15 19:13:59 +000028static const size_t quadTests_count = SK_ARRAY_COUNT(quadTests);
29static const size_t cubicTests_count = SK_ARRAY_COUNT(cubicTests);
caryclark@google.com07393ca2013-04-08 11:47:37 +000030
caryclark54359292015-03-26 07:52:43 -070031static void setRawBounds(const SkDQuad& quad, SkDRect* rect) {
32 rect->set(quad[0]);
33 rect->add(quad[1]);
34 rect->add(quad[2]);
35}
36
37static void setRawBounds(const SkDCubic& cubic, SkDRect* rect) {
38 rect->set(cubic[0]);
39 rect->add(cubic[1]);
40 rect->add(cubic[2]);
41 rect->add(cubic[3]);
42}
43
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000044DEF_TEST(PathOpsDRect, reporter) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000045 size_t index;
46 SkDRect rect, rect2;
caryclark@google.com07393ca2013-04-08 11:47:37 +000047 for (index = 0; index < quadTests_count; ++index) {
48 const SkDQuad& quad = quadTests[index];
caryclark@google.com8d0a5242013-07-16 16:11:16 +000049 SkASSERT(ValidQuad(quad));
caryclark54359292015-03-26 07:52:43 -070050 setRawBounds(quad, &rect);
caryclark@google.com07393ca2013-04-08 11:47:37 +000051 rect2.setBounds(quad);
caryclark54359292015-03-26 07:52:43 -070052 REPORTER_ASSERT(reporter, rect.intersects(rect2));
caryclark@google.com07393ca2013-04-08 11:47:37 +000053 // FIXME: add a recursive box subdivision method to verify that tight bounds is correct
54 SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
55 REPORTER_ASSERT(reporter, rect.contains(leftTop));
56 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
57 REPORTER_ASSERT(reporter, rect.contains(rightBottom));
58 }
59 for (index = 0; index < cubicTests_count; ++index) {
60 const SkDCubic& cubic = cubicTests[index];
caryclark@google.com8d0a5242013-07-16 16:11:16 +000061 SkASSERT(ValidCubic(cubic));
caryclark54359292015-03-26 07:52:43 -070062 setRawBounds(cubic, &rect);
caryclark@google.com07393ca2013-04-08 11:47:37 +000063 rect2.setBounds(cubic);
caryclark54359292015-03-26 07:52:43 -070064 REPORTER_ASSERT(reporter, rect.intersects(rect2));
caryclark@google.com07393ca2013-04-08 11:47:37 +000065 // FIXME: add a recursive box subdivision method to verify that tight bounds is correct
66 SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
67 REPORTER_ASSERT(reporter, rect.contains(leftTop));
68 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
69 REPORTER_ASSERT(reporter, rect.contains(rightBottom));
70 }
71}