| Flutter Impeller |

Macros | Functions
geometry_asserts.h File Reference
`#include <array>`
`#include <iostream>`
`#include "gtest/gtest.h"`
`#include "impeller/geometry/matrix.h"`
`#include "impeller/geometry/point.h"`
`#include "impeller/geometry/rect.h"`
`#include "impeller/geometry/size.h"`
`#include "impeller/geometry/vector.h"`

Go to the source code of this file.

## Macros
#define | ASSERT_MATRIX_NEAR(a, b) ASSERT_PRED2(&::MatrixNear, a, b)
#define | ASSERT_QUATERNION_NEAR(a, b) ASSERT_PRED2(&::QuaternionNear, a, b)
#define | ASSERT_RECT_NEAR(a, b) ASSERT_PRED2(&::RectNear, a, b)
#define | ASSERT_COLOR_NEAR(a, b) ASSERT_PRED2(&::ColorNear, a, b)
#define | ASSERT_POINT_NEAR(a, b) ASSERT_PRED2(&::PointNear, a, b)
#define | ASSERT_VECTOR3_NEAR(a, b) ASSERT_PRED2(&::Vector3Near, a, b)
#define | ASSERT_VECTOR4_NEAR(a, b) ASSERT_PRED2(&::Vector4Near, a, b)
#define | ASSERT_SIZE_NEAR(a, b) ASSERT_PRED2(&::SizeNear, a, b)
#define | ASSERT_ARRAY_4_NEAR(a, b) ASSERT_PRED2(&::Array4Near, a, b)
#define | ASSERT_COLOR_BUFFER_NEAR(a, b) ASSERT_PRED2(&::ColorBufferNear, a, b)
#define | ASSERT_COLORS_NEAR(a, b) ASSERT_PRED2(&::ColorsNear, a, b)
#define | EXPECT_MATRIX_NEAR(a, b) EXPECT_PRED2(&::MatrixNear, a, b)
#define | EXPECT_QUATERNION_NEAR(a, b) EXPECT_PRED2(&::QuaternionNear, a, b)
#define | EXPECT_RECT_NEAR(a, b) EXPECT_PRED2(&::RectNear, a, b)
#define | EXPECT_COLOR_NEAR(a, b) EXPECT_PRED2(&::ColorNear, a, b)
#define | EXPECT_POINT_NEAR(a, b) EXPECT_PRED2(&::PointNear, a, b)
#define | EXPECT_VECTOR3_NEAR(a, b) EXPECT_PRED2(&::Vector3Near, a, b)
#define | EXPECT_VECTOR4_NEAR(a, b) EXPECT_PRED2(&::Vector4Near, a, b)
#define | EXPECT_SIZE_NEAR(a, b) EXPECT_PRED2(&::SizeNear, a, b)
#define | EXPECT_ARRAY_4_NEAR(a, b) EXPECT_PRED2(&::Array4Near, a, b)
#define | EXPECT_COLOR_BUFFER_NEAR(a, b) EXPECT_PRED2(&::ColorBufferNear, a, b)
#define | EXPECT_COLORS_NEAR(a, b) EXPECT_PRED2(&::ColorsNear, a, b)

## Functions
bool | NumberNear (double a, double b)
inline ::testing::AssertionResult | MatrixNear (impeller::Matrix a, impeller::Matrix b)
inline ::testing::AssertionResult | QuaternionNear (impeller::Quaternion a, impeller::Quaternion b)
inline ::testing::AssertionResult | RectNear (impeller::Rect a, impeller::Rect b)
inline ::testing::AssertionResult | ColorNear (impeller::Color a, impeller::Color b)
inline ::testing::AssertionResult | PointNear (impeller::Point a, impeller::Point b)
inline ::testing::AssertionResult | Vector3Near (impeller::Vector3 a, impeller::Vector3 b)
inline ::testing::AssertionResult | Vector4Near (impeller::Vector4 a, impeller::Vector4 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)
inline ::testing::AssertionResult | ColorBufferNear (std::vector< uint8_t > a, std::vector< impeller::Color > b)
inline ::testing::AssertionResult | ColorsNear (std::vector< impeller::Color > a, std::vector< impeller::Color > b)

## Macro Definition Documentation

## ◆ ASSERT_ARRAY_4_NEAR

