9#include "gtest/gtest.h"
15template <
typename T,
size_t N>
16constexpr size_t size(
const T (&array)[
N])
noexcept {
20TEST(Vector2dTest, ConversionToFloat) {
33 EXPECT_FALSE(int_nonzero.
IsZero());
35 EXPECT_FALSE(float_nonzero.
IsZero());
49 for (
size_t i = 0;
i <
size(int_tests); ++
i)
50 EXPECT_EQ(int_tests[
i].expected.ToString(), int_tests[
i].actual.ToString());
60 {
Vector2dF(3.1f + 4.3f, 5.1f - 1.3f), f1 + f2},
61 {
Vector2dF(3.1f - 4.3f, 5.1f + 1.3f), f1 - f2}};
63 for (
size_t i = 0;
i <
size(float_tests); ++
i)
64 EXPECT_EQ(float_tests[
i].expected.ToString(),
65 float_tests[
i].actual.ToString());
68TEST(Vector2dTest, Negative) {
78 for (
size_t i = 0;
i <
size(int_tests); ++
i)
79 EXPECT_EQ(int_tests[
i].expected.ToString(), int_tests[
i].actual.ToString());
90 for (
size_t i = 0;
i <
size(float_tests); ++
i)
91 EXPECT_EQ(float_tests[
i].expected.ToString(),
92 float_tests[
i].actual.ToString());
96 float double_values[][4] = {
97 {4.5f, 1.2f, 3.3f, 5.6f}, {4.5f, -1.2f, 3.3f, 5.6f},
98 {4.5f, 1.2f, 3.3f, -5.6f}, {4.5f, 1.2f, -3.3f, -5.6f},
99 {-4.5f, 1.2f, 3.3f, 5.6f}, {-4.5f, 1.2f, 0, 5.6f},
100 {-4.5f, 1.2f, 3.3f, 0}, {4.5f, 0, 3.3f, 5.6f},
101 {0, 1.2f, 3.3f, 5.6f}};
103 for (
size_t i = 0;
i <
size(double_values); ++
i) {
104 Vector2dF v(double_values[
i][0], double_values[
i][1]);
105 v.
Scale(double_values[
i][2], double_values[
i][3]);
106 EXPECT_EQ(v.
x(), double_values[
i][0] * double_values[
i][2]);
107 EXPECT_EQ(v.
y(), double_values[
i][1] * double_values[
i][3]);
111 double_values[
i][2], double_values[
i][3]);
112 EXPECT_EQ(double_values[
i][0] * double_values[
i][2],
v2.x());
113 EXPECT_EQ(double_values[
i][1] * double_values[
i][3],
v2.y());
116 float single_values[][3] = {
117 {4.5f, 1.2f, 3.3f}, {4.5f, -1.2f, 3.3f}, {4.5f, 1.2f, 3.3f},
118 {4.5f, 1.2f, -3.3f}, {-4.5f, 1.2f, 3.3f}, {-4.5f, 1.2f, 0},
119 {-4.5f, 1.2f, 3.3f}, {4.5f, 0, 3.3f}, {0, 1.2f, 3.3f}};
121 for (
size_t i = 0;
i <
size(single_values); ++
i) {
122 Vector2dF v(single_values[
i][0], single_values[
i][1]);
123 v.
Scale(single_values[
i][2]);
124 EXPECT_EQ(v.
x(), single_values[
i][0] * single_values[
i][2]);
125 EXPECT_EQ(v.
y(), single_values[
i][1] * single_values[
i][2]);
129 double_values[
i][2]);
130 EXPECT_EQ(single_values[
i][0] * single_values[
i][2],
v2.x());
131 EXPECT_EQ(single_values[
i][1] * single_values[
i][2],
v2.y());
136 int int_values[][2] = {
137 {0, 0}, {10, 20}, {20, 10}, {-10, -20}, {-20, 10}, {10, -20},
140 for (
size_t i = 0;
i <
size(int_values); ++
i) {
141 int v0 = int_values[
i][0];
142 int v1 = int_values[
i][1];
143 double length_squared =
144 static_cast<double>(v0) * v0 +
static_cast<double>(v1) * v1;
147 EXPECT_EQ(
static_cast<float>(length_squared), vector.
LengthSquared());
151 float float_values[][2] = {
160 {1236278317862780234892374893213178027.12122348904204230f,
161 335890352589839028212313231225425134332.38123f},
164 for (
size_t i = 0;
i <
size(float_values); ++
i) {
165 double v0 = float_values[
i][0];
166 double v1 = float_values[
i][1];
167 double length_squared =
168 static_cast<double>(v0) * v0 +
static_cast<double>(v1) * v1;
172 EXPECT_FLOAT_EQ(
static_cast<float>(
length), vector.
Length());
176TEST(Vector2dTest, ClampVector2d) {
202TEST(Vector2dTest, ClampVector2dF) {
228TEST(Vector2dTest, IntegerOverflow) {
232 Vector2d max_vector(int_max, int_max);
233 Vector2d min_vector(int_min, int_min);
238 EXPECT_EQ(
test, max_vector);
242 EXPECT_EQ(
test, min_vector);
246 EXPECT_EQ(
test, max_vector);
250 EXPECT_EQ(
test, min_vector);
258 EXPECT_EQ(
test, max_vector);
262 EXPECT_EQ(
test, max_vector);
266 EXPECT_EQ(
test, min_vector);
constexpr float y() const
constexpr float x() const
double LengthSquared() const
int64_t LengthSquared() const
static float max(float r, float g, float b)
static float min(float r, float g, float b)
bool IsZero(char *begin, char *end)
Vector2dF ScaleVector2d(const Vector2dF &v, float x_scale, float y_scale)
constexpr size_t size(const T(&array)[N]) noexcept
TEST(PointTest, ToPointF)
static std::string ToString(CompilerBackend::Type type)
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
#define EXPECT_TRUE(handle)