| 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)

## 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 160 of file geometry_asserts.h.

## ◆ ASSERT_COLOR_BUFFER_NEAR

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

Definition at line 161 of file geometry_asserts.h.

## ◆ ASSERT_COLOR_NEAR

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

Definition at line 155 of file geometry_asserts.h.

## ◆ ASSERT_COLORS_NEAR

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

Definition at line 162 of file geometry_asserts.h.

## ◆ ASSERT_MATRIX_NEAR

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

Definition at line 152 of file geometry_asserts.h.

## ◆ ASSERT_POINT_NEAR

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

Definition at line 156 of file geometry_asserts.h.

## ◆ ASSERT_QUATERNION_NEAR

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

Definition at line 153 of file geometry_asserts.h.

## ◆ ASSERT_RECT_NEAR

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

Definition at line 154 of file geometry_asserts.h.

## ◆ ASSERT_SIZE_NEAR

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

Definition at line 159 of file geometry_asserts.h.

## ◆ ASSERT_VECTOR3_NEAR

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

Definition at line 157 of file geometry_asserts.h.

## ◆ ASSERT_VECTOR4_NEAR

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

Definition at line 158 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 106 of file geometry_asserts.h.

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

References NumberNear().

## ◆ ColorBufferNear()

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

Definition at line 115 of file geometry_asserts.h.

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

References NumberNear().

## ◆ ColorNear()

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

Definition at line 64 of file geometry_asserts.h.

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

References impeller::Color::alpha, 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 135 of file geometry_asserts.h.

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

References NumberNear().

## ◆ MatrixNear()

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

Definition at line 22 of file geometry_asserts.h.

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

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

## ◆ NumberNear()

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

Definition at line 17 of file geometry_asserts.h.

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

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 73 of file geometry_asserts.h.

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

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

## ◆ QuaternionNear()

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

Definition at line 45 of file geometry_asserts.h.

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

References 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 54 of file geometry_asserts.h.

54 {
55 auto equal = NumberNear(a.origin.x, b.origin.x) &&
56 NumberNear(a.origin.y, b.origin.y) &&
57 NumberNear(a.size.width, b.size.width) &&
58 NumberNear(a.size.height, b.size.height);
59
60 return equal ? ::testing::AssertionSuccess()
61 : ::testing::AssertionFailure() << "Rects are not equal.";
62 }

References impeller::TSize< T >::height, NumberNear(), impeller::TRect< T >::origin, impeller::TRect< T >::size, impeller::TSize< T >::width, impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

## ◆ SizeNear()

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

Definition at line 99 of file geometry_asserts.h.

99 {
100 auto equal = NumberNear(a.width, b.width) && NumberNear(a.height, b.height);
101
102 return equal ? ::testing::AssertionSuccess()
103 : ::testing::AssertionFailure() << "Sizes are not equal.";
104 }

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

## ◆ Vector3Near()

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

Definition at line 81 of file geometry_asserts.h.

82 {
83 auto equal =
84 NumberNear(a.x, b.x) && NumberNear(a.y, b.y) && NumberNear(a.z, b.z);
85
86 return equal ? ::testing::AssertionSuccess()
87 : ::testing::AssertionFailure() << "Vector3s are not equal.";
88 }

References 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 90 of file geometry_asserts.h.

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

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

impeller::Matrix::m
Scalar m[16]
Definition: matrix.h:38
NumberNear
bool NumberNear(double a, double b)
Definition: geometry_asserts.h:17
impeller::Quaternion::z
Scalar z
Definition: quaternion.h:18
impeller::TRect::size
TSize< Type > size
Definition: rect.h:24
impeller::TPoint::y
Type y
Definition: point.h:24
impeller::Quaternion::w
Scalar w
Definition: quaternion.h:19
impeller::Color::alpha
Scalar alpha
Definition: color.h:141
impeller::Color::green
Scalar green
Definition: color.h:131
impeller::Vector3::x
Scalar x
Definition: vector.h:20
impeller::Quaternion::x
Scalar x
Definition: quaternion.h:16
impeller::Color::red
Scalar red
Definition: color.h:126
impeller::Vector3::z
Scalar z
Definition: vector.h:22
impeller::TRect::origin
TPoint< Type > origin
Definition: rect.h:23
impeller::Vector4::x
Scalar x
Definition: vector.h:232
impeller::Vector3::y
Scalar y
Definition: vector.h:21
impeller::TSize::width
Type width
Definition: size.h:21
impeller::TPoint::x
Type x
Definition: point.h:23
impeller::Vector4::w
Scalar w
Definition: vector.h:235
impeller::Vector4::y
Scalar y
Definition: vector.h:233
impeller::Quaternion::y
Scalar y
Definition: quaternion.h:17
impeller::TSize::height
Type height
Definition: size.h:22
impeller::Color::blue
Scalar blue
Definition: color.h:136
impeller::Vector4::z
Scalar z
Definition: vector.h:234