#define ASSERT_ARRAY_4_NEAR | ( |  | a,
|  |  | b
| ) |  | ASSERT_PRED2(&::Array4Near, a, b)

Definition at line 164 of file geometry_asserts.h.

## ◆ ASSERT_COLOR_BUFFER_NEAR

#define ASSERT_COLOR_BUFFER_NEAR | ( |  | a,
|  |  | b
| ) |  | ASSERT_PRED2(&::ColorBufferNear, a, b)

Definition at line 165 of file geometry_asserts.h.

## ◆ ASSERT_COLOR_NEAR

#define ASSERT_COLOR_NEAR | ( |  | a,
|  |  | b
| ) |  | ASSERT_PRED2(&::ColorNear, a, b)

Definition at line 159 of file geometry_asserts.h.

## ◆ ASSERT_COLORS_NEAR

#define ASSERT_COLORS_NEAR | ( |  | a,
|  |  | b
| ) |  | ASSERT_PRED2(&::ColorsNear, a, b)

Definition at line 166 of file geometry_asserts.h.

## ◆ ASSERT_MATRIX_NEAR

#define ASSERT_MATRIX_NEAR | ( |  | a,
|  |  | b
| ) |  | ASSERT_PRED2(&::MatrixNear, a, b)

Definition at line 156 of file geometry_asserts.h.

## ◆ ASSERT_POINT_NEAR

#define ASSERT_POINT_NEAR | ( |  | a,
|  |  | b
| ) |  | ASSERT_PRED2(&::PointNear, a, b)

Definition at line 160 of file geometry_asserts.h.

## ◆ ASSERT_QUATERNION_NEAR

#define ASSERT_QUATERNION_NEAR | ( |  | a,
|  |  | b
| ) |  | ASSERT_PRED2(&::QuaternionNear, a, b)

Definition at line 157 of file geometry_asserts.h.

## ◆ ASSERT_RECT_NEAR

#define ASSERT_RECT_NEAR | ( |  | a,
|  |  | b
| ) |  | ASSERT_PRED2(&::RectNear, a, b)

Definition at line 158 of file geometry_asserts.h.

## ◆ ASSERT_SIZE_NEAR

#define ASSERT_SIZE_NEAR | ( |  | a,
|  |  | b
| ) |  | ASSERT_PRED2(&::SizeNear, a, b)

Definition at line 163 of file geometry_asserts.h.

## ◆ ASSERT_VECTOR3_NEAR

#define ASSERT_VECTOR3_NEAR | ( |  | a,
|  |  | b
| ) |  | ASSERT_PRED2(&::Vector3Near, a, b)

Definition at line 161 of file geometry_asserts.h.

## ◆ ASSERT_VECTOR4_NEAR

#define ASSERT_VECTOR4_NEAR | ( |  | a,
|  |  | b
| ) |  | ASSERT_PRED2(&::Vector4Near, a, b)

Definition at line 162 of file geometry_asserts.h.

## ◆ EXPECT_ARRAY_4_NEAR

#define EXPECT_ARRAY_4_NEAR | ( |  | a,
|  |  | b
| ) |  | EXPECT_PRED2(&::Array4Near, a, b)

Definition at line 176 of file geometry_asserts.h.

## ◆ EXPECT_COLOR_BUFFER_NEAR

#define EXPECT_COLOR_BUFFER_NEAR | ( |  | a,
|  |  | b
| ) |  | EXPECT_PRED2(&::ColorBufferNear, a, b)

Definition at line 177 of file geometry_asserts.h.

## ◆ EXPECT_COLOR_NEAR

#define EXPECT_COLOR_NEAR | ( |  | a,
|  |  | b
| ) |  | EXPECT_PRED2(&::ColorNear, a, b)

Definition at line 171 of file geometry_asserts.h.

## ◆ EXPECT_COLORS_NEAR

#define EXPECT_COLORS_NEAR | ( |  | a,
|  |  | b
| ) |  | EXPECT_PRED2(&::ColorsNear, a, b)

Definition at line 178 of file geometry_asserts.h.

## ◆ EXPECT_MATRIX_NEAR

#define EXPECT_MATRIX_NEAR | ( |  | a,
|  |  | b
| ) |  | EXPECT_PRED2(&::MatrixNear, a, b)

Definition at line 168 of file geometry_asserts.h.

## ◆ EXPECT_POINT_NEAR

