5#ifndef FLUTTER_IMPELLER_GEOMETRY_GEOMETRY_ASSERTS_H_
6#define FLUTTER_IMPELLER_GEOMETRY_GEOMETRY_ASSERTS_H_
11#include "gtest/gtest.h"
22 if (std::isnan(
a) || std::isnan(
b)) {
33 static constexpr float kImpellerTestingMaxULP = 32;
39 static constexpr float kMinimumULPStep = (1.0f / (1 << 24));
41 auto adjust_step = [](
float v) {
42 return (
std::abs(v) < kMinimumULPStep) ? std::copysignf(kMinimumULPStep, v)
46 float step_ab = adjust_step(
a - std::nexttowardf(
a,
b));
47 float step_ba = adjust_step(
b - std::nexttowardf(
b,
a));
49 float ab_ulps = (
a -
b) / step_ab;
50 float ba_ulps = (
b -
a) / step_ba;
53 return (
std::min(ab_ulps, ba_ulps) < kImpellerTestingMaxULP);
75 return equal ? ::testing::AssertionSuccess()
76 : ::testing::AssertionFailure()
77 <<
"Matrixes are not equal " <<
a <<
" " <<
b;
85 return equal ? ::testing::AssertionSuccess()
86 : ::testing::AssertionFailure() <<
"Quaternions are not equal.";
95 return equal ? ::testing::AssertionSuccess()
96 : ::testing::AssertionFailure()
97 <<
"Rects are not equal (" <<
a <<
" " <<
b <<
")";
105 return equal ? ::testing::AssertionSuccess()
106 : ::testing::AssertionFailure() <<
"Colors are not equal.";
113 return equal ? ::testing::AssertionSuccess()
114 : ::testing::AssertionFailure()
115 <<
"Points are not equal (" <<
a <<
" " <<
b <<
").";
123 return equal ? ::testing::AssertionSuccess()
124 : ::testing::AssertionFailure() <<
"Vector3s are not equal.";
132 return equal ? ::testing::AssertionSuccess()
133 : ::testing::AssertionFailure() <<
"Vector4s are not equal.";
139 return equal ? ::testing::AssertionSuccess()
140 : ::testing::AssertionFailure() <<
"Sizes are not equal.";
143inline ::testing::AssertionResult
Array4Near(std::array<uint8_t, 4>
a,
144 std::array<uint8_t, 4>
b) {
148 return equal ? ::testing::AssertionSuccess()
149 : ::testing::AssertionFailure() <<
"Arrays are not equal.";
153 std::vector<uint8_t>
a,
154 std::vector<impeller::Color>
b) {
155 if (
a.size() !=
b.size() * 4) {
156 return ::testing::AssertionFailure()
157 <<
"Color buffer length does not match";
159 for (
auto i = 0u;
i <
b.size();
i++) {
160 auto right =
b[
i].Premultiply().ToR8G8B8A8();
166 ::testing::AssertionFailure() <<
"Color buffers are not equal.";
169 return ::testing::AssertionSuccess();
172inline ::testing::AssertionResult
ColorsNear(std::vector<impeller::Color>
a,
173 std::vector<impeller::Color>
b) {
174 if (
a.size() !=
b.size()) {
175 return ::testing::AssertionFailure() <<
"Colors length does not match";
177 for (
auto i = 0u;
i <
b.size();
i++) {
183 ::testing::AssertionFailure() <<
"Colors are not equal.";
186 return ::testing::AssertionSuccess();
189#define ASSERT_MATRIX_NEAR(a, b) ASSERT_PRED2(&::MatrixNear, a, b)
190#define ASSERT_QUATERNION_NEAR(a, b) ASSERT_PRED2(&::QuaternionNear, a, b)
191#define ASSERT_RECT_NEAR(a, b) ASSERT_PRED2(&::RectNear, a, b)
192#define ASSERT_COLOR_NEAR(a, b) ASSERT_PRED2(&::ColorNear, a, b)
193#define ASSERT_POINT_NEAR(a, b) ASSERT_PRED2(&::PointNear, a, b)
194#define ASSERT_VECTOR3_NEAR(a, b) ASSERT_PRED2(&::Vector3Near, a, b)
195#define ASSERT_VECTOR4_NEAR(a, b) ASSERT_PRED2(&::Vector4Near, a, b)
196#define ASSERT_SIZE_NEAR(a, b) ASSERT_PRED2(&::SizeNear, a, b)
197#define ASSERT_ARRAY_4_NEAR(a, b) ASSERT_PRED2(&::Array4Near, a, b)
198#define ASSERT_COLOR_BUFFER_NEAR(a, b) ASSERT_PRED2(&::ColorBufferNear, a, b)
199#define ASSERT_COLORS_NEAR(a, b) ASSERT_PRED2(&::ColorsNear, a, b)
201#define EXPECT_MATRIX_NEAR(a, b) EXPECT_PRED2(&::MatrixNear, a, b)
202#define EXPECT_QUATERNION_NEAR(a, b) EXPECT_PRED2(&::QuaternionNear, a, b)
203#define EXPECT_RECT_NEAR(a, b) EXPECT_PRED2(&::RectNear, a, b)
204#define EXPECT_COLOR_NEAR(a, b) EXPECT_PRED2(&::ColorNear, a, b)
205#define EXPECT_POINT_NEAR(a, b) EXPECT_PRED2(&::PointNear, a, b)
206#define EXPECT_VECTOR3_NEAR(a, b) EXPECT_PRED2(&::Vector3Near, a, b)
207#define EXPECT_VECTOR4_NEAR(a, b) EXPECT_PRED2(&::Vector4Near, a, b)
208#define EXPECT_SIZE_NEAR(a, b) EXPECT_PRED2(&::SizeNear, a, b)
209#define EXPECT_ARRAY_4_NEAR(a, b) EXPECT_PRED2(&::Array4Near, a, b)
210#define EXPECT_COLOR_BUFFER_NEAR(a, b) EXPECT_PRED2(&::ColorBufferNear, a, b)
211#define EXPECT_COLORS_NEAR(a, b) EXPECT_PRED2(&::ColorsNear, a, b)
static bool equal(const SkBitmap &a, const SkBitmap &b)
static bool right(const SkPoint &p0, const SkPoint &p1)
#define FML_CHECK(condition)
inline ::testing::AssertionResult RectNear(impeller::Rect a, impeller::Rect b)
inline ::testing::AssertionResult QuaternionNear(impeller::Quaternion a, impeller::Quaternion b)
inline ::testing::AssertionResult ColorNear(impeller::Color a, impeller::Color b)
inline ::testing::AssertionResult ColorsNear(std::vector< impeller::Color > a, std::vector< impeller::Color > b)
inline ::testing::AssertionResult PointNear(impeller::Point a, impeller::Point b)
inline ::testing::AssertionResult SizeNear(impeller::Size a, impeller::Size b)
inline ::testing::AssertionResult Array4Near(std::array< uint8_t, 4 > a, std::array< uint8_t, 4 > b)
bool NumberNear(double a, double b)
inline ::testing::AssertionResult MatrixNear(impeller::Matrix a, impeller::Matrix b)
inline ::testing::AssertionResult Vector4Near(impeller::Vector4 a, impeller::Vector4 b)
inline ::testing::AssertionResult Vector3Near(impeller::Vector3 a, impeller::Vector3 b)
inline ::testing::AssertionResult ColorBufferNear(std::vector< uint8_t > a, std::vector< impeller::Color > b)
static float min(float r, float g, float b)
SIN Vec< N, float > abs(const Vec< N, float > &x)
A 4x4 matrix using column-major storage.