skia2/tests/graphite/IntersectionTreeTest.cpp
Jim Van Verth 42f710f3fa Reland "[graphite] Move Graphite into Skia base directories."
This is a reland of commit ae5e846047

Original change's description:
> [graphite] Move Graphite into Skia base directories.
>
> Change-Id: Ie0fb74f3766a8b33387c145bd1151344c25808cb
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/528708
> Reviewed-by: Kevin Lubick <kjlubick@google.com>
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> Commit-Queue: Jim Van Verth <jvanverth@google.com>

Change-Id: Ia575fd49206ad0b665a6a9153317e738bb321446
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/529059
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
2022-04-11 18:37:20 +00:00

76 lines
2.5 KiB
C++

/*
* Copyright 2021 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/utils/SkRandom.h"
#include "src/gpu/graphite/geom/IntersectionTree.h"
#include "tests/Test.h"
namespace skgpu::graphite {
class SimpleIntersectionTree {
public:
bool add(SkRect rect) {
for (const SkRect& r : fRects) {
if (r.intersects(rect)) {
return false;
}
}
fRects.push_back(rect);
return true;
}
private:
std::vector<SkRect> fRects;
};
#define CHECK(A) REPORTER_ASSERT(reporter, A)
DEF_GRAPHITE_TEST(skgpu_IntersectionTree, reporter) {
SkRandom rand;
{
SimpleIntersectionTree simpleTree;
IntersectionTree tree;
for (int i = 0; i < 1000; ++i) {
Rect rect = Rect::XYWH(rand.nextRangeF(0, 500),
rand.nextRangeF(0, 500),
rand.nextRangeF(0, 70),
rand.nextRangeF(0, 70));
CHECK(tree.add(rect) == simpleTree.add({rect.left(),
rect.top(),
rect.right(),
rect.bot()}));
}
}
{
SimpleIntersectionTree simpleTree;
IntersectionTree tree;
for (int i = 0; i < 100; ++i) {
Rect rect = Rect::XYWH(rand.nextRangeF(0, 500),
rand.nextRangeF(0, 500),
rand.nextRangeF(0, 200),
rand.nextRangeF(0, 200));
CHECK(tree.add(rect) == simpleTree.add({rect.left(),
rect.top(),
rect.right(),
rect.bot()}));
}
}
{
SimpleIntersectionTree simpleTree;
IntersectionTree tree;
CHECK(tree.add(Rect(float2(-std::numeric_limits<float>::infinity()),
float2(std::numeric_limits<float>::infinity()))));
CHECK(!tree.add(Rect::WH(1,1)));
CHECK(!tree.add(Rect::WH(1,std::numeric_limits<float>::infinity())));
CHECK(tree.add(Rect::WH(0, 0)));
CHECK(tree.add(Rect::WH(-1, 1)));
CHECK(tree.add(Rect::WH(1, std::numeric_limits<float>::quiet_NaN())));
}
}
} // namespace skgpu::graphite