#define EXPECT_POINT_NEAR | ( |  | a,
|  |  | b
| ) |  | EXPECT_PRED2(&::PointNear, a, b)

Definition at line 172 of file geometry_asserts.h.

## ◆ EXPECT_QUATERNION_NEAR

#define EXPECT_QUATERNION_NEAR | ( |  | a,
|  |  | b
| ) |  | EXPECT_PRED2(&::QuaternionNear, a, b)

Definition at line 169 of file geometry_asserts.h.

## ◆ EXPECT_RECT_NEAR

#define EXPECT_RECT_NEAR | ( |  | a,
|  |  | b
| ) |  | EXPECT_PRED2(&::RectNear, a, b)

Definition at line 170 of file geometry_asserts.h.

## ◆ EXPECT_SIZE_NEAR

#define EXPECT_SIZE_NEAR | ( |  | a,
|  |  | b
| ) |  | EXPECT_PRED2(&::SizeNear, a, b)

Definition at line 175 of file geometry_asserts.h.

## ◆ EXPECT_VECTOR3_NEAR

#define EXPECT_VECTOR3_NEAR | ( |  | a,
|  |  | b
| ) |  | EXPECT_PRED2(&::Vector3Near, a, b)

Definition at line 173 of file geometry_asserts.h.

## ◆ EXPECT_VECTOR4_NEAR

#define EXPECT_VECTOR4_NEAR | ( |  | a,
|  |  | b
| ) |  | EXPECT_PRED2(&::Vector4Near, a, b)

Definition at line 174 of file geometry_asserts.h.

## Function Documentation

## ◆ Array4Near()

inline ::testing::AssertionResult Array4Near | ( | std::array< uint8_t, 4 > | a,
|  | std::array< uint8_t, 4 > | b
| ) |  |

Definition at line 110 of file geometry_asserts.h.

111 {
112 auto equal = NumberNear(a[0], b[0]) && NumberNear(a[1], b[1]) &&
113 NumberNear(a[2], b[2]) && NumberNear(a[3], b[3]);
114
115 return equal ? ::testing::AssertionSuccess()
116 : ::testing::AssertionFailure() << "Arrays are not equal.";
117 }

References impeller::saturated::b, and NumberNear().

## ◆ ColorBufferNear()

inline ::testing::AssertionResult ColorBufferNear | ( | std::vector< uint8_t > | a,
|  | std::vector< impeller::Color > | b
| ) |  |

Definition at line 119 of file geometry_asserts.h.

121 {
122 if (a.size() != b.size() * 4) {
123 return ::testing::AssertionFailure()
124 << "Color buffer length does not match";
125 }
126 for (auto i = 0u; i < b.size(); i++) {
127 auto right = b[i].Premultiply().ToR8G8B8A8();
128 auto j = i * 4;
129 auto equal = NumberNear(a[j], right[0]) && NumberNear(a[j + 1], right[1]) &&
130 NumberNear(a[j + 2], right[2]) &&
131 NumberNear(a[j + 3], right[3]);
132 if (!equal) {
133 ::testing::AssertionFailure() << "Color buffers are not equal.";
134 }
135 }
136 return ::testing::AssertionSuccess();
137 }

References impeller::saturated::b, and NumberNear().

## ◆ ColorNear()

inline ::testing::AssertionResult ColorNear | ( | impeller::Color | a,
|  | impeller::Color | b
| ) |  |

Definition at line 67 of file geometry_asserts.h.

68 {
69 auto equal = NumberNear(a.red, b.red) && NumberNear(a.green, b.green) &&
70 NumberNear(a.blue, b.blue) && NumberNear(a.alpha, b.alpha);
71
72 return equal ? ::testing::AssertionSuccess()
73 : ::testing::AssertionFailure() << "Colors are not equal.";
74 }

References impeller::Color::alpha, impeller::saturated::b, impeller::Color::blue, impeller::Color::green, NumberNear(), and impeller::Color::red.

## ◆ ColorsNear()

inline ::testing::AssertionResult ColorsNear | ( | std::vector< impeller::Color > | a,
|  | std::vector< impeller::Color > | b
| ) |  |

Definition at line 139 of file geometry_asserts.h.

