Set strict warnings
This commit is contained in:
parent
5141766de5
commit
87d2c11ab6
@ -52,6 +52,13 @@ else()
|
||||
VectorAlgebra
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(VectorAlgebraTest PRIVATE /W4 /WX)
|
||||
else()
|
||||
target_compile_options(VectorAlgebraTest PRIVATE -Wall -Wextra -Wpedantic -Werror)
|
||||
endif()
|
||||
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(VectorAlgebraTest)
|
||||
endif()
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include "Angle.h"
|
||||
#include <math.h>
|
||||
|
||||
// 1-byte angle
|
||||
|
||||
template <> AngleUsing<unsigned char>::AngleUsing(unsigned char angle) {
|
||||
if (!isfinite(angle)) {
|
||||
value = 0;
|
||||
@ -21,11 +23,13 @@ template <> AngleUsing<unsigned char>::AngleUsing(unsigned char angle) {
|
||||
this->value = (unsigned char)((angle + 180.0F) / 360.0F * 255.0F);
|
||||
}
|
||||
|
||||
template <> float AngleUsing<unsigned char>::ToFloat() {
|
||||
template <> float AngleUsing<unsigned char>::ToFloat() const {
|
||||
float f = ((float)this->value / 255.0F) * 360.0F - 180.0F;
|
||||
return f;
|
||||
}
|
||||
|
||||
// 2-byte angle
|
||||
|
||||
template <> AngleUsing<unsigned short>::AngleUsing(unsigned short angle) {
|
||||
if (!isfinite(angle)) {
|
||||
value = 0;
|
||||
@ -40,7 +44,7 @@ template <> AngleUsing<unsigned short>::AngleUsing(unsigned short angle) {
|
||||
this->value = (unsigned short)((angle + 180.0F) / 360.0F * 65535.0F);
|
||||
}
|
||||
|
||||
template <> float AngleUsing<unsigned short>::ToFloat() {
|
||||
template <> float AngleUsing<unsigned short>::ToFloat() const {
|
||||
float f = ((float)this->value / 65535.0F) * 360.0F - 180.0F;
|
||||
return f;
|
||||
}
|
@ -8,17 +8,28 @@
|
||||
template <typename T> class AngleUsing {
|
||||
public:
|
||||
AngleUsing(T sourceValue);
|
||||
float ToFloat();
|
||||
inline T GetValue() { return this->value; }
|
||||
float ToFloat() const;
|
||||
inline T GetValue() const { return this->value; }
|
||||
|
||||
inline AngleUsing<T> operator-(AngleUsing<T> a) {
|
||||
inline AngleUsing<T> operator+(const AngleUsing<T> a) {
|
||||
return this->value + a.value;
|
||||
}
|
||||
|
||||
inline AngleUsing<T> operator+=(const AngleUsing<T> a &) {
|
||||
return this->value + a.value;
|
||||
}
|
||||
|
||||
inline AngleUsing<T> operator-(const AngleUsing<T> a) {
|
||||
return this->value - a.value;
|
||||
}
|
||||
|
||||
inline AngleUsing<T> operator-() { return -this->value; }
|
||||
inline bool operator==(const AngleUsing<T> a, const AngleUsing<T> b) {
|
||||
return a.value == b.value;
|
||||
}
|
||||
|
||||
protected:
|
||||
T value;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// template <typename T> inline float AngleUsing<T>::ToFloat() { return 0.0f; }
|
||||
|
4
Matrix.h
4
Matrix.h
@ -33,7 +33,7 @@ public:
|
||||
// Return a null matrix;
|
||||
// We dont set data to nullptr because it is allocated memory
|
||||
// Instead we write all zeros
|
||||
for (int dataIx = 0; dataIx < resultSize; dataIx++)
|
||||
for (unsigned int dataIx = 0; dataIx < resultSize; dataIx++)
|
||||
r->data[dataIx] = 0.0f;
|
||||
r->rows = 0;
|
||||
r->cols = 0;
|
||||
@ -43,7 +43,7 @@ public:
|
||||
r->cols = this->rows;
|
||||
r->rows = this->cols;
|
||||
|
||||
for (int rDataIx = 0; rDataIx < matrixSize; rDataIx++) {
|
||||
for (unsigned int rDataIx = 0; rDataIx < matrixSize; rDataIx++) {
|
||||
unsigned int rowIx = rDataIx / this->rows;
|
||||
unsigned int colIx = rDataIx % this->rows;
|
||||
unsigned int mDataIx = this->cols * colIx + rowIx;
|
||||
|
@ -18,7 +18,8 @@ TEST(MatrixSingle, Init) {
|
||||
MatrixOf<float> m2 = MatrixOf<float>(2, 2, data2);
|
||||
|
||||
// negative
|
||||
MatrixOf<float> m_1 = MatrixOf<float>(-1, -1);
|
||||
// MatrixOf<float> m_1 = MatrixOf<float>(-1, -1);
|
||||
// parameters are unsigned
|
||||
}
|
||||
|
||||
TEST(MatrixSingle, Transpose) {
|
||||
|
@ -99,8 +99,6 @@ TEST(Vector2, Normalize) {
|
||||
}
|
||||
|
||||
TEST(Vector2, Negate) {
|
||||
bool r = false;
|
||||
|
||||
Vector2 v1 = Vector2(4, 5);
|
||||
Vector2 v = Vector2::zero;
|
||||
|
||||
@ -129,8 +127,6 @@ TEST(Vector2, Negate) {
|
||||
}
|
||||
|
||||
TEST(Vector2, Subtract) {
|
||||
bool r = false;
|
||||
|
||||
Vector2 v1 = Vector2(4, 5);
|
||||
Vector2 v2 = Vector2(1, 2);
|
||||
Vector2 v = Vector2::zero;
|
||||
@ -164,11 +160,9 @@ TEST(Vector2, Subtract) {
|
||||
}
|
||||
|
||||
TEST(Vector2, Addition) {
|
||||
|
||||
Vector2 v1 = Vector2(4, 5);
|
||||
Vector2 v2 = Vector2(1, 2);
|
||||
Vector2 v = Vector2::zero;
|
||||
bool r = false;
|
||||
|
||||
v = v1 + v2;
|
||||
EXPECT_TRUE(v == Vector2(5, 7)) << "4 5 + 1 2";
|
||||
@ -195,8 +189,6 @@ TEST(Vector2, Addition) {
|
||||
}
|
||||
|
||||
TEST(Vector2, Scale) {
|
||||
bool r = false;
|
||||
|
||||
Vector2 v1 = Vector2(4, 5);
|
||||
Vector2 v2 = Vector2(1, 2);
|
||||
Vector2 v = Vector2::zero;
|
||||
@ -226,8 +218,6 @@ TEST(Vector2, Scale) {
|
||||
}
|
||||
|
||||
TEST(Vector2, Multiply) {
|
||||
bool r = false;
|
||||
|
||||
Vector2 v1 = Vector2(4, 5);
|
||||
float f = 3;
|
||||
Vector2 v = Vector2::zero;
|
||||
@ -257,8 +247,6 @@ TEST(Vector2, Multiply) {
|
||||
}
|
||||
|
||||
TEST(Vector2, Divide) {
|
||||
bool r = false;
|
||||
|
||||
Vector2 v1 = Vector2(4, 5);
|
||||
float f = 2;
|
||||
Vector2 v = Vector2::zero;
|
||||
|
@ -103,8 +103,6 @@ TEST(Vector3, Normalize) {
|
||||
}
|
||||
|
||||
TEST(Vector3, Negate) {
|
||||
bool r = false;
|
||||
|
||||
Vector3 v1 = Vector3(4, 5, 6);
|
||||
Vector3 v = Vector3::zero;
|
||||
|
||||
@ -133,8 +131,6 @@ TEST(Vector3, Negate) {
|
||||
}
|
||||
|
||||
TEST(Vector3, Subtract) {
|
||||
bool r = false;
|
||||
|
||||
Vector3 v1 = Vector3(4, 5, 6);
|
||||
Vector3 v2 = Vector3(1, 2, 3);
|
||||
Vector3 v = Vector3::zero;
|
||||
@ -168,11 +164,9 @@ TEST(Vector3, Subtract) {
|
||||
}
|
||||
|
||||
TEST(Vector3, Addition) {
|
||||
|
||||
Vector3 v1 = Vector3(4, 5, 6);
|
||||
Vector3 v2 = Vector3(1, 2, 3);
|
||||
Vector3 v = Vector3::zero;
|
||||
bool r = false;
|
||||
|
||||
v = v1 + v2;
|
||||
EXPECT_TRUE(v == Vector3(5, 7, 9)) << "4 5 6 + 1 2 3";
|
||||
@ -199,8 +193,6 @@ TEST(Vector3, Addition) {
|
||||
}
|
||||
|
||||
TEST(Vector3, Scale) {
|
||||
bool r = false;
|
||||
|
||||
Vector3 v1 = Vector3(4, 5, 6);
|
||||
Vector3 v2 = Vector3(1, 2, 3);
|
||||
Vector3 v = Vector3::zero;
|
||||
@ -230,8 +222,6 @@ TEST(Vector3, Scale) {
|
||||
}
|
||||
|
||||
TEST(Vector3, Multiply) {
|
||||
bool r = false;
|
||||
|
||||
Vector3 v1 = Vector3(4, 5, 6);
|
||||
float f = 3;
|
||||
Vector3 v = Vector3::zero;
|
||||
@ -261,8 +251,6 @@ TEST(Vector3, Multiply) {
|
||||
}
|
||||
|
||||
TEST(Vector3, Divide) {
|
||||
bool r = false;
|
||||
|
||||
Vector3 v1 = Vector3(4, 5, 6);
|
||||
float f = 2;
|
||||
Vector3 v = Vector3::zero;
|
||||
|
Loading…
x
Reference in New Issue
Block a user