Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
PathOpsBoundsTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 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 */
16#include "tests/Test.h"
17
18#include <array>
19#include <cstddef>
20
21static const SkRect sectTests[][2] = {
22 {{2, 0, 4, 1}, {4, 0, 6, 1}},
23 {{2, 0, 4, 1}, {3, 0, 5, 1}},
24 {{2, 0, 4, 1}, {3, 0, 5, 0}},
25 {{2, 0, 4, 1}, {3, 1, 5, 2}},
26 {{2, 1, 4, 2}, {1, 0, 5, 3}},
27 {{2, 1, 5, 3}, {3, 1, 4, 2}},
28 {{2, 0, 4, 1}, {3, 0, 3, 0}}, // intersecting an empty bounds is OK
29 {{2, 0, 4, 1}, {4, 1, 5, 2}}, // touching just on a corner is OK
30};
31
32static const size_t sectTestsCount = std::size(sectTests);
33
34static const SkRect noSectTests[][2] = {
35 {{2, 0, 4, 1}, {5, 0, 6, 1}},
36 {{2, 0, 4, 1}, {3, 2, 5, 2}},
37};
38
39static const size_t noSectTestsCount = std::size(noSectTests);
40
41DEF_TEST(PathOpsBounds, reporter) {
42 for (size_t index = 0; index < sectTestsCount; ++index) {
43 const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(sectTests[index][0]);
44 SkASSERT(ValidBounds(bounds1));
45 const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(sectTests[index][1]);
46 SkASSERT(ValidBounds(bounds2));
47 bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2);
48 REPORTER_ASSERT(reporter, touches);
49 }
50 for (size_t index = 0; index < noSectTestsCount; ++index) {
51 const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(noSectTests[index][0]);
52 SkASSERT(ValidBounds(bounds1));
53 const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(noSectTests[index][1]);
54 SkASSERT(ValidBounds(bounds2));
55 bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2);
56 REPORTER_ASSERT(reporter, !touches);
57 }
58 SkPathOpsBounds bounds;
59 bounds.setEmpty();
60 bounds.add(1, 2, 3, 4);
61 SkPathOpsBounds expected;
62 expected.setLTRB(0, 0, 3, 4);
63 REPORTER_ASSERT(reporter, bounds == expected);
64 bounds.setEmpty();
65 SkPathOpsBounds ordinal;
66 ordinal.setLTRB(1, 2, 3, 4);
67 bounds.add(ordinal);
68 REPORTER_ASSERT(reporter, bounds == expected);
69 bounds.setEmpty();
70 SkDPoint botRight = {3, 4};
71 bounds.add(botRight);
72 REPORTER_ASSERT(reporter, bounds == expected);
73 const SkPoint curvePts[] = {{0, 0}, {1, 2}, {3, 4}, {5, 6}};
74 SkDCurve curve;
75 curve.fQuad.set(curvePts);
76 curve.setQuadBounds(curvePts, 1, 0, 1, &bounds);
77 expected.setLTRB(0, 0, 3, 4);
78 REPORTER_ASSERT(reporter, bounds == expected);
79 curve.fCubic.set(curvePts);
80 curve.setCubicBounds(curvePts, 1, 0, 1, &bounds);
81 expected.setLTRB(0, 0, 5, 6);
82 REPORTER_ASSERT(reporter, bounds == expected);
83}
reporter
static const SkRect noSectTests[][2]
static const size_t noSectTestsCount
static const SkRect sectTests[][2]
static const size_t sectTestsCount
bool ValidBounds(const SkPathOpsBounds &bounds)
#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
const SkDCubic & set(const SkPoint pts[kPointCount] SkDEBUGPARAMS(SkOpGlobalState *state=nullptr))
SkDQuad fQuad
void setCubicBounds(const SkPoint curve[4], SkScalar, double s, double e, SkPathOpsBounds *)
SkDCubic fCubic
void setQuadBounds(const SkPoint curve[3], SkScalar, double s, double e, SkPathOpsBounds *)
const SkDQuad & set(const SkPoint pts[kPointCount] SkDEBUGPARAMS(SkOpGlobalState *state=nullptr))
static bool Intersects(const SkPathOpsBounds &a, const SkPathOpsBounds &b)
void setLTRB(float left, float top, float right, float bottom)
Definition SkRect.h:865