140 {
141 if (a.size() != b.size()) {
142 return ::testing::AssertionFailure() << "Colors length does not match";
143 }
144 for (auto i = 0u; i < b.size(); i++) {
145 auto equal =
146 NumberNear(a[i].red, b[i].red) && NumberNear(a[i].green, b[i].green) &&
147 NumberNear(a[i].blue, b[i].blue) && NumberNear(a[i].alpha, b[i].alpha);
148
149 if (!equal) {
150 ::testing::AssertionFailure() << "Colors are not equal.";
151 }
152 }
153 return ::testing::AssertionSuccess();
154 }

References impeller::saturated::b, and NumberNear().

## ◆ MatrixNear()

inline ::testing::AssertionResult MatrixNear | ( | impeller::Matrix | a,
|  | impeller::Matrix | b
| ) |  |

Definition at line 23 of file geometry_asserts.h.

24 {
25 auto equal = NumberNear(a.m[0], b.m[0]) //
26 && NumberNear(a.m[1], b.m[1]) //
27 && NumberNear(a.m[2], b.m[2]) //
28 && NumberNear(a.m[3], b.m[3]) //
29 && NumberNear(a.m[4], b.m[4]) //
30 && NumberNear(a.m[5], b.m[5]) //
31 && NumberNear(a.m[6], b.m[6]) //
32 && NumberNear(a.m[7], b.m[7]) //
33 && NumberNear(a.m[8], b.m[8]) //
34 && NumberNear(a.m[9], b.m[9]) //
35 && NumberNear(a.m[10], b.m[10]) //
36 && NumberNear(a.m[11], b.m[11]) //
37 && NumberNear(a.m[12], b.m[12]) //
38 && NumberNear(a.m[13], b.m[13]) //
39 && NumberNear(a.m[14], b.m[14]) //
40 && NumberNear(a.m[15], b.m[15]);
41
42 return equal ? ::testing::AssertionSuccess()
43 : ::testing::AssertionFailure()
44 << "Matrixes are not equal " << a << " " << b;
45 }

References impeller::saturated::b, impeller::Matrix::m, and NumberNear().

Referenced by impeller::testing::TEST().

## ◆ NumberNear()

bool NumberNear | ( | double | a,
|  | double | b
| ) |  |
| inline

Definition at line 18 of file geometry_asserts.h.

18 {
19 static const double epsilon = 1e-3;
20 return (a > (b - epsilon)) && (a < (b + epsilon));
21 }

References impeller::saturated::b.

Referenced by Array4Near(), ColorBufferNear(), ColorNear(), ColorsNear(), MatrixNear(), PointNear(), QuaternionNear(), RectNear(), SizeNear(), impeller::testing::TEST_P(), Vector3Near(), and Vector4Near().

## ◆ PointNear()

inline ::testing::AssertionResult PointNear | ( | impeller::Point | a,
|  | impeller::Point | b
| ) |  |

Definition at line 76 of file geometry_asserts.h.

77 {
78 auto equal = NumberNear(a.x, b.x) && NumberNear(a.y, b.y);
79
80 return equal ? ::testing::AssertionSuccess()
81 : ::testing::AssertionFailure()
82 << "Points are not equal (" << a << " " << b << ").";
83 }

