skia2/tests/graphite/IntersectionTreeTest.cpp
Michael Ludwig 5c08e3c357 Standardize on skvx aliases, plus clean-up
This adds aliases like skvx::float2, float4, etc. to SkVx.h and goes
through existing usages of SkVx to standardize on those aliases, or
refer to the full name directly.

In particular, this lets us clean up the equivalent aliases in
src/gpu/tessellate, src/gpu/graphite/VectorTypes and src/gpu/ganesh/GrVx

Where possible, I switched to using skvx::Foo directly and leveraged
auto to make it less redundant. Headers always used the full type
except for PatchWriter.h and Rect.h because of the number of their
usages. In this case, the alias is scoped to private so it can't leak.

This is prep to migrate older code that is still using SkNx and its
aliases like Sk4f to SkVx as well.

Change-Id: I9dd104e83cf17c2b88995a047cfd2e2b0fe6fac2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/541058
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2022-05-17 18:04:55 +00:00

75 lines
2.4 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::Infinite()));
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