Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
RTreeTest.cpp File Reference
#include "include/core/SkRect.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkTemplates.h"
#include "src/base/SkRandom.h"
#include "src/core/SkRTree.h"
#include "tests/Test.h"
#include <cmath>
#include <cstddef>
#include <vector>

Go to the source code of this file.

Functions

static SkRect random_rect (SkRandom &rand)
 
static bool verify_query (SkRect query, SkRect rects[], const std::vector< int > &found)
 
static void run_queries (skiatest::Reporter *reporter, SkRandom &rand, SkRect rects[], const SkRTree &tree)
 
 DEF_TEST (RTree, reporter)
 

Variables

static const int NUM_RECTS = 200
 
static const size_t NUM_ITERATIONS = 100
 
static const size_t NUM_QUERIES = 50
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( RTree  ,
reporter   
)

Definition at line 65 of file RTreeTest.cpp.

65 {
66 int expectedDepthMin = -1;
67 int tmp = NUM_RECTS;
68 while (tmp > 0) {
69 tmp -= static_cast<int>(pow(static_cast<double>(SkRTree::kMaxChildren),
70 static_cast<double>(expectedDepthMin + 1)));
71 ++expectedDepthMin;
72 }
73
74 int expectedDepthMax = -1;
75 tmp = NUM_RECTS;
76 while (tmp > 0) {
77 tmp -= static_cast<int>(pow(static_cast<double>(SkRTree::kMinChildren),
78 static_cast<double>(expectedDepthMax + 1)));
79 ++expectedDepthMax;
80 }
81
82 SkRandom rand;
84 for (size_t i = 0; i < NUM_ITERATIONS; ++i) {
85 SkRTree rtree;
86 REPORTER_ASSERT(reporter, 0 == rtree.getCount());
87
88 for (int j = 0; j < NUM_RECTS; j++) {
89 rects[j] = random_rect(rand);
90 }
91
92 rtree.insert(rects.data(), NUM_RECTS);
93
94 run_queries(reporter, rand, rects.data(), rtree);
96 REPORTER_ASSERT(reporter, expectedDepthMin <= rtree.getDepth() &&
97 expectedDepthMax >= rtree.getDepth());
98 }
99}
reporter
static SkRect random_rect(SkRandom &rand)
Definition RTreeTest.cpp:25
static const int NUM_RECTS
Definition RTreeTest.cpp:21
static void run_queries(skiatest::Reporter *reporter, SkRandom &rand, SkRect rects[], const SkRTree &tree)
Definition RTreeTest.cpp:55
static const size_t NUM_ITERATIONS
Definition RTreeTest.cpp:22
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
void insert(const SkRect[], int N) override
Definition SkRTree.cpp:15
static const int kMinChildren
Definition SkRTree.h:50
int getDepth() const
Definition SkRTree.h:45
int getCount() const
Definition SkRTree.h:47
static const int kMaxChildren
Definition SkRTree.h:51

◆ random_rect()

static SkRect random_rect ( SkRandom rand)
static

Definition at line 25 of file RTreeTest.cpp.

25 {
26 SkRect rect = {0,0,0,0};
27 while (rect.isEmpty()) {
28 rect.fLeft = rand.nextRangeF(0, 1000);
29 rect.fRight = rand.nextRangeF(0, 1000);
30 rect.fTop = rand.nextRangeF(0, 1000);
31 rect.fBottom = rand.nextRangeF(0, 1000);
32 rect.sort();
33 }
34 return rect;
35}
float nextRangeF(float min, float max)
Definition SkRandom.h:64
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350

◆ run_queries()

static void run_queries ( skiatest::Reporter reporter,
SkRandom rand,
SkRect  rects[],
const SkRTree tree 
)
static

Definition at line 55 of file RTreeTest.cpp.

56 {
57 for (size_t i = 0; i < NUM_QUERIES; ++i) {
58 std::vector<int> hits;
59 SkRect query = random_rect(rand);
60 tree.search(query, &hits);
61 REPORTER_ASSERT(reporter, verify_query(query, rects, hits));
62 }
63}
static const size_t NUM_QUERIES
Definition RTreeTest.cpp:23
static bool verify_query(SkRect query, SkRect rects[], const std::vector< int > &found)
Definition RTreeTest.cpp:37
void search(const SkRect &query, std::vector< int > *results) const override
Definition SkRTree.cpp:147

◆ verify_query()

static bool verify_query ( SkRect  query,
SkRect  rects[],
const std::vector< int > &  found 
)
static

Definition at line 37 of file RTreeTest.cpp.

37 {
38 std::vector<int> expected;
39 // manually intersect with every rectangle
40 for (int i = 0; i < NUM_RECTS; ++i) {
41 if (SkRect::Intersects(query, rects[i])) {
42 expected.push_back(i);
43 }
44 }
45
46 if (expected.size() != found.size()) {
47 return false;
48 }
49 if (0 == expected.size()) {
50 return true;
51 }
52 return found == expected;
53}

Variable Documentation

◆ NUM_ITERATIONS

const size_t NUM_ITERATIONS = 100
static

Definition at line 22 of file RTreeTest.cpp.

◆ NUM_QUERIES

const size_t NUM_QUERIES = 50
static

Definition at line 23 of file RTreeTest.cpp.

◆ NUM_RECTS

const int NUM_RECTS = 200
static

Definition at line 21 of file RTreeTest.cpp.