References impeller::saturated::b, NumberNear(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by SolidVerticesNear(), and TextureVerticesNear().

## ◆ QuaternionNear()

inline ::testing::AssertionResult QuaternionNear | ( | impeller::Quaternion | a,
|  | impeller::Quaternion | b
| ) |  |

Definition at line 47 of file geometry_asserts.h.

48 {
49 auto equal = NumberNear(a.x, b.x) && NumberNear(a.y, b.y) &&
50 NumberNear(a.z, b.z) && NumberNear(a.w, b.w);
51
52 return equal ? ::testing::AssertionSuccess()
53 : ::testing::AssertionFailure() << "Quaternions are not equal.";
54 }

References impeller::saturated::b, NumberNear(), impeller::Quaternion::w, impeller::Quaternion::x, impeller::Quaternion::y, and impeller::Quaternion::z.

## ◆ RectNear()

inline ::testing::AssertionResult RectNear | ( | impeller::Rect | a,
|  | impeller::Rect | b
| ) |  |

Definition at line 56 of file geometry_asserts.h.

56 {
57 auto equal = NumberNear(a.GetLeft(), b.GetLeft()) &&
58 NumberNear(a.GetTop(), b.GetTop()) &&
59 NumberNear(a.GetRight(), b.GetRight()) &&
60 NumberNear(a.GetBottom(), b.GetBottom());
61
62 return equal ? ::testing::AssertionSuccess()
63 : ::testing::AssertionFailure()
64 << "Rects are not equal (" << a << " " << b << ")";
65 }

References impeller::saturated::b, impeller::TRect< T >::GetBottom(), impeller::TRect< T >::GetLeft(), impeller::TRect< T >::GetRight(), impeller::TRect< T >::GetTop(), and NumberNear().

Referenced by impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ SizeNear()

inline ::testing::AssertionResult SizeNear | ( | impeller::Size | a,
|  | impeller::Size | b
| ) |  |

Definition at line 103 of file geometry_asserts.h.

103 {
104 auto equal = NumberNear(a.width, b.width) && NumberNear(a.height, b.height);
105
106 return equal ? ::testing::AssertionSuccess()
107 : ::testing::AssertionFailure() << "Sizes are not equal.";
108 }

References impeller::saturated::b, impeller::TSize< T >::height, NumberNear(), and impeller::TSize< T >::width.

## ◆ Vector3Near()

inline ::testing::AssertionResult Vector3Near | ( | impeller::Vector3 | a,
|  | impeller::Vector3 | b
| ) |  |

Definition at line 85 of file geometry_asserts.h.

86 {
87 auto equal =
88 NumberNear(a.x, b.x) && NumberNear(a.y, b.y) && NumberNear(a.z, b.z);
89
90 return equal ? ::testing::AssertionSuccess()
91 : ::testing::AssertionFailure() << "Vector3s are not equal.";
92 }

References impeller::saturated::b, NumberNear(), impeller::Vector3::x, impeller::Vector3::y, and impeller::Vector3::z.

## ◆ Vector4Near()

inline ::testing::AssertionResult Vector4Near | ( | impeller::Vector4 | a,
|  | impeller::Vector4 | b
| ) |  |

Definition at line 94 of file geometry_asserts.h.

95 {
96 auto equal = NumberNear(a.x, b.x) && NumberNear(a.y, b.y) &&
97 NumberNear(a.z, b.z) && NumberNear(a.w, b.w);
98
99 return equal ? ::testing::AssertionSuccess()
100 : ::testing::AssertionFailure() << "Vector4s are not equal.";
101 }

References impeller::saturated::b, NumberNear(), impeller::Vector4::w, impeller::Vector4::x, impeller::Vector4::y, and impeller::Vector4::z.

impeller::Matrix::m
Scalar m[16]
Definition: matrix.h:39
NumberNear
bool NumberNear(double a, double b)
Definition: geometry_asserts.h:18
impeller::Quaternion::z
Scalar z
Definition: quaternion.h:19
impeller::TPoint::y
Type y
Definition: point.h:31
impeller::Quaternion::w
Scalar w
Definition: quaternion.h:20
impeller::Color::alpha
Scalar alpha
Definition: color.h:143
impeller::Color::green
Scalar green
Definition: color.h:133
impeller::Vector3::x
Scalar x
Definition: vector.h:23
impeller::Quaternion::x
Scalar x
Definition: quaternion.h:17
impeller::TRect::GetLeft
constexpr auto GetLeft() const
Definition: rect.h:318
impeller::Color::red
Scalar red
Definition: color.h:128
impeller::Vector3::z
Scalar z
Definition: vector.h:25
impeller::Vector4::x
Scalar x
Definition: vector.h:235
impeller::Vector3::y
Scalar y
Definition: vector.h:24
impeller::TSize::width
Type width
Definition: size.h:22
impeller::TPoint::x
Type x
Definition: point.h:30
impeller::Vector4::w
Scalar w
Definition: vector.h:238
impeller::TRect::GetRight
constexpr auto GetRight() const
Definition: rect.h:322
impeller::Vector4::y
Scalar y
Definition: vector.h:236
impeller::saturated::b
SI b
Definition: saturated_math.h:87
impeller::Quaternion::y
Scalar y
Definition: quaternion.h:18
impeller::TRect::GetBottom
constexpr auto GetBottom() const
Definition: rect.h:324
impeller::TSize::height
Type height
Definition: size.h:23
impeller::Color::blue
Scalar blue
Definition: color.h:138
impeller::Vector4::z
Scalar z
Definition: vector.h:237
impeller::TRect::GetTop
constexpr auto GetTop() const
Definition: rect.h:320