aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/RTreeBench.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-08-27 10:39:42 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-08-27 10:39:42 -0700
commit533eb782edaa0b6fece6166d3001edf72ec39f11 (patch)
treea4d863ff13725c8c8c33c9b50d63ec74c54deff1 /bench/RTreeBench.cpp
parent3031350e05d8ef8c67a5e9ce8e5c428c8560eb50 (diff)
Convert BBH APIs to use SkRect.
Still TODO: convert internals of SkTileGrid.cpp and SkRTree.cpp to work in floats too. NOTREECHECKS=true BUG=skia:1021 R=robertphillips@google.com, reed@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/511613002
Diffstat (limited to 'bench/RTreeBench.cpp')
-rw-r--r--bench/RTreeBench.cpp76
1 files changed, 38 insertions, 38 deletions
diff --git a/bench/RTreeBench.cpp b/bench/RTreeBench.cpp
index 95f55c9a8f..5442f7e261 100644
--- a/bench/RTreeBench.cpp
+++ b/bench/RTreeBench.cpp
@@ -13,12 +13,12 @@
#include "SkString.h"
// confine rectangles to a smallish area, so queries generally hit something, and overlap occurs:
-static const int GENERATE_EXTENTS = 1000;
+static const SkScalar GENERATE_EXTENTS = 1000.0f;
static const int NUM_BUILD_RECTS = 500;
static const int NUM_QUERY_RECTS = 5000;
static const int GRID_WIDTH = 100;
-typedef SkIRect (*MakeRectProc)(SkRandom&, int, int);
+typedef SkRect (*MakeRectProc)(SkRandom&, int, int);
// Time how long it takes to build an R-Tree either bulk-loaded or not
class RTreeBuildBench : public Benchmark {
@@ -115,32 +115,32 @@ protected:
SkRandom rand;
for (int i = 0; i < loops; ++i) {
SkTDArray<void*> hits;
- SkIRect query;
+ SkRect query;
switch(fQuery) {
case kSmall_QueryType:
- query.fLeft = rand.nextU() % GENERATE_EXTENTS;
- query.fTop = rand.nextU() % GENERATE_EXTENTS;
- query.fRight = query.fLeft + (GENERATE_EXTENTS / 20);
- query.fBottom = query.fTop + (GENERATE_EXTENTS / 20);
+ query.fLeft = rand.nextRangeF(0, GENERATE_EXTENTS);
+ query.fTop = rand.nextRangeF(0, GENERATE_EXTENTS);
+ query.fRight = query.fLeft + (GENERATE_EXTENTS / 20);
+ query.fBottom = query.fTop + (GENERATE_EXTENTS / 20);
break;
case kLarge_QueryType:
- query.fLeft = rand.nextU() % GENERATE_EXTENTS;
- query.fTop = rand.nextU() % GENERATE_EXTENTS;
- query.fRight = query.fLeft + (GENERATE_EXTENTS / 2);
- query.fBottom = query.fTop + (GENERATE_EXTENTS / 2);
+ query.fLeft = rand.nextRangeF(0, GENERATE_EXTENTS);
+ query.fTop = rand.nextRangeF(0, GENERATE_EXTENTS);
+ query.fRight = query.fLeft + (GENERATE_EXTENTS / 2);
+ query.fBottom = query.fTop + (GENERATE_EXTENTS / 2);
break;
case kFull_QueryType:
- query.fLeft = -GENERATE_EXTENTS;
- query.fTop = -GENERATE_EXTENTS;
- query.fRight = 2 * GENERATE_EXTENTS;
+ query.fLeft = -GENERATE_EXTENTS;
+ query.fTop = -GENERATE_EXTENTS;
+ query.fRight = 2 * GENERATE_EXTENTS;
query.fBottom = 2 * GENERATE_EXTENTS;
break;
default: // fallthrough
case kRandom_QueryType:
- query.fLeft = rand.nextU() % GENERATE_EXTENTS;
- query.fTop = rand.nextU() % GENERATE_EXTENTS;
- query.fRight = query.fLeft + 1 + rand.nextU() % (GENERATE_EXTENTS / 2);
- query.fBottom = query.fTop + 1 + rand.nextU() % (GENERATE_EXTENTS / 2);
+ query.fLeft = rand.nextRangeF(0, GENERATE_EXTENTS);
+ query.fTop = rand.nextRangeF(0, GENERATE_EXTENTS);
+ query.fRight = query.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/2);
+ query.fBottom = query.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/2);
break;
};
fTree->search(query, &hits);
@@ -155,34 +155,34 @@ private:
typedef Benchmark INHERITED;
};
-static inline SkIRect make_concentric_rects_increasing(SkRandom&, int index, int numRects) {
- SkIRect out = {0, 0, index + 1, index + 1};
+static inline SkRect make_concentric_rects_increasing(SkRandom&, int index, int numRects) {
+ SkRect out = SkRect::MakeWH(SkIntToScalar(index+1), SkIntToScalar(index+1));
return out;
}
-static inline SkIRect make_XYordered_rects(SkRandom& rand, int index, int numRects) {
- SkIRect out;
- out.fLeft = index % GRID_WIDTH;
- out.fTop = index / GRID_WIDTH;
- out.fRight = out.fLeft + 1 + rand.nextU() % (GENERATE_EXTENTS / 3);
- out.fBottom = out.fTop + 1 + rand.nextU() % (GENERATE_EXTENTS / 3);
+static inline SkRect make_XYordered_rects(SkRandom& rand, int index, int numRects) {
+ SkRect out;
+ out.fLeft = SkIntToScalar(index % GRID_WIDTH);
+ out.fTop = SkIntToScalar(index / GRID_WIDTH);
+ out.fRight = out.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/3);
+ out.fBottom = out.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/3);
return out;
}
-static inline SkIRect make_YXordered_rects(SkRandom& rand, int index, int numRects) {
- SkIRect out;
- out.fLeft = index / GRID_WIDTH;
- out.fTop = index % GRID_WIDTH;
- out.fRight = out.fLeft + 1 + rand.nextU() % (GENERATE_EXTENTS / 3);
- out.fBottom = out.fTop + 1 + rand.nextU() % (GENERATE_EXTENTS / 3);
+static inline SkRect make_YXordered_rects(SkRandom& rand, int index, int numRects) {
+ SkRect out;
+ out.fLeft = SkIntToScalar(index / GRID_WIDTH);
+ out.fTop = SkIntToScalar(index % GRID_WIDTH);
+ out.fRight = out.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/3);
+ out.fBottom = out.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/3);
return out;
}
-static inline SkIRect make_random_rects(SkRandom& rand, int index, int numRects) {
- SkIRect out;
- out.fLeft = rand.nextS() % GENERATE_EXTENTS;
- out.fTop = rand.nextS() % GENERATE_EXTENTS;
- out.fRight = out.fLeft + 1 + rand.nextU() % (GENERATE_EXTENTS / 5);
- out.fBottom = out.fTop + 1 + rand.nextU() % (GENERATE_EXTENTS / 5);
+static inline SkRect make_random_rects(SkRandom& rand, int index, int numRects) {
+ SkRect out;
+ out.fLeft = rand.nextRangeF(0, GENERATE_EXTENTS);
+ out.fTop = rand.nextRangeF(0, GENERATE_EXTENTS);
+ out.fRight = out.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/5);
+ out.fBottom = out.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/5);
return out;
}