Flutter Engine
The Flutter Engine
IntersectionTreeTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 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
8#include "src/base/SkRandom.h"
10#include "tests/Test.h"
11
12namespace skgpu::graphite {
13
15public:
16 bool add(SkRect rect) {
17 for (const SkRect& r : fRects) {
18 if (r.intersects(rect)) {
19 return false;
20 }
21 }
22 fRects.push_back(rect);
23 return true;
24 }
25
26private:
27 std::vector<SkRect> fRects;
28};
29
30#define CHECK(A) REPORTER_ASSERT(reporter, A)
31
33 SkRandom rand;
34 {
35 SimpleIntersectionTree simpleTree;
37 for (int i = 0; i < 1000; ++i) {
38 Rect rect = Rect::XYWH(rand.nextRangeF(0, 500),
39 rand.nextRangeF(0, 500),
40 rand.nextRangeF(0, 70),
41 rand.nextRangeF(0, 70));
42 CHECK(tree.add(rect) == simpleTree.add({rect.left(),
43 rect.top(),
44 rect.right(),
45 rect.bot()}));
46 }
47 }
48 {
49 SimpleIntersectionTree simpleTree;
51 for (int i = 0; i < 100; ++i) {
52 Rect rect = Rect::XYWH(rand.nextRangeF(0, 500),
53 rand.nextRangeF(0, 500),
54 rand.nextRangeF(0, 200),
55 rand.nextRangeF(0, 200));
56 CHECK(tree.add(rect) == simpleTree.add({rect.left(),
57 rect.top(),
58 rect.right(),
59 rect.bot()}));
60 }
61 }
62 {
63 SimpleIntersectionTree simpleTree;
65 CHECK(tree.add(Rect::Infinite()));
66 CHECK(!tree.add(Rect::WH(1,1)));
67 CHECK(!tree.add(Rect::WH(1,std::numeric_limits<float>::infinity())));
68 CHECK(tree.add(Rect::WH(0, 0)));
69 CHECK(tree.add(Rect::WH(-1, 1)));
70 CHECK(tree.add(Rect::WH(1, std::numeric_limits<float>::quiet_NaN())));
71 }
72}
73
74} // namespace skgpu::graphite
reporter
Definition: FontMgrTest.cpp:39
#define CHECK(A)
float nextRangeF(float min, float max)
Definition: SkRandom.h:64
static AI Rect XYWH(float x, float y, float w, float h)
Definition: Rect.h:40
static AI Rect WH(float w, float h)
Definition: Rect.h:46
static AI Rect Infinite()
Definition: Rect.h:60
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
DEF_GRAPHITE_TEST(skgpu_IntersectionTree, reporter, CtsEnforcement::kNextRelease)