diff --git a/include/keisan/angle/angle.hpp b/include/keisan/angle/angle.hpp index d46eed6..f802244 100644 --- a/include/keisan/angle/angle.hpp +++ b/include/keisan/angle/angle.hpp @@ -26,32 +26,32 @@ namespace keisan { -template +template using IfElseFloat = typename std::conditional::value, T, U>::type; // Forward declaration -template +template class Angle; -template +template Angle make_degree(const T & value); -template +template Angle make_radian(const T & value); -template +template Angle> arcsin(const T & value); -template +template Angle> arccos(const T & value); -template +template Angle> arctan(const T & value); -template +template Angle> signed_arctan(const T & y, const T & x); -template +template class Angle { public: - template + template friend class Angle; friend Angle make_degree(const T & value); @@ -63,7 +63,7 @@ class Angle explicit Angle(const T & data, const bool & is_degree = false); public: - template + template operator Angle() const; bool operator==(const Angle & angle) const; @@ -114,7 +114,7 @@ Angle operator""_pi_rad(long double value); } // namespace keisan -template +template keisan::Angle operator*(const U & value, const keisan::Angle & angle); #include "keisan/angle/angle.impl.hpp" diff --git a/include/keisan/angle/euler.hpp b/include/keisan/angle/euler.hpp index f480ef2..e2c6c30 100644 --- a/include/keisan/angle/euler.hpp +++ b/include/keisan/angle/euler.hpp @@ -29,16 +29,16 @@ namespace keisan { // Forward declaration -template +template struct Quaternion; -template +template struct Euler { Euler(); Euler(const Angle & roll, const Angle & pitch, const Angle & yaw); - template + template operator Euler() const; bool operator==(const Euler & other) const; @@ -53,7 +53,7 @@ struct Euler } // namespace keisan -template +template std::ostream & operator<<(std::ostream & out, const keisan::Euler & euler); #include "keisan/angle/euler.impl.hpp" diff --git a/include/keisan/angle/euler.impl.hpp b/include/keisan/angle/euler.impl.hpp index 96b6361..dce3f1d 100644 --- a/include/keisan/angle/euler.impl.hpp +++ b/include/keisan/angle/euler.impl.hpp @@ -24,7 +24,7 @@ #include "keisan/angle/quaternion.hpp" #include "keisan/constant.hpp" -template +template std::ostream & operator<<(std::ostream & out, const keisan::Euler & euler) { return out << euler.roll.degree() << " " << euler.pitch.degree() << " " << euler.yaw.degree(); @@ -33,37 +33,37 @@ std::ostream & operator<<(std::ostream & out, const keisan::Euler & euler) namespace keisan { -template +template Euler::Euler() { } -template +template Euler::Euler(const Angle & roll, const Angle & pitch, const Angle & yaw) : roll(roll), pitch(pitch), yaw(yaw) { } -template -template +template +template Euler::operator Euler() const { return Euler(roll, pitch, yaw); } -template +template bool Euler::operator==(const Euler & other) const { return roll == other.roll && yaw == other.yaw && pitch == other.pitch; } -template +template bool Euler::operator!=(const Euler & other) const { return roll != other.roll || yaw != other.yaw || pitch != other.pitch; } -template +template Quaternion Euler::quaternion() const { Quaternion quaternion; diff --git a/include/keisan/angle/quaternion.hpp b/include/keisan/angle/quaternion.hpp index 8d7b501..74ecf91 100644 --- a/include/keisan/angle/quaternion.hpp +++ b/include/keisan/angle/quaternion.hpp @@ -27,16 +27,16 @@ namespace keisan { // Forward declaration -template +template struct Euler; -template +template struct Quaternion { Quaternion(); Quaternion(const T & x, const T & y, const T & z, const T & w); - template + template operator Quaternion() const; bool operator==(const Quaternion & other) const; @@ -52,7 +52,7 @@ struct Quaternion } // namespace keisan -template +template std::ostream & operator<<(std::ostream & out, const keisan::Quaternion & quaternion); #include "keisan/angle/quaternion.impl.hpp" diff --git a/include/keisan/angle/quaternion.impl.hpp b/include/keisan/angle/quaternion.impl.hpp index 008a0d3..3419c35 100644 --- a/include/keisan/angle/quaternion.impl.hpp +++ b/include/keisan/angle/quaternion.impl.hpp @@ -26,7 +26,7 @@ using keisan::literals::operator""_pi; -template +template std::ostream & operator<<(std::ostream & out, const keisan::Quaternion & quaternion) { return out << quaternion.x << " " << quaternion.y << " " << quaternion.z << " " << quaternion.w; @@ -35,37 +35,37 @@ std::ostream & operator<<(std::ostream & out, const keisan::Quaternion & quat namespace keisan { -template +template Quaternion::Quaternion() { } -template +template Quaternion::Quaternion(const T & x, const T & y, const T & z, const T & w) : x(x), y(y), z(z), w(w) { } -template -template +template +template Quaternion::operator Quaternion() const { return Quaternion(x, y, z, w); } -template +template bool Quaternion::operator==(const Quaternion & other) const { return x == other.x && y == other.y && z == other.z && w == other.w; } -template +template bool Quaternion::operator!=(const Quaternion & other) const { return x != other.x || y != other.y || z != other.z || w != other.w; } -template +template Euler Quaternion::euler() const { Euler euler; diff --git a/include/keisan/constant.hpp b/include/keisan/constant.hpp index af302f1..35c2829 100644 --- a/include/keisan/constant.hpp +++ b/include/keisan/constant.hpp @@ -26,7 +26,7 @@ namespace keisan { -template +template const T pi = std::atan((T)1) * 4; namespace literals diff --git a/include/keisan/keisan.hpp b/include/keisan/keisan.hpp index 5037704..38eacaa 100644 --- a/include/keisan/keisan.hpp +++ b/include/keisan/keisan.hpp @@ -21,11 +21,10 @@ #ifndef KEISAN__KEISAN_HPP_ #define KEISAN__KEISAN_HPP_ -#include "keisan/geometry/point_2.hpp" -#include "keisan/geometry/point_3.hpp" - #include "keisan/angle.hpp" #include "keisan/constant.hpp" +#include "keisan/geometry/point_2.hpp" +#include "keisan/geometry/point_3.hpp" #include "keisan/matrix.hpp" #include "keisan/number.hpp" diff --git a/include/keisan/matrix/matrix.hpp b/include/keisan/matrix/matrix.hpp index 08f1cc1..ec38554 100644 --- a/include/keisan/matrix/matrix.hpp +++ b/include/keisan/matrix/matrix.hpp @@ -32,14 +32,14 @@ namespace keisan { -template +template class Matrix { public: Matrix(); - template - explicit Matrix(const double & value, Types ... the_rest); + template + explicit Matrix(const double & value, Types... the_rest); Matrix(const Matrix & matrix); @@ -59,7 +59,7 @@ class Matrix Matrix & operator*=(const double & value); Matrix & operator/=(const double & value); - template + template Matrix operator*(const Matrix & matrix); Vector operator*(const Vector & vector); @@ -93,10 +93,10 @@ Matrix<4, 4> rotation_matrix(const Euler & angle); } // namespace keisan -template +template std::ostream & operator<<(std::ostream & out, const keisan::Matrix & matrix); -template +template keisan::Matrix operator*(const double & value, const keisan::Matrix & matrix); #include "keisan/matrix/matrix.impl.hpp" diff --git a/include/keisan/matrix/matrix.impl.hpp b/include/keisan/matrix/matrix.impl.hpp index 57d06f0..91630b6 100644 --- a/include/keisan/matrix/matrix.impl.hpp +++ b/include/keisan/matrix/matrix.impl.hpp @@ -27,7 +27,7 @@ #include "gtest/gtest.h" #include "keisan/matrix/matrix.hpp" -template +template std::ostream & operator<<(std::ostream & out, const keisan::Matrix & matrix) { out << "["; @@ -53,7 +53,7 @@ std::ostream & operator<<(std::ostream & out, const keisan::Matrix & matri return out; } -template +template inline keisan::Matrix operator*(const double & value, const keisan::Matrix & matrix) { return matrix * value; @@ -62,25 +62,24 @@ inline keisan::Matrix operator*(const double & value, const keisan::Matrix namespace keisan { -template +template Matrix::Matrix() { } -template -template -Matrix::Matrix(const double & value, Types ... the_rest) -: data{value, the_rest ...} +template +template +Matrix::Matrix(const double & value, Types... the_rest) : data{value, the_rest...} { } -template +template Matrix::Matrix(const Matrix & matrix) { *this = matrix; } -template +template Matrix Matrix::zero() { Matrix matrix; @@ -93,7 +92,7 @@ Matrix Matrix::zero() return matrix; } -template +template Matrix Matrix::identity() { static_assert( @@ -111,14 +110,14 @@ Matrix Matrix::identity() return matrix; } -template +template Matrix & Matrix::operator=(const Matrix & matrix) { std::copy(matrix.data, matrix.data + M * N, data); return *this; } -template +template bool Matrix::operator==(const Matrix & matrix) const { using testing::internal::FloatingPoint; @@ -131,13 +130,13 @@ bool Matrix::operator==(const Matrix & matrix) const return true; } -template +template bool Matrix::operator!=(const Matrix & matrix) const { return !(*this == matrix); } -template +template Matrix & Matrix::operator+=(const Matrix & matrix) { for (size_t i = 0; i < M * N; ++i) { @@ -147,7 +146,7 @@ Matrix & Matrix::operator+=(const Matrix & matrix) return *this; } -template +template Matrix & Matrix::operator-=(const Matrix & matrix) { for (size_t i = 0; i < M * N; ++i) { @@ -157,7 +156,7 @@ Matrix & Matrix::operator-=(const Matrix & matrix) return *this; } -template +template Matrix & Matrix::operator+=(const double & value) { for (size_t i = 0; i < M * N; ++i) { @@ -167,7 +166,7 @@ Matrix & Matrix::operator+=(const double & value) return *this; } -template +template Matrix & Matrix::operator-=(const double & value) { for (size_t i = 0; i < M * N; ++i) { @@ -177,7 +176,7 @@ Matrix & Matrix::operator-=(const double & value) return *this; } -template +template Matrix & Matrix::operator*=(const double & value) { for (size_t i = 0; i < M * N; ++i) { @@ -187,7 +186,7 @@ Matrix & Matrix::operator*=(const double & value) return *this; } -template +template Matrix & Matrix::operator/=(const double & value) { for (size_t i = 0; i < M * N; ++i) { @@ -197,9 +196,8 @@ Matrix & Matrix::operator/=(const double & value) return *this; } - -template -template +template +template Matrix Matrix::operator*(const Matrix & matrix) { Matrix new_matrix; @@ -215,7 +213,7 @@ Matrix Matrix::operator*(const Matrix & matrix) return new_matrix; } -template +template Vector Matrix::operator*(const Vector & vector) { Vector new_vector; @@ -229,7 +227,7 @@ Vector Matrix::operator*(const Vector & vector) return new_vector; } -template +template Matrix Matrix::operator+(const Matrix & matrix) const { auto new_matrix = *this; @@ -238,7 +236,7 @@ Matrix Matrix::operator+(const Matrix & matrix) const return new_matrix; } -template +template Matrix Matrix::operator-(const Matrix & matrix) const { auto new_matrix = *this; @@ -247,7 +245,7 @@ Matrix Matrix::operator-(const Matrix & matrix) const return new_matrix; } -template +template Matrix Matrix::operator+(const double & value) const { auto new_matrix = *this; @@ -256,7 +254,7 @@ Matrix Matrix::operator+(const double & value) const return new_matrix; } -template +template Matrix Matrix::operator-(const double & value) const { auto new_matrix = *this; @@ -265,7 +263,7 @@ Matrix Matrix::operator-(const double & value) const return new_matrix; } -template +template Matrix Matrix::operator*(const double & value) const { auto new_matrix = *this; @@ -274,7 +272,7 @@ Matrix Matrix::operator*(const double & value) const return new_matrix; } -template +template Matrix Matrix::operator/(const double & value) const { auto new_matrix = *this; @@ -283,7 +281,7 @@ Matrix Matrix::operator/(const double & value) const return new_matrix; } -template +template Matrix Matrix::operator-() const { Matrix matrix; @@ -294,19 +292,19 @@ Matrix Matrix::operator-() const return matrix; } -template +template double * Matrix::operator[](size_t pos) { return data + (pos * N); } -template +template const double * Matrix::operator[](size_t pos) const { return data + (pos * N); } -template +template bool Matrix::inverse() { static_assert( @@ -314,127 +312,93 @@ bool Matrix::inverse() "The dimensions of matrix are not matched. " "There is no inverse matrix for non-square matrix!"); - static_assert( - M == 4, - "Inverse matrix operation only available for 4 by 4 matrix."); + static_assert(M == 4, "Inverse matrix operation only available for 4 by 4 matrix."); auto inverse = Matrix::zero(); auto source = *this; - inverse[0][0] = source[1][1] * source[2][2] * source[3][3] - - source[1][1] * source[2][3] * source[3][2] - - source[2][1] * source[1][2] * source[3][3] + - source[2][1] * source[1][3] * source[3][2] + - source[3][1] * source[1][2] * source[2][3] - - source[3][1] * source[1][3] * source[2][2]; - - inverse[1][0] = -source[1][0] * source[2][2] * source[3][3] + - source[1][0] * source[2][3] * source[3][2] + - source[2][0] * source[1][2] * source[3][3] - - source[2][0] * source[1][3] * source[3][2] - - source[3][0] * source[1][2] * source[2][3] + - source[3][0] * source[1][3] * source[2][2]; - - inverse[2][0] = source[1][0] * source[2][1] * source[3][3] - - source[1][0] * source[2][3] * source[3][1] - - source[2][0] * source[1][1] * source[3][3] + - source[2][0] * source[1][3] * source[3][1] + - source[3][0] * source[1][1] * source[2][3] - - source[3][0] * source[1][3] * source[2][1]; - - inverse[3][0] = -source[1][0] * source[2][1] * source[3][2] + - source[1][0] * source[2][2] * source[3][1] + - source[2][0] * source[1][1] * source[3][2] - - source[2][0] * source[1][2] * source[3][1] - - source[3][0] * source[1][1] * source[2][2] + - source[3][0] * source[1][2] * source[2][1]; - - inverse[0][1] = -source[0][1] * source[2][2] * source[3][3] + - source[0][1] * source[2][3] * source[3][2] + - source[2][1] * source[0][2] * source[3][3] - - source[2][1] * source[0][3] * source[3][2] - - source[3][1] * source[0][2] * source[2][3] + - source[3][1] * source[0][3] * source[2][2]; - - inverse[1][1] = source[0][0] * source[2][2] * source[3][3] - - source[0][0] * source[2][3] * source[3][2] - - source[2][0] * source[0][2] * source[3][3] + - source[2][0] * source[0][3] * source[3][2] + - source[3][0] * source[0][2] * source[2][3] - - source[3][0] * source[0][3] * source[2][2]; - - inverse[2][1] = -source[0][0] * source[2][1] * source[3][3] + - source[0][0] * source[2][3] * source[3][1] + - source[2][0] * source[0][1] * source[3][3] - - source[2][0] * source[0][3] * source[3][1] - - source[3][0] * source[0][1] * source[2][3] + - source[3][0] * source[0][3] * source[2][1]; - - inverse[3][1] = source[0][0] * source[2][1] * source[3][2] - - source[0][0] * source[2][2] * source[3][1] - - source[2][0] * source[0][1] * source[3][2] + - source[2][0] * source[0][2] * source[3][1] + - source[3][0] * source[0][1] * source[2][2] - - source[3][0] * source[0][2] * source[2][1]; - - inverse[0][2] = source[0][1] * source[1][2] * source[3][3] - - source[0][1] * source[1][3] * source[3][2] - - source[1][1] * source[0][2] * source[3][3] + - source[1][1] * source[0][3] * source[3][2] + - source[3][1] * source[0][2] * source[1][3] - - source[3][1] * source[0][3] * source[1][2]; - - inverse[1][2] = -source[0][0] * source[1][2] * source[3][3] + - source[0][0] * source[1][3] * source[3][2] + - source[1][0] * source[0][2] * source[3][3] - - source[1][0] * source[0][3] * source[3][2] - - source[3][0] * source[0][2] * source[1][3] + - source[3][0] * source[0][3] * source[1][2]; - - inverse[2][2] = source[0][0] * source[1][1] * source[3][3] - - source[0][0] * source[1][3] * source[3][1] - - source[1][0] * source[0][1] * source[3][3] + - source[1][0] * source[0][3] * source[3][1] + - source[3][0] * source[0][1] * source[1][3] - - source[3][0] * source[0][3] * source[1][1]; - - inverse[3][2] = -source[0][0] * source[1][1] * source[3][2] + - source[0][0] * source[1][2] * source[3][1] + - source[1][0] * source[0][1] * source[3][2] - - source[1][0] * source[0][2] * source[3][1] - - source[3][0] * source[0][1] * source[1][2] + - source[3][0] * source[0][2] * source[1][1]; - - inverse[0][3] = -source[0][1] * source[1][2] * source[2][3] + - source[0][1] * source[1][3] * source[2][2] + - source[1][1] * source[0][2] * source[2][3] - - source[1][1] * source[0][3] * source[2][2] - - source[2][1] * source[0][2] * source[1][3] + - source[2][1] * source[0][3] * source[1][2]; - - inverse[1][3] = source[0][0] * source[1][2] * source[2][3] - - source[0][0] * source[1][3] * source[2][2] - - source[1][0] * source[0][2] * source[2][3] + - source[1][0] * source[0][3] * source[2][2] + - source[2][0] * source[0][2] * source[1][3] - - source[2][0] * source[0][3] * source[1][2]; - - inverse[2][3] = -source[0][0] * source[1][1] * source[2][3] + - source[0][0] * source[1][3] * source[2][1] + - source[1][0] * source[0][1] * source[2][3] - - source[1][0] * source[0][3] * source[2][1] - - source[2][0] * source[0][1] * source[1][3] + - source[2][0] * source[0][3] * source[1][1]; - - inverse[3][3] = source[0][0] * source[1][1] * source[2][2] - - source[0][0] * source[1][2] * source[2][1] - - source[1][0] * source[0][1] * source[2][2] + - source[1][0] * source[0][2] * source[2][1] + - source[2][0] * source[0][1] * source[1][2] - - source[2][0] * source[0][2] * source[1][1]; + inverse[0][0] = + source[1][1] * source[2][2] * source[3][3] - source[1][1] * source[2][3] * source[3][2] - + source[2][1] * source[1][2] * source[3][3] + source[2][1] * source[1][3] * source[3][2] + + source[3][1] * source[1][2] * source[2][3] - source[3][1] * source[1][3] * source[2][2]; + + inverse[1][0] = + -source[1][0] * source[2][2] * source[3][3] + source[1][0] * source[2][3] * source[3][2] + + source[2][0] * source[1][2] * source[3][3] - source[2][0] * source[1][3] * source[3][2] - + source[3][0] * source[1][2] * source[2][3] + source[3][0] * source[1][3] * source[2][2]; + + inverse[2][0] = + source[1][0] * source[2][1] * source[3][3] - source[1][0] * source[2][3] * source[3][1] - + source[2][0] * source[1][1] * source[3][3] + source[2][0] * source[1][3] * source[3][1] + + source[3][0] * source[1][1] * source[2][3] - source[3][0] * source[1][3] * source[2][1]; + + inverse[3][0] = + -source[1][0] * source[2][1] * source[3][2] + source[1][0] * source[2][2] * source[3][1] + + source[2][0] * source[1][1] * source[3][2] - source[2][0] * source[1][2] * source[3][1] - + source[3][0] * source[1][1] * source[2][2] + source[3][0] * source[1][2] * source[2][1]; + + inverse[0][1] = + -source[0][1] * source[2][2] * source[3][3] + source[0][1] * source[2][3] * source[3][2] + + source[2][1] * source[0][2] * source[3][3] - source[2][1] * source[0][3] * source[3][2] - + source[3][1] * source[0][2] * source[2][3] + source[3][1] * source[0][3] * source[2][2]; + + inverse[1][1] = + source[0][0] * source[2][2] * source[3][3] - source[0][0] * source[2][3] * source[3][2] - + source[2][0] * source[0][2] * source[3][3] + source[2][0] * source[0][3] * source[3][2] + + source[3][0] * source[0][2] * source[2][3] - source[3][0] * source[0][3] * source[2][2]; + + inverse[2][1] = + -source[0][0] * source[2][1] * source[3][3] + source[0][0] * source[2][3] * source[3][1] + + source[2][0] * source[0][1] * source[3][3] - source[2][0] * source[0][3] * source[3][1] - + source[3][0] * source[0][1] * source[2][3] + source[3][0] * source[0][3] * source[2][1]; + + inverse[3][1] = + source[0][0] * source[2][1] * source[3][2] - source[0][0] * source[2][2] * source[3][1] - + source[2][0] * source[0][1] * source[3][2] + source[2][0] * source[0][2] * source[3][1] + + source[3][0] * source[0][1] * source[2][2] - source[3][0] * source[0][2] * source[2][1]; + + inverse[0][2] = + source[0][1] * source[1][2] * source[3][3] - source[0][1] * source[1][3] * source[3][2] - + source[1][1] * source[0][2] * source[3][3] + source[1][1] * source[0][3] * source[3][2] + + source[3][1] * source[0][2] * source[1][3] - source[3][1] * source[0][3] * source[1][2]; + + inverse[1][2] = + -source[0][0] * source[1][2] * source[3][3] + source[0][0] * source[1][3] * source[3][2] + + source[1][0] * source[0][2] * source[3][3] - source[1][0] * source[0][3] * source[3][2] - + source[3][0] * source[0][2] * source[1][3] + source[3][0] * source[0][3] * source[1][2]; + + inverse[2][2] = + source[0][0] * source[1][1] * source[3][3] - source[0][0] * source[1][3] * source[3][1] - + source[1][0] * source[0][1] * source[3][3] + source[1][0] * source[0][3] * source[3][1] + + source[3][0] * source[0][1] * source[1][3] - source[3][0] * source[0][3] * source[1][1]; + + inverse[3][2] = + -source[0][0] * source[1][1] * source[3][2] + source[0][0] * source[1][2] * source[3][1] + + source[1][0] * source[0][1] * source[3][2] - source[1][0] * source[0][2] * source[3][1] - + source[3][0] * source[0][1] * source[1][2] + source[3][0] * source[0][2] * source[1][1]; + + inverse[0][3] = + -source[0][1] * source[1][2] * source[2][3] + source[0][1] * source[1][3] * source[2][2] + + source[1][1] * source[0][2] * source[2][3] - source[1][1] * source[0][3] * source[2][2] - + source[2][1] * source[0][2] * source[1][3] + source[2][1] * source[0][3] * source[1][2]; + + inverse[1][3] = + source[0][0] * source[1][2] * source[2][3] - source[0][0] * source[1][3] * source[2][2] - + source[1][0] * source[0][2] * source[2][3] + source[1][0] * source[0][3] * source[2][2] + + source[2][0] * source[0][2] * source[1][3] - source[2][0] * source[0][3] * source[1][2]; + + inverse[2][3] = + -source[0][0] * source[1][1] * source[2][3] + source[0][0] * source[1][3] * source[2][1] + + source[1][0] * source[0][1] * source[2][3] - source[1][0] * source[0][3] * source[2][1] - + source[2][0] * source[0][1] * source[1][3] + source[2][0] * source[0][3] * source[1][1]; + + inverse[3][3] = + source[0][0] * source[1][1] * source[2][2] - source[0][0] * source[1][2] * source[2][1] - + source[1][0] * source[0][1] * source[2][2] + source[1][0] * source[0][2] * source[2][1] + + source[2][0] * source[0][1] * source[1][2] - source[2][0] * source[0][2] * source[1][1]; double determinant = source[0][0] * inverse[0][0] + source[0][1] * inverse[1][0] + - source[0][2] * inverse[2][0] + source[0][3] * inverse[3][0]; + source[0][2] * inverse[2][0] + source[0][3] * inverse[3][0]; if (determinant == 0) { return false; diff --git a/include/keisan/matrix/vector.hpp b/include/keisan/matrix/vector.hpp index 746ffa7..1122883 100644 --- a/include/keisan/matrix/vector.hpp +++ b/include/keisan/matrix/vector.hpp @@ -26,14 +26,14 @@ namespace keisan { -template +template class Vector { public: Vector(); - template - explicit Vector(const double & value, Types ... the_rest); + template + explicit Vector(const double & value, Types... the_rest); Vector(const Vector & vector); @@ -71,10 +71,10 @@ class Vector } // namespace keisan -template +template std::ostream & operator<<(std::ostream & out, const keisan::Vector & vector); -template +template keisan::Vector operator*(const double & value, const keisan::Vector & vector); #include "keisan/matrix/vector.impl.hpp" diff --git a/include/keisan/matrix/vector.impl.hpp b/include/keisan/matrix/vector.impl.hpp index 3f3b570..9dc93f0 100644 --- a/include/keisan/matrix/vector.impl.hpp +++ b/include/keisan/matrix/vector.impl.hpp @@ -27,7 +27,7 @@ #include "gtest/gtest.h" #include "keisan/matrix/vector.hpp" -template +template std::ostream & operator<<(std::ostream & out, const keisan::Vector & vector) { out << "["; @@ -44,7 +44,7 @@ std::ostream & operator<<(std::ostream & out, const keisan::Vector & vector) return out; } -template +template inline keisan::Vector operator*(const double & value, const keisan::Vector & vector) { return vector * value; @@ -53,25 +53,24 @@ inline keisan::Vector operator*(const double & value, const keisan::Vector namespace keisan { -template +template Vector::Vector() { } -template -template -Vector::Vector(const double & value, Types ... the_rest) -: data{value, the_rest ...} +template +template +Vector::Vector(const double & value, Types... the_rest) : data{value, the_rest...} { } -template +template Vector::Vector(const Vector & vector) { *this = vector; } -template +template Vector Vector::zero() { Vector vector; @@ -82,14 +81,14 @@ Vector Vector::zero() return vector; } -template +template Vector & Vector::operator=(const Vector & vector) { std::copy(vector.data, vector.data + N, data); return *this; } -template +template bool Vector::operator==(const Vector & vector) const { using testing::internal::FloatingPoint; @@ -102,13 +101,13 @@ bool Vector::operator==(const Vector & vector) const return true; } -template +template bool Vector::operator!=(const Vector & vector) const { return !(*this == vector); } -template +template Vector & Vector::operator+=(const Vector & vector) { for (size_t i = 0; i < N; ++i) { @@ -118,7 +117,7 @@ Vector & Vector::operator+=(const Vector & vector) return *this; } -template +template Vector & Vector::operator-=(const Vector & vector) { for (size_t i = 0; i < N; ++i) { @@ -128,7 +127,7 @@ Vector & Vector::operator-=(const Vector & vector) return *this; } -template +template Vector & Vector::operator+=(const double & value) { for (size_t i = 0; i < N; ++i) { @@ -138,7 +137,7 @@ Vector & Vector::operator+=(const double & value) return *this; } -template +template Vector & Vector::operator-=(const double & value) { for (size_t i = 0; i < N; ++i) { @@ -148,7 +147,7 @@ Vector & Vector::operator-=(const double & value) return *this; } -template +template Vector & Vector::operator*=(const double & value) { for (size_t i = 0; i < N; ++i) { @@ -158,7 +157,7 @@ Vector & Vector::operator*=(const double & value) return *this; } -template +template Vector & Vector::operator/=(const double & value) { for (size_t i = 0; i < N; ++i) { @@ -168,7 +167,7 @@ Vector & Vector::operator/=(const double & value) return *this; } -template +template Vector Vector::operator+(const Vector & vector) const { auto new_vector = *this; @@ -177,7 +176,7 @@ Vector Vector::operator+(const Vector & vector) const return new_vector; } -template +template Vector Vector::operator-(const Vector & vector) const { auto new_vector = *this; @@ -186,7 +185,7 @@ Vector Vector::operator-(const Vector & vector) const return new_vector; } -template +template Vector Vector::operator+(const double & value) const { auto new_vector = *this; @@ -195,7 +194,7 @@ Vector Vector::operator+(const double & value) const return new_vector; } -template +template Vector Vector::operator-(const double & value) const { auto new_vector = *this; @@ -204,7 +203,7 @@ Vector Vector::operator-(const double & value) const return new_vector; } -template +template Vector Vector::operator*(const double & value) const { auto new_vector = *this; @@ -213,7 +212,7 @@ Vector Vector::operator*(const double & value) const return new_vector; } -template +template Vector Vector::operator/(const double & value) const { auto new_vector = *this; @@ -221,7 +220,7 @@ Vector Vector::operator/(const double & value) const return new_vector; } -template +template Vector Vector::operator-() const { Vector vector; @@ -232,13 +231,13 @@ Vector Vector::operator-() const return vector; } -template +template double & Vector::operator[](size_t pos) { return data[pos]; } -template +template const double & Vector::operator[](size_t pos) const { return data[pos]; diff --git a/include/keisan/number.hpp b/include/keisan/number.hpp index ddbbf0c..cce2332 100644 --- a/include/keisan/number.hpp +++ b/include/keisan/number.hpp @@ -26,58 +26,58 @@ namespace keisan { -template +template class Angle; -template +template using enable_if_is_integral = std::enable_if_t::value, bool>; -template +template using enable_if_is_floating_point = std::enable_if_t::value, bool>; -template +template T sign(const T & value); -template +template T sign(const Angle & value); -template +template T scale(const T & value, const T & source, const T & target); -template +template T map( - const T & value, const T & source_min, const T & source_max, - const T & target_min, const T & target_max); + const T & value, const T & source_min, const T & source_max, const T & target_min, + const T & target_max); -template +template T exponentialmap( - const T & value, const T & source_min, const T & source_max, - const T & target_min, const T & target_max); + const T & value, const T & source_min, const T & source_max, const T & target_min, + const T & target_max); -template +template T sinusoidalmap( - const T & value, const T & source_min, const T & source_max, - const T & target_min, const T & target_max); + const T & value, const T & source_min, const T & source_max, const T & target_min, + const T & target_max); -template +template T clamp(const T & value, const T & min, const T & max); -template +template Angle clamp(const Angle & value, const Angle & min, const Angle & max); -template = true> +template = true> T wrap(const T & value, const T & min, const T & max); -template = true> +template = true> T wrap(const T & value, const T & min, const T & max); -template +template T smooth(T value, T target, T ratio); -template +template T curve(const T & value, const T & min, const T & max, const T & exponential); -template +template T lerp(const T & start, const T & end, const T & rate); } // namespace keisan diff --git a/include/keisan/number.impl.hpp b/include/keisan/number.impl.hpp index 0f11741..0793ff3 100644 --- a/include/keisan/number.impl.hpp +++ b/include/keisan/number.impl.hpp @@ -30,28 +30,28 @@ namespace keisan { -template +template T sign(const T & value) { return (value >= 0) ? 1 : -1; } -template +template T sign(const Angle & value) { return (value >= make_degree(0)) ? 1.0 : -1.0; } -template +template T scale(const T & value, const T & source, const T & target) { return value / source * target; } -template +template T map( - const T & value, const T & source_min, const T & source_max, - const T & target_min, const T & target_max) + const T & value, const T & source_min, const T & source_max, const T & target_min, + const T & target_max) { auto source_val = value; source_val = std::min(source_val, std::max(source_min, source_max)); @@ -61,39 +61,40 @@ T map( scale(source_val - source_min, source_max - source_min, target_max - target_min); } -template +template T exponentialmap( - const T & value, const T & source_min, const T & source_max, - const T & target_min, const T & target_max) + const T & value, const T & source_min, const T & source_max, const T & target_min, + const T & target_max) { auto source_val = value; source_val = std::min(source_val, std::max(source_min, source_max)); source_val = std::max(source_val, std::min(source_min, source_max)); auto map_coeff = (target_min <= target_max) ? 1 : -1; auto normalized_val = (source_val - source_min) / (source_max - source_min); - return map_coeff * std::pow(std::abs(target_max - target_min + map_coeff), normalized_val) + target_min - map_coeff; + return map_coeff * std::pow(std::abs(target_max - target_min + map_coeff), normalized_val) + + target_min - map_coeff; } -template +template T sinusoidalmap( - const T & value, const T & source_min, const T & source_max, - const T & target_min, const T & target_max) + const T & value, const T & source_min, const T & source_max, const T & target_min, + const T & target_max) { auto source_val = value; source_val = std::min(source_val, std::max(source_min, source_max)); source_val = std::max(source_val, std::min(source_min, source_max)); auto coeff = -(target_max - target_min) / 2; - auto angle = (M_PI * (source_min - source_val)) / (source_min - source_max); + auto angle = (M_PI * (source_min - source_val)) / (source_min - source_max); return coeff * std::cos(angle) + (target_max + target_min) / 2; } -template +template T clamp(const T & value, const T & min, const T & max) { return std::min(std::max(value, min), max); } -template +template Angle clamp(const Angle & value, const Angle & min, const Angle & max) { if (value < min) { @@ -107,7 +108,7 @@ Angle clamp(const Angle & value, const Angle & min, const Angle & ma return value; } -template = true> +template = true> T wrap(const T & value, const T & min, const T & max) { auto min_value = value - min; @@ -116,7 +117,7 @@ T wrap(const T & value, const T & min, const T & max) return min + std::fmod(min_max + std::fmod(min_value, min_max), min_max); } -template = true> +template = true> T wrap(const T & value, const T & min, const T & max) { auto min_value = value - min; @@ -125,23 +126,24 @@ T wrap(const T & value, const T & min, const T & max) return min + (min_max + min_value % min_max) % min_max; } -template +template T smooth(T value, T target, T ratio) { return ((1.0 - ratio) * value) + (ratio * target); } -template +template T curve(const T & value, const T & min, const T & max, const T & exponential) { if (min == max) { return min; } auto val = clamp(value, min, max); - return min + ((max - min) * (std::pow(val - min, exponential) / std::pow(max - min, exponential))); + return min + + ((max - min) * (std::pow(val - min, exponential) / std::pow(max - min, exponential))); } -template +template T lerp(const T & start, const T & end, const T & rate) { return (start + ((end - start) * rate)); diff --git a/src/angle/angle.cpp b/src/angle/angle.cpp index ab97cde..dbfd504 100644 --- a/src/angle/angle.cpp +++ b/src/angle/angle.cpp @@ -31,10 +31,7 @@ Angle operator""_deg(unsigned long long int value) // NOLINT return make_degree(value); } -Angle operator""_deg(long double value) -{ - return make_degree(value); -} +Angle operator""_deg(long double value) { return make_degree(value); } Angle operator""_pi_rad(unsigned long long int value) // NOLINT { diff --git a/src/constant.cpp b/src/constant.cpp index 8fc5c98..c181b2a 100644 --- a/src/constant.cpp +++ b/src/constant.cpp @@ -31,10 +31,7 @@ double operator""_pi(unsigned long long int value) // NOLINT return value * keisan::pi; } -double operator""_pi(long double value) -{ - return value * keisan::pi; -} +double operator""_pi(long double value) { return value * keisan::pi; } } // namespace literals diff --git a/src/geometry/point_2.cpp b/src/geometry/point_2.cpp index cb1b010..35814e8 100644 --- a/src/geometry/point_2.cpp +++ b/src/geometry/point_2.cpp @@ -18,10 +18,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include "keisan/geometry/point_2.hpp" + #include #include "keisan/angle.hpp" -#include "keisan/geometry/point_2.hpp" keisan::Point2 operator*(const double & value, const keisan::Point2 & point) { @@ -31,47 +32,21 @@ keisan::Point2 operator*(const double & value, const keisan::Point2 & point) namespace keisan { -Point2::Point2() -{ -} +Point2::Point2() {} -Point2::Point2(double x, double y) -: x(x), - y(y) -{ -} +Point2::Point2(double x, double y) : x(x), y(y) {} -Point2::Point2(const Vector<2> & vector) -: x(vector[0]), - y(vector[1]) -{ -} +Point2::Point2(const Vector<2> & vector) : x(vector[0]), y(vector[1]) {} -Point2::Point2(const Vector<3> & vector) -: x(vector[0] / vector[2]), - y(vector[1] / vector[2]) -{ -} +Point2::Point2(const Vector<3> & vector) : x(vector[0] / vector[2]), y(vector[1] / vector[2]) {} -Point2::Point2(const Point2 & point) -{ - *this = point; -} +Point2::Point2(const Point2 & point) { *this = point; } -Point2::operator Vector<2>() const -{ - return Vector<2>(x, y); -} +Point2::operator Vector<2>() const { return Vector<2>(x, y); } -Point2::operator Vector<3>() const -{ - return Vector<3>(x, y, 1.0); -} +Point2::operator Vector<3>() const { return Vector<3>(x, y, 1.0); } -Point2 Point2::zero() -{ - return Point2(0.0, 0.0); -} +Point2 Point2::zero() { return Point2(0.0, 0.0); } Point2 & Point2::operator=(const Point2 & point) { @@ -81,15 +56,9 @@ Point2 & Point2::operator=(const Point2 & point) return *this; } -bool Point2::operator==(const Point2 & other) const -{ - return x == other.x && y == other.y; -} +bool Point2::operator==(const Point2 & other) const { return x == other.x && y == other.y; } -bool Point2::operator!=(const Point2 & other) const -{ - return x != other.x || y != other.y; -} +bool Point2::operator!=(const Point2 & other) const { return x != other.x || y != other.y; } Point2 & Point2::operator+=(const Point2 & other) { @@ -139,50 +108,23 @@ Point2 & Point2::operator/=(const double & value) return *this; } -Point2 Point2::operator+(const Point2 & other) const -{ - return Point2(x + other.x, y + other.y); -} +Point2 Point2::operator+(const Point2 & other) const { return Point2(x + other.x, y + other.y); } -Point2 Point2::operator-(const Point2 & other) const -{ - return Point2(x - other.x, y - other.y); -} +Point2 Point2::operator-(const Point2 & other) const { return Point2(x - other.x, y - other.y); } -Point2 Point2::operator+(const double & value) const -{ - return Point2(x + value, y + value); -} +Point2 Point2::operator+(const double & value) const { return Point2(x + value, y + value); } -Point2 Point2::operator-(const double & value) const -{ - return Point2(x - value, y - value); -} +Point2 Point2::operator-(const double & value) const { return Point2(x - value, y - value); } -Point2 Point2::operator*(const double & value) const -{ - return Point2(x * value, y * value); -} +Point2 Point2::operator*(const double & value) const { return Point2(x * value, y * value); } -Point2 Point2::operator/(const double & value) const -{ - return Point2(x / value, y / value); -} +Point2 Point2::operator/(const double & value) const { return Point2(x / value, y / value); } -Point2 Point2::operator-() const -{ - return Point2(-x, -y); -} +Point2 Point2::operator-() const { return Point2(-x, -y); } -double Point2::magnitude() const -{ - return std::hypot(x, y); -} +double Point2::magnitude() const { return std::hypot(x, y); } -Angle Point2::direction() const -{ - return signed_arctan(y, x); -} +Angle Point2::direction() const { return signed_arctan(y, x); } Point2 Point2::normalize() const { @@ -190,30 +132,15 @@ Point2 Point2::normalize() const return Point2(x / mag, y / mag); } -double Point2::dot(const Point2 & other) const -{ - return x * other.x + y * other.y; -} +double Point2::dot(const Point2 & other) const { return x * other.x + y * other.y; } -double Point2::cross(const Point2 & other) const -{ - return x * other.y - y * other.x; -} +double Point2::cross(const Point2 & other) const { return x * other.y - y * other.x; } -Point2 Point2::translate(const Point2 & translation) const -{ - return *this + translation; -} +Point2 Point2::translate(const Point2 & translation) const { return *this + translation; } -Point2 Point2::scale(const Point2 & scaling) const -{ - return Point2(x * scaling.x, y * scaling.y); -} +Point2 Point2::scale(const Point2 & scaling) const { return Point2(x * scaling.x, y * scaling.y); } -Point2 Point2::scale(const double & scaling) const -{ - return scale({scaling, scaling}); -} +Point2 Point2::scale(const double & scaling) const { return scale({scaling, scaling}); } Point2 Point2::rotate(const Angle & rotation) const { diff --git a/src/geometry/point_3.cpp b/src/geometry/point_3.cpp index f331542..dd57045 100644 --- a/src/geometry/point_3.cpp +++ b/src/geometry/point_3.cpp @@ -18,10 +18,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include "keisan/geometry/point_3.hpp" + #include #include "keisan/angle.hpp" -#include "keisan/geometry/point_3.hpp" std::ostream & operator<<(std::ostream & out, const keisan::Point3 point) { @@ -36,50 +37,24 @@ keisan::Point3 operator*(const double & value, const keisan::Point3 & point) namespace keisan { -Point3::Point3() -{ -} +Point3::Point3() {} -Point3::Point3(double x, double y, double z) -: x(x), - y(y), - z(z) -{ -} +Point3::Point3(double x, double y, double z) : x(x), y(y), z(z) {} -Point3::Point3(const Vector<3> & vector) -: x(vector[0]), - y(vector[1]), - z(vector[2]) -{ -} +Point3::Point3(const Vector<3> & vector) : x(vector[0]), y(vector[1]), z(vector[2]) {} Point3::Point3(const Vector<4> & vector) -: x(vector[0] / vector[3]), - y(vector[1] / vector[3]), - z(vector[2] / vector[3]) +: x(vector[0] / vector[3]), y(vector[1] / vector[3]), z(vector[2] / vector[3]) { } -Point3::Point3(const Point3 & point) -{ - *this = point; -} +Point3::Point3(const Point3 & point) { *this = point; } -Point3::operator Vector<3>() const -{ - return Vector<3>(x, y, z); -} +Point3::operator Vector<3>() const { return Vector<3>(x, y, z); } -Point3::operator Vector<4>() const -{ - return Vector<4>(x, y, z, 1.0); -} +Point3::operator Vector<4>() const { return Vector<4>(x, y, z, 1.0); } -Point3 Point3::zero() -{ - return Point3(0.0, 0.0, 0.0); -} +Point3 Point3::zero() { return Point3(0.0, 0.0, 0.0); } Point3 & Point3::operator=(const Point3 & point) { @@ -184,15 +159,9 @@ Point3 Point3::operator/(const double & value) const return Point3(x / value, y / value, z / value); } -Point3 Point3::operator-() const -{ - return Point3(-x, -y, -z); -} +Point3 Point3::operator-() const { return Point3(-x, -y, -z); } -double Point3::magnitude() const -{ - return std::hypot(std::hypot(x, y), z); -} +double Point3::magnitude() const { return std::hypot(std::hypot(x, y), z); } Point3 Point3::normalize() const { @@ -201,17 +170,11 @@ Point3 Point3::normalize() const return Point3(x / mag, y / mag, z / mag); } -double Point3::dot(const Point3 & other) const -{ - return x * other.x + y * other.y + z * other.z; -} +double Point3::dot(const Point3 & other) const { return x * other.x + y * other.y + z * other.z; } Point3 Point3::cross(const Point3 & other) const { - return Point3( - y * other.z - z * other.y, - z * other.x - x * other.z, - x * other.y - y * other.x); + return Point3(y * other.z - z * other.y, z * other.x - x * other.z, x * other.y - y * other.x); } } // namespace keisan diff --git a/test/angle/angle_test.cpp b/test/angle/angle_test.cpp index 3ae585d..a166cec 100644 --- a/test/angle/angle_test.cpp +++ b/test/angle/angle_test.cpp @@ -98,25 +98,22 @@ TEST(AngleTest, Empty) TEST(AngleTest, AssignmentConstructor) { - #define EXPECT_CONVERSION_CONSTRUCTOR(TYPE, SOURCE) \ - { \ - ksn::Angle a(SOURCE), b = SOURCE, c; \ - c = SOURCE; \ - EXPECT_DOUBLE_EQ(a.degree(), SOURCE.degree()); \ - EXPECT_DOUBLE_EQ(b.degree(), SOURCE.degree()); \ - EXPECT_DOUBLE_EQ(c.degree(), SOURCE.degree()); \ +#define EXPECT_CONVERSION_CONSTRUCTOR(TYPE, SOURCE) \ + { \ + ksn::Angle a(SOURCE), b = SOURCE, c; \ + c = SOURCE; \ + EXPECT_DOUBLE_EQ(a.degree(), SOURCE.degree()); \ + EXPECT_DOUBLE_EQ(b.degree(), SOURCE.degree()); \ + EXPECT_DOUBLE_EQ(c.degree(), SOURCE.degree()); \ } auto float_angle = ksn::make_degree(90.0f); auto double_angle = ksn::make_degree(-45.0); auto long_double_angle = ksn::make_degree(15.0l); - #define LOOP_EXPECT_CONVERSION_CONSTRUCTOR(TYPE) \ - { \ - EXPECT_CONVERSION_CONSTRUCTOR(TYPE, float_angle) \ - EXPECT_CONVERSION_CONSTRUCTOR(TYPE, double_angle) \ - EXPECT_CONVERSION_CONSTRUCTOR(TYPE, long_double_angle) \ - } +#define LOOP_EXPECT_CONVERSION_CONSTRUCTOR(TYPE) \ + {EXPECT_CONVERSION_CONSTRUCTOR(TYPE, float_angle) EXPECT_CONVERSION_CONSTRUCTOR( \ + TYPE, double_angle) EXPECT_CONVERSION_CONSTRUCTOR(TYPE, long_double_angle)} LOOP_EXPECT_CONVERSION_CONSTRUCTOR(float) LOOP_EXPECT_CONVERSION_CONSTRUCTOR(double) @@ -129,9 +126,8 @@ TEST(AngleTest, ComparisonOperator) auto b = -180_deg; auto c = -1_pi_rad; - EXPECT_TRUE(b == c && a != c) << - "-180 == -1pi\n" - "90 != -1pi"; + EXPECT_TRUE(b == c && a != c) << "-180 == -1pi\n" + "90 != -1pi"; EXPECT_TRUE(a > b && a >= b && a >= a) << "90 > -180"; EXPECT_TRUE(b < a && b <= a && b <= b) << "-180 < 90"; diff --git a/test/angle/euler_test.cpp b/test/angle/euler_test.cpp index c231b25..9f7e6c1 100644 --- a/test/angle/euler_test.cpp +++ b/test/angle/euler_test.cpp @@ -33,42 +33,35 @@ TEST(EulerTest, Empty) ksn::Euler long_double_euler; } -TEST(EulerTest, RpyConstructor) -{ - #define EXPECT_RPY_CONSTRUCTOR(TYPE) \ - { \ +TEST(EulerTest, RpyConstructor){ +#define EXPECT_RPY_CONSTRUCTOR(TYPE) \ + { \ ksn::Euler euler(0_deg, 90_deg, 180_deg); \ - EXPECT_DOUBLE_EQ(euler.roll.degree(), 0.0); \ - EXPECT_DOUBLE_EQ(euler.pitch.degree(), 90.0); \ - EXPECT_DOUBLE_EQ(euler.yaw.degree(), 180.0); \ + EXPECT_DOUBLE_EQ(euler.roll.degree(), 0.0); \ + EXPECT_DOUBLE_EQ(euler.pitch.degree(), 90.0); \ + EXPECT_DOUBLE_EQ(euler.yaw.degree(), 180.0); \ } - EXPECT_RPY_CONSTRUCTOR(float) - EXPECT_RPY_CONSTRUCTOR(double) - EXPECT_RPY_CONSTRUCTOR(long double) -} + EXPECT_RPY_CONSTRUCTOR(float) EXPECT_RPY_CONSTRUCTOR(double) EXPECT_RPY_CONSTRUCTOR(long double)} TEST(EulerTest, AssignmentConstructor) { - #define EXPECT_CONVERSION_CONSTRUCTOR(TYPE, SOURCE) \ - { \ - ksn::Euler a(SOURCE), b = SOURCE, c; \ - c = SOURCE; \ - EXPECT_TRUE(a == SOURCE); \ - EXPECT_TRUE(b == SOURCE); \ - EXPECT_TRUE(c == SOURCE); \ +#define EXPECT_CONVERSION_CONSTRUCTOR(TYPE, SOURCE) \ + { \ + ksn::Euler a(SOURCE), b = SOURCE, c; \ + c = SOURCE; \ + EXPECT_TRUE(a == SOURCE); \ + EXPECT_TRUE(b == SOURCE); \ + EXPECT_TRUE(c == SOURCE); \ } ksn::Euler float_euler(90_deg, 90_deg, 90_deg); ksn::Euler double_euler(-45_deg, -45_deg, -45_deg); ksn::Euler long_double_euler(15_deg, 15_deg, 15_deg); - #define LOOP_EXPECT_CONVERSION_CONSTRUCTOR(TYPE) \ - { \ - EXPECT_CONVERSION_CONSTRUCTOR(TYPE, float_euler) \ - EXPECT_CONVERSION_CONSTRUCTOR(TYPE, double_euler) \ - EXPECT_CONVERSION_CONSTRUCTOR(TYPE, long_double_euler) \ - } +#define LOOP_EXPECT_CONVERSION_CONSTRUCTOR(TYPE) \ + {EXPECT_CONVERSION_CONSTRUCTOR(TYPE, float_euler) EXPECT_CONVERSION_CONSTRUCTOR( \ + TYPE, double_euler) EXPECT_CONVERSION_CONSTRUCTOR(TYPE, long_double_euler)} LOOP_EXPECT_CONVERSION_CONSTRUCTOR(float) LOOP_EXPECT_CONVERSION_CONSTRUCTOR(double) diff --git a/test/angle/quaternion_test.cpp b/test/angle/quaternion_test.cpp index 08f4d9d..8542028 100644 --- a/test/angle/quaternion_test.cpp +++ b/test/angle/quaternion_test.cpp @@ -30,50 +30,45 @@ TEST(QuaternionTest, Empty) ksn::Quaternion long_double_quaternion; } -TEST(QuaternionTest, XyzwConstructor) -{ - #define EXPECT_XYZW_CONSTRUCTOR(TYPE) \ - { \ +TEST(QuaternionTest, XyzwConstructor){ +#define EXPECT_XYZW_CONSTRUCTOR(TYPE) \ + { \ ksn::Quaternion quaternion(1.0, 0.5, 0.0, -0.5); \ - EXPECT_DOUBLE_EQ(quaternion.x, 1.0); \ - EXPECT_DOUBLE_EQ(quaternion.y, 0.5); \ - EXPECT_DOUBLE_EQ(quaternion.z, 0.0); \ - EXPECT_DOUBLE_EQ(quaternion.w, -0.5); \ + EXPECT_DOUBLE_EQ(quaternion.x, 1.0); \ + EXPECT_DOUBLE_EQ(quaternion.y, 0.5); \ + EXPECT_DOUBLE_EQ(quaternion.z, 0.0); \ + EXPECT_DOUBLE_EQ(quaternion.w, -0.5); \ } - EXPECT_XYZW_CONSTRUCTOR(float) - EXPECT_XYZW_CONSTRUCTOR(double) - EXPECT_XYZW_CONSTRUCTOR(long double) -} + EXPECT_XYZW_CONSTRUCTOR(float) EXPECT_XYZW_CONSTRUCTOR(double) + EXPECT_XYZW_CONSTRUCTOR(long double)} TEST(QuaternionTest, AssignmentConstructor) { - #define EXPECT_CONVERSION_CONSTRUCTOR(TYPE, SOURCE) \ - { \ +#define EXPECT_CONVERSION_CONSTRUCTOR(TYPE, SOURCE) \ + { \ ksn::Quaternion a(SOURCE), b = SOURCE, c; \ - c = SOURCE; \ - EXPECT_TRUE(a == SOURCE); \ - EXPECT_TRUE(b == SOURCE); \ - EXPECT_TRUE(c == SOURCE); \ + c = SOURCE; \ + EXPECT_TRUE(a == SOURCE); \ + EXPECT_TRUE(b == SOURCE); \ + EXPECT_TRUE(c == SOURCE); \ } ksn::Quaternion float_quaternion(1.0f, 1.0f, 1.0f, 1.0f); ksn::Quaternion double_quaternion(0.5, 0.5, 0.5, 0.5); ksn::Quaternion long_double_quaternion(-0.5l, -0.5l, -0.5l, -0.5l); - #define LOOP_EXPECT_CONVERSION_CONSTRUCTOR(TYPE) \ - { \ - EXPECT_CONVERSION_CONSTRUCTOR(TYPE, float_quaternion) \ - EXPECT_CONVERSION_CONSTRUCTOR(TYPE, double_quaternion) \ - EXPECT_CONVERSION_CONSTRUCTOR(TYPE, long_double_quaternion) \ - } +#define LOOP_EXPECT_CONVERSION_CONSTRUCTOR(TYPE) \ + {EXPECT_CONVERSION_CONSTRUCTOR(TYPE, float_quaternion) EXPECT_CONVERSION_CONSTRUCTOR( \ + TYPE, double_quaternion) EXPECT_CONVERSION_CONSTRUCTOR(TYPE, long_double_quaternion)} LOOP_EXPECT_CONVERSION_CONSTRUCTOR(float) LOOP_EXPECT_CONVERSION_CONSTRUCTOR(double) LOOP_EXPECT_CONVERSION_CONSTRUCTOR(long double) } -TEST(QuaternionTest, ComparisonOperator) { +TEST(QuaternionTest, ComparisonOperator) +{ ksn::Quaternion a(1.0, 0.5, 0.0, -0.5); auto b = a; diff --git a/test/comparison/almost_equal.hpp b/test/comparison/almost_equal.hpp index 1813258..90500d9 100644 --- a/test/comparison/almost_equal.hpp +++ b/test/comparison/almost_equal.hpp @@ -26,7 +26,7 @@ namespace testing { -template +template bool almost_equal(const T & a, const T & b) { return internal::FloatingPoint(a).AlmostEquals(internal::FloatingPoint(b)); diff --git a/test/comparison/point_2.hpp b/test/comparison/point_2.hpp index a33cfdf..bac8940 100644 --- a/test/comparison/point_2.hpp +++ b/test/comparison/point_2.hpp @@ -24,9 +24,8 @@ #include #include -#include "keisan/keisan.hpp" - #include "./almost_equal.hpp" +#include "keisan/keisan.hpp" namespace testing { @@ -34,31 +33,28 @@ namespace testing std::string point2_print_string(const keisan::Point2 & point) { std::stringstream ss; - ss << std::setprecision(std::numeric_limits::digits10 + 2) << - "{" << point.x << ", " << point.y << "}"; + ss << std::setprecision(std::numeric_limits::digits10 + 2) << "{" << point.x << ", " + << point.y << "}"; return internal::StringStreamToString(&ss); } AssertionResult point2_equal( - const char * lhs_expression, const char * rhs_expression, - const keisan::Point2 & lhs_value, const keisan::Point2 & rhs_value) + const char * lhs_expression, const char * rhs_expression, const keisan::Point2 & lhs_value, + const keisan::Point2 & rhs_value) { if (almost_equal(lhs_value.x, rhs_value.x) && almost_equal(lhs_value.y, rhs_value.y)) { return AssertionSuccess(); } return internal::EqFailure( - lhs_expression, rhs_expression, - point2_print_string(lhs_value), point2_print_string(rhs_value), + lhs_expression, rhs_expression, point2_print_string(lhs_value), point2_print_string(rhs_value), false); } -#define EXPECT_POINT2_EQ(val1, val2) \ - EXPECT_PRED_FORMAT2(testing::point2_equal, val1, val2) +#define EXPECT_POINT2_EQ(val1, val2) EXPECT_PRED_FORMAT2(testing::point2_equal, val1, val2) -#define ASSERT_POINT2_EQ(val1, val2) \ - ASSERT_PRED_FORMAT2(testing::point2_equal, val1, val2) +#define ASSERT_POINT2_EQ(val1, val2) ASSERT_PRED_FORMAT2(testing::point2_equal, val1, val2) } // namespace testing diff --git a/test/comparison/point_3.hpp b/test/comparison/point_3.hpp index 8b6d57b..83be421 100644 --- a/test/comparison/point_3.hpp +++ b/test/comparison/point_3.hpp @@ -24,9 +24,8 @@ #include #include -#include "keisan/keisan.hpp" - #include "./almost_equal.hpp" +#include "keisan/keisan.hpp" namespace testing { @@ -34,15 +33,15 @@ namespace testing std::string point3_print_string(const keisan::Point3 & point) { std::stringstream ss; - ss << std::setprecision(std::numeric_limits::digits10 + 2) << - "{" << point.x << ", " << point.y << ", " << point.z << "}"; + ss << std::setprecision(std::numeric_limits::digits10 + 2) << "{" << point.x << ", " + << point.y << ", " << point.z << "}"; return internal::StringStreamToString(&ss); } AssertionResult point3_equal( - const char * lhs_expression, const char * rhs_expression, - const keisan::Point3 & lhs_value, const keisan::Point3 & rhs_value) + const char * lhs_expression, const char * rhs_expression, const keisan::Point3 & lhs_value, + const keisan::Point3 & rhs_value) { if (almost_equal(lhs_value.x, rhs_value.x)) { if (almost_equal(lhs_value.y, rhs_value.y)) { @@ -53,16 +52,13 @@ AssertionResult point3_equal( } return internal::EqFailure( - lhs_expression, rhs_expression, - point3_print_string(lhs_value), point3_print_string(rhs_value), + lhs_expression, rhs_expression, point3_print_string(lhs_value), point3_print_string(rhs_value), false); } -#define EXPECT_POINT3_EQ(val1, val2) \ - EXPECT_PRED_FORMAT2(testing::point3_equal, val1, val2) +#define EXPECT_POINT3_EQ(val1, val2) EXPECT_PRED_FORMAT2(testing::point3_equal, val1, val2) -#define ASSERT_POINT3_EQ(val1, val2) \ - ASSERT_PRED_FORMAT2(testing::point3_equal, val1, val2) +#define ASSERT_POINT3_EQ(val1, val2) ASSERT_PRED_FORMAT2(testing::point3_equal, val1, val2) } // namespace testing diff --git a/test/geometry/point_2_test.cpp b/test/geometry/point_2_test.cpp index 8a6e822..2b4d158 100644 --- a/test/geometry/point_2_test.cpp +++ b/test/geometry/point_2_test.cpp @@ -167,6 +167,5 @@ TEST(Point2Test, Rotation) auto point = ksn::Point2(4.0, 3.0); EXPECT_POINT2_EQ(point.rotate(ksn::make_degree(90.0)), ksn::Point2(-3.0, 4.0)); - EXPECT_POINT2_EQ( - point.rotate_from(ksn::make_degree(90.0), {1.0, -1.0}), ksn::Point2(-3.0, 2.0)); + EXPECT_POINT2_EQ(point.rotate_from(ksn::make_degree(90.0), {1.0, -1.0}), ksn::Point2(-3.0, 2.0)); } diff --git a/test/matrix/matrix_inverse_test.cpp b/test/matrix/matrix_inverse_test.cpp index 51f843a..34d4805 100644 --- a/test/matrix/matrix_inverse_test.cpp +++ b/test/matrix/matrix_inverse_test.cpp @@ -36,18 +36,15 @@ struct matrix_3d_inverse_args class MatrixInverseTest : public ::testing::TestWithParam { protected: - MatrixInverseTest() - : matrix(std::make_shared>(GetParam().origin)) - { - } + MatrixInverseTest() : matrix(std::make_shared>(GetParam().origin)) {} testing::AssertionResult do_test() { auto params = GetParam(); if (matrix->inverse() != params.is_invertible) { - return testing::AssertionFailure() << "the invertible check is failed, matrix is " << - (params.is_invertible ? "not" : "") << " invertible"; + return testing::AssertionFailure() << "the invertible check is failed, matrix is " + << (params.is_invertible ? "not" : "") << " invertible"; } if (((*matrix) == params.inverse) != params.is_valid) { @@ -60,100 +57,45 @@ class MatrixInverseTest : public ::testing::TestWithParam> matrix; }; -TEST_P(MatrixInverseTest, Inverse) -{ - EXPECT_TRUE(do_test()); -} +TEST_P(MatrixInverseTest, Inverse) { EXPECT_TRUE(do_test()); } matrix_3d_inverse_args test_case_1 = { - ksn::Matrix<4, 4>( - 1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0), - ksn::Matrix<4, 4>( - 1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0), - true, - true -}; + ksn::Matrix<4, 4>(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0), + ksn::Matrix<4, 4>(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0), + true, true}; matrix_3d_inverse_args test_case_2 = { - ksn::Matrix<4, 4>( - 1.0, 0.0, 0.0, 1.0, - 0.0, 1.0, 1.0, 0.0, - 0.0, 1.0, 1.0, 0.0, - 1.0, 0.0, 0.0, 1.0), - ksn::Matrix<4, 4>::zero(), - false, - false -}; + ksn::Matrix<4, 4>(1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0), + ksn::Matrix<4, 4>::zero(), false, false}; matrix_3d_inverse_args test_case_3 = { + ksn::Matrix<4, 4>(1.0, 1.0, 1.0, 1.0, 1.0, 5.0, 3.0, 0.0, 1.0, 1.0, 6.0, 1.0, 1.0, 1.0, 1.0, 0.0), ksn::Matrix<4, 4>( - 1.0, 1.0, 1.0, 1.0, - 1.0, 5.0, 3.0, 0.0, - 1.0, 1.0, 6.0, 1.0, - 1.0, 1.0, 1.0, 0.0), - ksn::Matrix<4, 4>( - 1.0 / 10.0, -1.0 / 4.0, -1.0 / 10.0, 5.0 / 4.0, - 1.0 / 10.0, 1.0 / 4.0, -1.0 / 10.0, -1.0 / 4.0, - -1.0 / 5.0, 0.0, 1.0 / 5.0, 0.0, - 1.0, 0.0, 0.0, -1.0), - true, - true -}; + 1.0 / 10.0, -1.0 / 4.0, -1.0 / 10.0, 5.0 / 4.0, 1.0 / 10.0, 1.0 / 4.0, -1.0 / 10.0, -1.0 / 4.0, + -1.0 / 5.0, 0.0, 1.0 / 5.0, 0.0, 1.0, 0.0, 0.0, -1.0), + true, true}; matrix_3d_inverse_args test_case_4 = { + ksn::Matrix<4, 4>(1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 3.0, 0.0, 0.0, 1.0, 6.0, 1.0, 8.0, 1.0, 1.0, 0.0), ksn::Matrix<4, 4>( - 1.0, 1.0, 1.0, 1.0, - 1.0, 0.0, 3.0, 0.0, - 0.0, 1.0, 6.0, 1.0, - 8.0, 1.0, 1.0, 0.0), - ksn::Matrix<4, 4>( - 3.0 / 8.0, 5.0 / 8.0, -3.0 / 8.0, 0.0, - -23.0 / 8.0, -41.0 / 8.0, 23.0 / 8.0, 1.0, - -1.0 / 8.0, 1.0 / 8.0, 1.0 / 8.0, 0.0, - 29.0 / 8.0, 35.0 / 8.0, -21.0 / 8.0, -1.0), - true, - true -}; + 3.0 / 8.0, 5.0 / 8.0, -3.0 / 8.0, 0.0, -23.0 / 8.0, -41.0 / 8.0, 23.0 / 8.0, 1.0, -1.0 / 8.0, + 1.0 / 8.0, 1.0 / 8.0, 0.0, 29.0 / 8.0, 35.0 / 8.0, -21.0 / 8.0, -1.0), + true, true}; matrix_3d_inverse_args test_case_5 = { + ksn::Matrix<4, 4>(1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 3.0, 0.0, 0.0, 1.0, 6.0, 1.0, 8.0, 1.0, 1.0, 0.0), ksn::Matrix<4, 4>( - 1.0, 1.0, 1.0, 1.0, - 1.0, 0.0, 3.0, 0.0, - 0.0, 1.0, 6.0, 1.0, - 8.0, 1.0, 1.0, 0.0), - ksn::Matrix<4, 4>( - 3.0 / 8.0, 5.0 / 8.0, -3.0 / 8.0, 0.0, - -23.0 / 8.0, -41.0 / 8.0, 23.0 / 8.0, 1.0, - -1.0 / 8.0, 1.0 / 8.0, 1.0 / 8.0, 0.0, - 29.0 / 8.0, 35.0 / 8.0, -21.0 / 8.0, 0.0), - true, - false -}; + 3.0 / 8.0, 5.0 / 8.0, -3.0 / 8.0, 0.0, -23.0 / 8.0, -41.0 / 8.0, 23.0 / 8.0, 1.0, -1.0 / 8.0, + 1.0 / 8.0, 1.0 / 8.0, 0.0, 29.0 / 8.0, 35.0 / 8.0, -21.0 / 8.0, 0.0), + true, false}; matrix_3d_inverse_args test_case_6 = { + ksn::Matrix<4, 4>(1.0, 1.0, 2.0, 1.0, 1.0, 0.0, 3.0, 0.0, 0.0, 1.0, 6.0, 1.0, 8.0, 1.0, 3.0, 0.0), ksn::Matrix<4, 4>( - 1.0, 1.0, 2.0, 1.0, - 1.0, 0.0, 3.0, 0.0, - 0.0, 1.0, 6.0, 1.0, - 8.0, 1.0, 3.0, 0.0), - ksn::Matrix<4, 4>( - 3.0 / 7.0, 4.0 / 7.0, -3.0 / 7.0, 0.0, - -21.0 / 7.0, -35.0 / 7.0, 21.0 / 7.0, 1.0, - -1.0 / 7.0, 1.0 / 7.0, 1.0 / 7.0, 0.0, - 27.0 / 7.0, 29.0 / 7.0, -20.0 / 7.0, -1.0), - true, - true -}; + 3.0 / 7.0, 4.0 / 7.0, -3.0 / 7.0, 0.0, -21.0 / 7.0, -35.0 / 7.0, 21.0 / 7.0, 1.0, -1.0 / 7.0, + 1.0 / 7.0, 1.0 / 7.0, 0.0, 27.0 / 7.0, 29.0 / 7.0, -20.0 / 7.0, -1.0), + true, true}; INSTANTIATE_TEST_CASE_P( - InverseTest, - MatrixInverseTest, - testing::Values( - test_case_1, test_case_2, test_case_3, - test_case_4, test_case_5, test_case_6)); + InverseTest, MatrixInverseTest, + testing::Values(test_case_1, test_case_2, test_case_3, test_case_4, test_case_5, test_case_6)); diff --git a/test/matrix/matrix_test.cpp b/test/matrix/matrix_test.cpp index 90f8dd7..e87311f 100644 --- a/test/matrix/matrix_test.cpp +++ b/test/matrix/matrix_test.cpp @@ -23,25 +23,22 @@ #include "gtest/gtest.h" #include "keisan/keisan.hpp" -#define ASSERT_MATRIX_M_N_EQ(M, N, MATRIX, ...) \ - { \ - ksn::Matrix _matrix = MATRIX; \ - double _values[] = {__VA_ARGS__}; \ - for (size_t i = 0; i < M; ++i) { \ - for (size_t j = 0; j < N; ++j) { \ +#define ASSERT_MATRIX_M_N_EQ(M, N, MATRIX, ...) \ + { \ + ksn::Matrix _matrix = MATRIX; \ + double _values[] = {__VA_ARGS__}; \ + for (size_t i = 0; i < M; ++i) { \ + for (size_t j = 0; j < N; ++j) { \ ASSERT_DOUBLE_EQ(_values[i * N + j], _matrix[i][j]); \ - } \ - } \ + } \ + } \ } namespace ksn = keisan; TEST(MatrixTest, OutStream) { - auto a = ksn::Matrix<3, 4>( - 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, - 3.0, 3.0, 3.0, 3.0); + auto a = ksn::Matrix<3, 4>(1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0); std::stringstream ss; ss << a; @@ -54,16 +51,9 @@ TEST(MatrixTest, InitialValue) auto a = ksn::Matrix<2, 1>(1.0, 2.0); ASSERT_MATRIX_M_N_EQ(2, 1, a, 1.0, 2.0); - auto b = ksn::Matrix<3, 4>( - 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, - 3.0, 3.0, 3.0, 3.0); + auto b = ksn::Matrix<3, 4>(1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0); - ASSERT_MATRIX_M_N_EQ( - 3, 4, b, - 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, - 3.0, 3.0, 3.0, 3.0); + ASSERT_MATRIX_M_N_EQ(3, 4, b, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0); } TEST(MatrixTest, ZeroValue) @@ -72,38 +62,24 @@ TEST(MatrixTest, ZeroValue) ASSERT_MATRIX_M_N_EQ(2, 1, a, 0.0, 0.0); auto b = ksn::Matrix<3, 4>::zero(); - ASSERT_MATRIX_M_N_EQ( - 3, 4, b, - 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0); + ASSERT_MATRIX_M_N_EQ(3, 4, b, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); } TEST(MatrixTest, Identity) { auto a = ksn::Matrix<2, 2>::identity(); - ASSERT_MATRIX_M_N_EQ( - 2, 2, a, - 1.0, 0.0, - 0.0, 1.0); + ASSERT_MATRIX_M_N_EQ(2, 2, a, 1.0, 0.0, 0.0, 1.0); auto b = ksn::Matrix<4, 4>::identity(); ASSERT_MATRIX_M_N_EQ( - 4, 4, b, - 1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0); + 4, 4, b, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0); } TEST(MatrixTest, ComparisonOperation) { - auto a = ksn::Matrix<3, 4>( - 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, - 3.0, 3.0, 3.0, 3.0); + auto a = ksn::Matrix<3, 4>(1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0); auto b = a; @@ -118,137 +94,63 @@ TEST(MatrixTest, ComparisonOperation) TEST(MatrixTest, MatrixMultiplication) { - auto a = ksn::Matrix<3, 2>( - 1.0, 1.0, - 2.0, 2.0, - 3.0, 3.0); + auto a = ksn::Matrix<3, 2>(1.0, 1.0, 2.0, 2.0, 3.0, 3.0); - auto b = ksn::Matrix<2, 2>( - 1.0, 1.0, - 2.0, 2.0); + auto b = ksn::Matrix<2, 2>(1.0, 1.0, 2.0, 2.0); - ASSERT_MATRIX_M_N_EQ( - 3, 2, a * b, - 3.0, 3.0, - 6.0, 6.0, - 9.0, 9.0); + ASSERT_MATRIX_M_N_EQ(3, 2, a * b, 3.0, 3.0, 6.0, 6.0, 9.0, 9.0); } TEST(MatrixTest, MatrixOperation) { - auto a = ksn::Matrix<3, 4>( - 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, - 3.0, 3.0, 3.0, 3.0); + auto a = ksn::Matrix<3, 4>(1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0); - auto b = ksn::Matrix<3, 4>( - 1.0, 2.0, 3.0, 4.0, - 1.0, 2.0, 3.0, 4.0, - 1.0, 2.0, 3.0, 4.0); + auto b = ksn::Matrix<3, 4>(1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0); - ASSERT_MATRIX_M_N_EQ( - 3, 4, a + b, - 2.0, 3.0, 4.0, 5.0, - 3.0, 4.0, 5.0, 6.0, - 4.0, 5.0, 6.0, 7.0); + ASSERT_MATRIX_M_N_EQ(3, 4, a + b, 2.0, 3.0, 4.0, 5.0, 3.0, 4.0, 5.0, 6.0, 4.0, 5.0, 6.0, 7.0); ASSERT_MATRIX_M_N_EQ( - 3, 4, a - b, - 0.0, -1.0, -2.0, -3.0, - 1.0, 0.0, -1.0, -2.0, - 2.0, 1.0, 0.0, -1.0); + 3, 4, a - b, 0.0, -1.0, -2.0, -3.0, 1.0, 0.0, -1.0, -2.0, 2.0, 1.0, 0.0, -1.0); a += b; - ASSERT_MATRIX_M_N_EQ( - 3, 4, a, - 2.0, 3.0, 4.0, 5.0, - 3.0, 4.0, 5.0, 6.0, - 4.0, 5.0, 6.0, 7.0); + ASSERT_MATRIX_M_N_EQ(3, 4, a, 2.0, 3.0, 4.0, 5.0, 3.0, 4.0, 5.0, 6.0, 4.0, 5.0, 6.0, 7.0); a -= b; - ASSERT_MATRIX_M_N_EQ( - 3, 4, a, - 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, - 3.0, 3.0, 3.0, 3.0); + ASSERT_MATRIX_M_N_EQ(3, 4, a, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0); } TEST(MatrixTest, ScalarOperation) { - auto a = ksn::Matrix<3, 4>( - 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, - 3.0, 3.0, 3.0, 3.0); + auto a = ksn::Matrix<3, 4>(1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0); - ASSERT_MATRIX_M_N_EQ( - 3, 4, a + 2.0, - 3.0, 3.0, 3.0, 3.0, - 4.0, 4.0, 4.0, 4.0, - 5.0, 5.0, 5.0, 5.0); + ASSERT_MATRIX_M_N_EQ(3, 4, a + 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 4.0, 5.0, 5.0, 5.0, 5.0); ASSERT_MATRIX_M_N_EQ( - 3, 4, a - 2.0, - -1.0, -1.0, -1.0, -1.0, - 0.0, 0.0, 0.0, 0.0, - 1.0, 1.0, 1.0, 1.0); + 3, 4, a - 2.0, -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0); - ASSERT_MATRIX_M_N_EQ( - 3, 4, a * 2.0, - 2.0, 2.0, 2.0, 2.0, - 4.0, 4.0, 4.0, 4.0, - 6.0, 6.0, 6.0, 6.0); + ASSERT_MATRIX_M_N_EQ(3, 4, a * 2.0, 2.0, 2.0, 2.0, 2.0, 4.0, 4.0, 4.0, 4.0, 6.0, 6.0, 6.0, 6.0); - ASSERT_MATRIX_M_N_EQ( - 3, 4, 2.0 * a, - 2.0, 2.0, 2.0, 2.0, - 4.0, 4.0, 4.0, 4.0, - 6.0, 6.0, 6.0, 6.0); + ASSERT_MATRIX_M_N_EQ(3, 4, 2.0 * a, 2.0, 2.0, 2.0, 2.0, 4.0, 4.0, 4.0, 4.0, 6.0, 6.0, 6.0, 6.0); - ASSERT_MATRIX_M_N_EQ( - 3, 4, a / 2.0, - 0.5, 0.5, 0.5, 0.5, - 1.0, 1.0, 1.0, 1.0, - 1.5, 1.5, 1.5, 1.5); + ASSERT_MATRIX_M_N_EQ(3, 4, a / 2.0, 0.5, 0.5, 0.5, 0.5, 1.0, 1.0, 1.0, 1.0, 1.5, 1.5, 1.5, 1.5); a += 2.0; - ASSERT_MATRIX_M_N_EQ( - 3, 4, a, - 3.0, 3.0, 3.0, 3.0, - 4.0, 4.0, 4.0, 4.0, - 5.0, 5.0, 5.0, 5.0); + ASSERT_MATRIX_M_N_EQ(3, 4, a, 3.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 4.0, 5.0, 5.0, 5.0, 5.0); a -= 2.0; - ASSERT_MATRIX_M_N_EQ( - 3, 4, a, - 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, - 3.0, 3.0, 3.0, 3.0); + ASSERT_MATRIX_M_N_EQ(3, 4, a, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0); a *= 2.0; - ASSERT_MATRIX_M_N_EQ( - 3, 4, a, - 2.0, 2.0, 2.0, 2.0, - 4.0, 4.0, 4.0, 4.0, - 6.0, 6.0, 6.0, 6.0); + ASSERT_MATRIX_M_N_EQ(3, 4, a, 2.0, 2.0, 2.0, 2.0, 4.0, 4.0, 4.0, 4.0, 6.0, 6.0, 6.0, 6.0); a /= 2.0; - ASSERT_MATRIX_M_N_EQ( - 3, 4, a, - 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, - 3.0, 3.0, 3.0, 3.0); + ASSERT_MATRIX_M_N_EQ(3, 4, a, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0); } TEST(MatrixTest, NegationOperation) { - auto a = ksn::Matrix<3, 4>( - 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, - 3.0, 3.0, 3.0, 3.0); + auto a = ksn::Matrix<3, 4>(1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0); ASSERT_MATRIX_M_N_EQ( - 3, 4, -a, - -1.0, -1.0, -1.0, -1.0, - -2.0, -2.0, -2.0, -2.0, - -3.0, -3.0, -3.0, -3.0); + 3, 4, -a, -1.0, -1.0, -1.0, -1.0, -2.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, -3.0); } diff --git a/test/matrix/matrix_transformation_test.cpp b/test/matrix/matrix_transformation_test.cpp index cb03177..ad76220 100644 --- a/test/matrix/matrix_transformation_test.cpp +++ b/test/matrix/matrix_transformation_test.cpp @@ -21,15 +21,15 @@ #include "gtest/gtest.h" #include "keisan/keisan.hpp" -#define ASSERT_MATRIX_M_N_NEAR(M, N, MATRIX, ...) \ - { \ - ksn::Matrix _matrix = MATRIX; \ - double _values[] = {__VA_ARGS__}; \ - for (size_t i = 0; i < M; ++i) { \ - for (size_t j = 0; j < N; ++j) { \ +#define ASSERT_MATRIX_M_N_NEAR(M, N, MATRIX, ...) \ + { \ + ksn::Matrix _matrix = MATRIX; \ + double _values[] = {__VA_ARGS__}; \ + for (size_t i = 0; i < M; ++i) { \ + for (size_t j = 0; j < N; ++j) { \ ASSERT_NEAR(_values[i * N + j], _matrix[i][j], 1e-2); \ - } \ - } \ + } \ + } \ } namespace ksn = keisan; @@ -39,36 +39,24 @@ TEST(MatrixTransformationTest, Translation) auto point2 = ksn::Point2(0.0, 0.0); ASSERT_MATRIX_M_N_NEAR( - 3, 3, ksn::translation_matrix(point2), - 1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - 0.0, 0.0, 1.0); + 3, 3, ksn::translation_matrix(point2), 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0); point2.x = 1.0; ASSERT_MATRIX_M_N_NEAR( - 3, 3, ksn::translation_matrix(point2), - 1.0, 0.0, 1.0, - 0.0, 1.0, 0.0, - 0.0, 0.0, 1.0); + 3, 3, ksn::translation_matrix(point2), 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0); auto point3 = ksn::Point3(0.0, 0.0, 0.0); ASSERT_MATRIX_M_N_NEAR( - 4, 4, ksn::translation_matrix(point3), - 1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0); + 4, 4, ksn::translation_matrix(point3), 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, + 0.0, 0.0, 0.0, 0.0, 1.0); point3.y = 2.0; ASSERT_MATRIX_M_N_NEAR( - 4, 4, ksn::translation_matrix(point3), - 1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 2.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0); + 4, 4, ksn::translation_matrix(point3), 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 0.0, 1.0, + 0.0, 0.0, 0.0, 0.0, 1.0); } TEST(MatrixTransformationTest, Rotation) @@ -76,82 +64,54 @@ TEST(MatrixTransformationTest, Rotation) auto angle = ksn::make_radian(0.0); ASSERT_MATRIX_M_N_NEAR( - 3, 3, ksn::rotation_matrix(angle), - 1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - 0.0, 0.0, 1.0); + 3, 3, ksn::rotation_matrix(angle), 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0); angle = ksn::make_radian(ksn::pi); ASSERT_MATRIX_M_N_NEAR( - 3, 3, ksn::rotation_matrix(angle), - -1.0, 0.0, 0.0, - 0.0, -1.0, 0.0, - 0.0, 0.0, 1.0); + 3, 3, ksn::rotation_matrix(angle), -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0); angle /= 2; ASSERT_MATRIX_M_N_NEAR( - 3, 3, ksn::rotation_matrix(angle), - 0.0, -1.0, 0.0, - 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0); + 3, 3, ksn::rotation_matrix(angle), 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0); angle /= 2; ASSERT_MATRIX_M_N_NEAR( - 3, 3, ksn::rotation_matrix(angle), - 0.7, -0.7, 0.0, - 0.7, 0.7, 0.0, - 0.0, 0.0, 1.0); + 3, 3, ksn::rotation_matrix(angle), 0.7, -0.7, 0.0, 0.7, 0.7, 0.0, 0.0, 0.0, 1.0); - auto euler = ksn::Euler( - ksn::make_radian(0.0), - ksn::make_radian(0.0), ksn::make_radian(0.0)); + auto euler = + ksn::Euler(ksn::make_radian(0.0), ksn::make_radian(0.0), ksn::make_radian(0.0)); ASSERT_MATRIX_M_N_NEAR( - 4, 4, ksn::rotation_matrix(euler), - 1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, + 4, 4, ksn::rotation_matrix(euler), 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0); euler.roll = ksn::make_radian(ksn::pi); ASSERT_MATRIX_M_N_NEAR( - 4, 4, ksn::rotation_matrix(euler), - 1.0, 0.0, 0.0, 0.0, - 0.0, -1.0, -1e-16, 0.0, - 0.0, 1e-16, -1.0, 0.0, - 0.0, 0.0, 0.0, 1.0); + 4, 4, ksn::rotation_matrix(euler), 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1e-16, 0.0, 0.0, 1e-16, -1.0, + 0.0, 0.0, 0.0, 0.0, 1.0); euler.roll /= 2; ASSERT_MATRIX_M_N_NEAR( - 4, 4, ksn::rotation_matrix(euler), - 1.0, 0.0, 0.0, 0.0, - 0.0, 6e-17, -1.0, 0.0, - 0.0, 1.0, 6e-17, 0.0, - 0.0, 0.0, 0.0, 1.0); + 4, 4, ksn::rotation_matrix(euler), 1.0, 0.0, 0.0, 0.0, 0.0, 6e-17, -1.0, 0.0, 0.0, 1.0, 6e-17, + 0.0, 0.0, 0.0, 0.0, 1.0); euler.roll = ksn::make_radian(0.0); euler.pitch = ksn::make_radian(ksn::pi); ASSERT_MATRIX_M_N_NEAR( - 4, 4, ksn::rotation_matrix(euler), - -1.0, 0.0, 1e-16, 0.0, - 0.0, 1.0, 0.0, 0.0, - -1e-16, 0.0, -1.0, 0.0, - 0.0, 0.0, 0.0, 1.0); + 4, 4, ksn::rotation_matrix(euler), -1.0, 0.0, 1e-16, 0.0, 0.0, 1.0, 0.0, 0.0, -1e-16, 0.0, -1.0, + 0.0, 0.0, 0.0, 0.0, 1.0); euler.yaw = ksn::make_radian(ksn::pi); ASSERT_MATRIX_M_N_NEAR( - 4, 4, ksn::rotation_matrix(euler), - 1.0, -1e-16, 1e-16, 0.0, - -1e-16, -1.0, 1e-32, 0.0, - -1e-16, 0.0, -1.0, 0.0, - 0.0, 0.0, 0.0, 1.0); + 4, 4, ksn::rotation_matrix(euler), 1.0, -1e-16, 1e-16, 0.0, -1e-16, -1.0, 1e-32, 0.0, -1e-16, + 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0); } TEST(MatrixTransformationTest, Transformation) @@ -160,55 +120,36 @@ TEST(MatrixTransformationTest, Transformation) auto angle = ksn::make_radian(ksn::pi); ASSERT_MATRIX_M_N_NEAR( - 3, 3, - ksn::translation_matrix(point2) * ksn::rotation_matrix(angle), - -1.0, 0.0, 1.0, - 0.0, -1.0, 0.0, - 0.0, 0.0, 1.0); + 3, 3, ksn::translation_matrix(point2) * ksn::rotation_matrix(angle), -1.0, 0.0, 1.0, 0.0, -1.0, + 0.0, 0.0, 0.0, 1.0); point2.y = 2.0; angle /= 4; ASSERT_MATRIX_M_N_NEAR( - 3, 3, - ksn::translation_matrix(point2) * ksn::rotation_matrix(angle), - 0.7, -0.7, 1.0, - 0.7, 0.7, 2.0, - 0.0, 0.0, 1.0); + 3, 3, ksn::translation_matrix(point2) * ksn::rotation_matrix(angle), 0.7, -0.7, 1.0, 0.7, 0.7, + 2.0, 0.0, 0.0, 1.0); auto point3 = ksn::Point3(0.0, 2.0, 0.0); auto euler = ksn::Euler( - ksn::make_radian(ksn::pi), - ksn::make_radian(0.0), ksn::make_radian(0.0)); + ksn::make_radian(ksn::pi), ksn::make_radian(0.0), ksn::make_radian(0.0)); ASSERT_MATRIX_M_N_NEAR( - 4, 4, - ksn::translation_matrix(point3) * ksn::rotation_matrix(euler), - 1.0, 0.0, 0.0, 0.0, - 0.0, -1.0, -1e-16, 2.0, - 0.0, 1e-16, -1.0, 0.0, - 0.0, 0.0, 0.0, 1.0); + 4, 4, ksn::translation_matrix(point3) * ksn::rotation_matrix(euler), 1.0, 0.0, 0.0, 0.0, 0.0, + -1.0, -1e-16, 2.0, 0.0, 1e-16, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0); point3.z = 3.0; euler.roll = ksn::make_radian(0.0); euler.pitch = ksn::make_radian(ksn::pi); ASSERT_MATRIX_M_N_NEAR( - 4, 4, - ksn::translation_matrix(point3) * ksn::rotation_matrix(euler), - -1.0, 0.0, 1e-16, 0.0, - 0.0, 1.0, 0.0, 2.0, - -1e-16, 0.0, -1.0, 3.0, - 0.0, 0.0, 0.0, 1.0); + 4, 4, ksn::translation_matrix(point3) * ksn::rotation_matrix(euler), -1.0, 0.0, 1e-16, 0.0, 0.0, + 1.0, 0.0, 2.0, -1e-16, 0.0, -1.0, 3.0, 0.0, 0.0, 0.0, 1.0); point3.z = 1.0; euler.yaw = ksn::make_radian(ksn::pi); ASSERT_MATRIX_M_N_NEAR( - 4, 4, - ksn::translation_matrix(point3) * ksn::rotation_matrix(euler), - 1.0, -1e-16, 1e-16, 0.0, - -1e-16, -1.0, 1e-32, 2.0, - -1e-16, 0.0, -1.0, 1.0, - 0.0, 0.0, 0.0, 1.0); + 4, 4, ksn::translation_matrix(point3) * ksn::rotation_matrix(euler), 1.0, -1e-16, 1e-16, 0.0, + -1e-16, -1.0, 1e-32, 2.0, -1e-16, 0.0, -1.0, 1.0, 0.0, 0.0, 0.0, 1.0); } diff --git a/test/matrix/vector_test.cpp b/test/matrix/vector_test.cpp index c0152fe..eac5d62 100644 --- a/test/matrix/vector_test.cpp +++ b/test/matrix/vector_test.cpp @@ -23,13 +23,13 @@ #include "gtest/gtest.h" #include "keisan/keisan.hpp" -#define ASSERT_VECTOR_N_EQ(N, VECTOR, ...) \ - { \ - ksn::Vector _vector = VECTOR; \ - double _values[] = {__VA_ARGS__}; \ - for (size_t i = 0; i < N; ++i) { \ +#define ASSERT_VECTOR_N_EQ(N, VECTOR, ...) \ + { \ + ksn::Vector _vector = VECTOR; \ + double _values[] = {__VA_ARGS__}; \ + for (size_t i = 0; i < N; ++i) { \ ASSERT_DOUBLE_EQ(_values[i], _vector[i]); \ - } \ + } \ } namespace ksn = keisan; @@ -78,10 +78,7 @@ TEST(VectorTest, ComparisonOperation) TEST(VectorTest, MatrixMultiplication) { - auto a = ksn::Matrix<3, 2>( - 1.0, 1.0, - 2.0, 2.0, - 3.0, 3.0); + auto a = ksn::Matrix<3, 2>(1.0, 1.0, 2.0, 2.0, 3.0, 3.0); auto b = ksn::Vector<2>(1.0, 2.0); diff --git a/test/number_test.cpp b/test/number_test.cpp index 90e4b10..21543b7 100644 --- a/test/number_test.cpp +++ b/test/number_test.cpp @@ -48,184 +48,176 @@ TEST(NumberTest, SignAngle) TEST(NumberTest, ScaleIntegral) { - EXPECT_EQ(ksn::scale(5, 2, 3), 6) << - "5 / 2 = 2\n" - "2 * 3 = 6"; + EXPECT_EQ(ksn::scale(5, 2, 3), 6) << "5 / 2 = 2\n" + "2 * 3 = 6"; } TEST(NumberTest, ScaleFloatingPoint) { - EXPECT_DOUBLE_EQ(ksn::scale(3.3, 0.5, 1.5), 9.9) << - "3.3 / 0.5 = 6.6\n" - "6.6 * 1.5 = 9.9"; + EXPECT_DOUBLE_EQ(ksn::scale(3.3, 0.5, 1.5), 9.9) << "3.3 / 0.5 = 6.6\n" + "6.6 * 1.5 = 9.9"; } TEST(NumberTest, MapIntegral) { - EXPECT_EQ(ksn::map(5, 2, 4, 0, 1), 1) << - "min(5, max(2, 4)) = 4\n" - "max(4, min(2, 4)) = 4\n" - "4 - 2 = 2\n" - "4 - 2 = 2\n" - "1 - 0 = 1\n" - "scale(2, 2, 1) = 1\n" - "1 + 0 = 1"; - - EXPECT_EQ(ksn::map(0, -2, -4, 0, 1), 0) << - "min(0, max(-2, -4)) = -2\n" - "max(-2, min(-2, -4)) = -2\n" - "-2 - (-2) = 0\n" - "-4 - (-2) = -2\n" - "1 - 0 = 1\n" - "scale(0, -2, 1) = 0\n" - "0 + 0 = 0"; - - EXPECT_EQ(ksn::map(10, 3, 11, -2, 2), -2) << - "min(10, max(3, 11)) = 10\n" - "max(10, min(3, 11)) = 10\n" - "10 - 3 = 7\n" - "11 - 3 = 8\n" - "2 - (-2) = 4\n" - "scale(7, 8, 4) = 0\n" - "0 + (-2) = -2"; + EXPECT_EQ(ksn::map(5, 2, 4, 0, 1), 1) << "min(5, max(2, 4)) = 4\n" + "max(4, min(2, 4)) = 4\n" + "4 - 2 = 2\n" + "4 - 2 = 2\n" + "1 - 0 = 1\n" + "scale(2, 2, 1) = 1\n" + "1 + 0 = 1"; + + EXPECT_EQ(ksn::map(0, -2, -4, 0, 1), 0) << "min(0, max(-2, -4)) = -2\n" + "max(-2, min(-2, -4)) = -2\n" + "-2 - (-2) = 0\n" + "-4 - (-2) = -2\n" + "1 - 0 = 1\n" + "scale(0, -2, 1) = 0\n" + "0 + 0 = 0"; + + EXPECT_EQ(ksn::map(10, 3, 11, -2, 2), -2) << "min(10, max(3, 11)) = 10\n" + "max(10, min(3, 11)) = 10\n" + "10 - 3 = 7\n" + "11 - 3 = 8\n" + "2 - (-2) = 4\n" + "scale(7, 8, 4) = 0\n" + "0 + (-2) = -2"; } TEST(NumberTest, MapFloatingPoint) { - EXPECT_DOUBLE_EQ(ksn::map(0.5, 0.2, 0.8, 1.0, 3.2), 2.1) << - "min(0.5, max(0.2, 0.8)) = 0.5\n" - "max(0.5, min(0.2, 0.8)) = 0.5\n" - "0.5 - 0.2 = 0.3\n" - "0.8 - 0.2 = 0.6\n" - "3.2 - 1.0 = 2.2\n" - "scale(0.5, 0.6, 2.2) = 1.1\n" - "1.1 + 1.0 = 2.1"; - - EXPECT_DOUBLE_EQ(ksn::map(-0.1, 0.2, 0.8, -3.2, -1.0), -3.2) << - "min(-0.1, max(0.2, 0.8)) = -0.1\n" - "max(-0.1, min(0.2, 0.8)) = 0.2\n" - "0.2 - 0.2 = 0.0\n" - "0.8 - 0.2 = 0.6\n" - "-1.0 - (-3.2) = 2.2\n" - "scale(0.0, 0.6, 2.2) = 0.0\n" - "0.0 + (-3.2) = -3.2"; - - EXPECT_DOUBLE_EQ(ksn::map(-1.5, 5.0, -2.5, 7.0, 13.0), 12.2) << - "min(-1.5, max(5.0, -2.5)) = -1.5\n" - "max(-1.5, min(5.0, -2.5)) = -1.5\n" - "-1.5 - 5.0 = -6.5\n" - "-2.5 - 5.0 = -7.5\n" - "13.0 - 7.0 = 6.0\n" - "scale(-6.5, -7.5, 6.0) = 5.2\n" - "5.2 + 7.0 = 12.2"; + EXPECT_DOUBLE_EQ(ksn::map(0.5, 0.2, 0.8, 1.0, 3.2), 2.1) << "min(0.5, max(0.2, 0.8)) = 0.5\n" + "max(0.5, min(0.2, 0.8)) = 0.5\n" + "0.5 - 0.2 = 0.3\n" + "0.8 - 0.2 = 0.6\n" + "3.2 - 1.0 = 2.2\n" + "scale(0.5, 0.6, 2.2) = 1.1\n" + "1.1 + 1.0 = 2.1"; + + EXPECT_DOUBLE_EQ(ksn::map(-0.1, 0.2, 0.8, -3.2, -1.0), -3.2) + << "min(-0.1, max(0.2, 0.8)) = -0.1\n" + "max(-0.1, min(0.2, 0.8)) = 0.2\n" + "0.2 - 0.2 = 0.0\n" + "0.8 - 0.2 = 0.6\n" + "-1.0 - (-3.2) = 2.2\n" + "scale(0.0, 0.6, 2.2) = 0.0\n" + "0.0 + (-3.2) = -3.2"; + + EXPECT_DOUBLE_EQ(ksn::map(-1.5, 5.0, -2.5, 7.0, 13.0), 12.2) + << "min(-1.5, max(5.0, -2.5)) = -1.5\n" + "max(-1.5, min(5.0, -2.5)) = -1.5\n" + "-1.5 - 5.0 = -6.5\n" + "-2.5 - 5.0 = -7.5\n" + "13.0 - 7.0 = 6.0\n" + "scale(-6.5, -7.5, 6.0) = 5.2\n" + "5.2 + 7.0 = 12.2"; } TEST(NumberTest, ExponentialMapIntegral) { - EXPECT_EQ(ksn::exponentialmap(5, 2, 4, 0, 1), 1) << - "clamp(5, 2, 4) = 4\n" - "map_coeff (0 <= 1) = 1\n" - "normalized_val = (4 - 2)/(4 - 2) = 1\n" - "1 * pow(|1 - 0 + 1|, 1) + 0 - 1 = 1\n"; - - EXPECT_EQ(ksn::exponentialmap(-5, -4, -2, 0, 1), 0) << - "clamp(-5, -4, -2) = -4\n" - "map_coeff (0 <= 1) = 1\n" - "normalized_val = (-4 - (-4))/( -2 - (-4)) = 0\n" - "1 * pow(|1 - 0 + 1|, 0) + 0 - 1 = 0\n"; + EXPECT_EQ(ksn::exponentialmap(5, 2, 4, 0, 1), 1) << "clamp(5, 2, 4) = 4\n" + "map_coeff (0 <= 1) = 1\n" + "normalized_val = (4 - 2)/(4 - 2) = 1\n" + "1 * pow(|1 - 0 + 1|, 1) + 0 - 1 = 1\n"; + + EXPECT_EQ(ksn::exponentialmap(-5, -4, -2, 0, 1), 0) + << "clamp(-5, -4, -2) = -4\n" + "map_coeff (0 <= 1) = 1\n" + "normalized_val = (-4 - (-4))/( -2 - (-4)) = 0\n" + "1 * pow(|1 - 0 + 1|, 0) + 0 - 1 = 0\n"; } TEST(NumberTest, ExponentialMapFloatingPoint) { - EXPECT_DOUBLE_EQ(ksn::exponentialmap(5.2, 1.8, 4.9, 0.4, 2.4), 2.4) << - "clamp(5.2, 1.8, 4.9) = 4.9\n" - "map_coeff (0.4 <= 2.4) = 1\n" - "normalized_val = (4.9 - 1.8) / (4.9 - 1.8) = 1\n" - "1 * pow(|2.4 - 0.4 + 1|, 1) + 0.4 - 1 = 2.4\n"; - - EXPECT_DOUBLE_EQ(ksn::exponentialmap(-6.9, -4.2, -2.0, 0.0, 1.3), 0) << - "clamp(-6.9, -4.2, -2.0) = -4.2\n" - "map_coeff (0.0 <= 1.3) = 1\n" - "normalized_val = (-4.2 - (-4.2)) / (-2.0 - (-4.2)) = 0\n" - "1 * pow(|1.3 - 0.0 + 1|, 0) + 0.0 - 1 = 0\n"; - - EXPECT_NEAR(ksn::exponentialmap(10.2, 3.1, 14.7, -2.2, 2.2), -0.393, 0.001) << - "clamp(10.2, 3.1, 14.7) = 10.2\n" - "map_coeff (-2.2 <= 2.2) = 1\n" - "normalized_val = (10.2 - 3.1) / (14.7 - 3.1) = 0.6121\n" - "1 * pow(|2.2 - (-2.2) + 1|, 0.6121) + (-2.2) - 1 ~ -0.393\n"; - - EXPECT_NEAR(ksn::exponentialmap(10.2, 3.1, 14.7, 2.2, -2.2), 0.393, 0.001) << - "clamp(10.2, 3.1, 14.7) = 10.2\n" - "map_coeff (2.2 <= -2.2) = -1\n" - "normalized_val = (10.2 - 3.1) / (14.7 - 3.1) = 0.6121\n" - "-1 * pow(|-2.2 - 2.2 + (-1)|, 0.6121) + 2.2 - (-1) ~ 0.393\n"; - - EXPECT_NEAR(ksn::exponentialmap(10.2, 14.7, 3.1, 2.2, -2.2), 1.276, 0.001) << - "clamp(10.2, 14.7, 3.1) = 10.2\n" - "map_coeff (2.2 <= -2.2) = -1\n" - "normalized_val = (10.2 - 14.7) / (3.1 - 14.7) = 0.3879\n" - "-1 * pow(|-2.2 - 2.2 + (-1)|, 0.3879) + 2.2 - (-1) ~ 1.276\n"; - - EXPECT_NEAR(ksn::exponentialmap(10.2, 14.7, 3.1, -2.2, 2.2), -1.276, 0.001) << - "clamp(10.2, 14.7, 3.1) = 10.2\n" - "map_coeff (-2.2 <= 2.2) = 1\n" - "normalized_val = (10.2 - 14.7) / (3.1 - 14.7) = 0.3879\n" - "1 * pow(|2.2 - (-2.2) + 1|, 0.3879) + (-2.2) - 1 ~ -1.276\n"; + EXPECT_DOUBLE_EQ(ksn::exponentialmap(5.2, 1.8, 4.9, 0.4, 2.4), 2.4) + << "clamp(5.2, 1.8, 4.9) = 4.9\n" + "map_coeff (0.4 <= 2.4) = 1\n" + "normalized_val = (4.9 - 1.8) / (4.9 - 1.8) = 1\n" + "1 * pow(|2.4 - 0.4 + 1|, 1) + 0.4 - 1 = 2.4\n"; + + EXPECT_DOUBLE_EQ(ksn::exponentialmap(-6.9, -4.2, -2.0, 0.0, 1.3), 0) + << "clamp(-6.9, -4.2, -2.0) = -4.2\n" + "map_coeff (0.0 <= 1.3) = 1\n" + "normalized_val = (-4.2 - (-4.2)) / (-2.0 - (-4.2)) = 0\n" + "1 * pow(|1.3 - 0.0 + 1|, 0) + 0.0 - 1 = 0\n"; + + EXPECT_NEAR(ksn::exponentialmap(10.2, 3.1, 14.7, -2.2, 2.2), -0.393, 0.001) + << "clamp(10.2, 3.1, 14.7) = 10.2\n" + "map_coeff (-2.2 <= 2.2) = 1\n" + "normalized_val = (10.2 - 3.1) / (14.7 - 3.1) = 0.6121\n" + "1 * pow(|2.2 - (-2.2) + 1|, 0.6121) + (-2.2) - 1 ~ -0.393\n"; + + EXPECT_NEAR(ksn::exponentialmap(10.2, 3.1, 14.7, 2.2, -2.2), 0.393, 0.001) + << "clamp(10.2, 3.1, 14.7) = 10.2\n" + "map_coeff (2.2 <= -2.2) = -1\n" + "normalized_val = (10.2 - 3.1) / (14.7 - 3.1) = 0.6121\n" + "-1 * pow(|-2.2 - 2.2 + (-1)|, 0.6121) + 2.2 - (-1) ~ 0.393\n"; + + EXPECT_NEAR(ksn::exponentialmap(10.2, 14.7, 3.1, 2.2, -2.2), 1.276, 0.001) + << "clamp(10.2, 14.7, 3.1) = 10.2\n" + "map_coeff (2.2 <= -2.2) = -1\n" + "normalized_val = (10.2 - 14.7) / (3.1 - 14.7) = 0.3879\n" + "-1 * pow(|-2.2 - 2.2 + (-1)|, 0.3879) + 2.2 - (-1) ~ 1.276\n"; + + EXPECT_NEAR(ksn::exponentialmap(10.2, 14.7, 3.1, -2.2, 2.2), -1.276, 0.001) + << "clamp(10.2, 14.7, 3.1) = 10.2\n" + "map_coeff (-2.2 <= 2.2) = 1\n" + "normalized_val = (10.2 - 14.7) / (3.1 - 14.7) = 0.3879\n" + "1 * pow(|2.2 - (-2.2) + 1|, 0.3879) + (-2.2) - 1 ~ -1.276\n"; } TEST(NumberTest, SinusoidalMapIntegral) { - EXPECT_EQ(ksn::sinusoidalmap(10, 2, 4, 0, 2), 2) << - "clamp(10, 2, 4) = 4\n" - "coeff = -(2 - 0) / 2 = -1\n" - "angle = (M_PI * (2 - 4)) / (2 - 4) = M_PI\n" - "-1 * cos(M_PI) + (2 + 0) / 2 = 2\n"; - - EXPECT_EQ(ksn::sinusoidalmap(-5, -4, -2, 0, 1), 0) << - "clamp(-5, -4, -2) = -4\n" - "coeff = -(1 - 0) / 2 = -0.5\n" - "angle = (M_PI * (-4 - (-4))) / (-4 - (-2)) = 0\n" - "-0.5 * cos(0) + (1 + 0) / 2 = 0\n"; + EXPECT_EQ(ksn::sinusoidalmap(10, 2, 4, 0, 2), 2) << "clamp(10, 2, 4) = 4\n" + "coeff = -(2 - 0) / 2 = -1\n" + "angle = (M_PI * (2 - 4)) / (2 - 4) = M_PI\n" + "-1 * cos(M_PI) + (2 + 0) / 2 = 2\n"; + + EXPECT_EQ(ksn::sinusoidalmap(-5, -4, -2, 0, 1), 0) + << "clamp(-5, -4, -2) = -4\n" + "coeff = -(1 - 0) / 2 = -0.5\n" + "angle = (M_PI * (-4 - (-4))) / (-4 - (-2)) = 0\n" + "-0.5 * cos(0) + (1 + 0) / 2 = 0\n"; } TEST(NumberTest, SinusoidalMapFloatingPoint) { - EXPECT_DOUBLE_EQ(ksn::sinusoidalmap(5.2, 1.8, 4.9, 0.4, 2.4), 2.4) << - "clamp(5.2, 1.8, 4.9) = 4.9\n" - "coeff = -(2.4 - 0.4) / 2 = -1\n" - "angle = (M_PI * (1.8 - 4.9)) / (1.8 - 4.9) = M_PI\n" - "-1 * cos(M_PI) + (2.4 + 0.4) / 2 = 2.4\n"; - - EXPECT_DOUBLE_EQ(ksn::sinusoidalmap(-6.9, -4.2, -2.0, 0.0, 1.3), 0) << - "clamp(-6.9, -4.2, -2.0) = -4.2\n" - "coeff = -(1.3 - 0.0) / 2 = -0.65\n" - "angle = (M_PI * (-4.2 - (-4.2))) / (-4.2 - (-2.0)) = 0\n" - "-0.65 * cos(0) + (1.3 + 0.0) / 2 = 0.0\n"; - - EXPECT_NEAR(ksn::sinusoidalmap(10.2, 3.1, 14.7, -2.2, 2.2), 0.759, 0.001) << - "clamp(10.2, 3.1, 14.7) = 10.2\n" - "coeff = -(2.2 - (-2.2)) / 2 = -2.2\n" - "angle = (M_PI * (3.1 - 10.2)) / (3.1 - 14.7) ~ 1.923\n" - "-2.2 * cos(1.923) + (2.2 + (-2.2)) / 2 ~ 0.759\n"; - - EXPECT_NEAR(ksn::sinusoidalmap(10.2, 3.1, 14.7, 2.2, -2.2), -0.759, 0.001) << - "clamp(10.2, 3.1, 14.7) = 10.2\n" - "coeff = -(-2.2 - 2.2) / 2 = 2.2\n" - "angle = (M_PI * (3.1 - 10.2)) / (3.1 - 14.7) ~ 1.923\n" - "2.2 * cos(1.923) + (-2.2 + 2.2) / 2 ~ -0.759\n"; - - EXPECT_NEAR(ksn::sinusoidalmap(10.2, 14.7, 3.1, 2.2, -2.2), 0.759, 0.001) << - "clamp(10.2, 14.7, 3.1) = 10.2\n" - "coeff = -(-2.2 - 2.2) / 2 = 2.2\n" - "angle = (M_PI * (14.7 - 10.2)) / (14.7 - 3.1) = 1.219\n" - "2.2 * cos(1.219) + (2.2 + (-2.2)) / 2 ~ 0.759\n"; - - EXPECT_NEAR(ksn::sinusoidalmap(10.2, 14.7, 3.1, -2.2, 2.2), -0.759, 0.001) << - "clamp(10.2, 14.7, 3.1) = 10.2\n" - "coeff = -(2.2 - (-2.2)) / 2 = -2.2\n" - "angle = (M_PI * (14.7 - 10.2)) / (14.7 - 3.1) = 1.219\n" - "-2.2 * cos(1.219) + (-2.2 + 2.2) / 2 ~ -0.759\n"; + EXPECT_DOUBLE_EQ(ksn::sinusoidalmap(5.2, 1.8, 4.9, 0.4, 2.4), 2.4) + << "clamp(5.2, 1.8, 4.9) = 4.9\n" + "coeff = -(2.4 - 0.4) / 2 = -1\n" + "angle = (M_PI * (1.8 - 4.9)) / (1.8 - 4.9) = M_PI\n" + "-1 * cos(M_PI) + (2.4 + 0.4) / 2 = 2.4\n"; + + EXPECT_DOUBLE_EQ(ksn::sinusoidalmap(-6.9, -4.2, -2.0, 0.0, 1.3), 0) + << "clamp(-6.9, -4.2, -2.0) = -4.2\n" + "coeff = -(1.3 - 0.0) / 2 = -0.65\n" + "angle = (M_PI * (-4.2 - (-4.2))) / (-4.2 - (-2.0)) = 0\n" + "-0.65 * cos(0) + (1.3 + 0.0) / 2 = 0.0\n"; + + EXPECT_NEAR(ksn::sinusoidalmap(10.2, 3.1, 14.7, -2.2, 2.2), 0.759, 0.001) + << "clamp(10.2, 3.1, 14.7) = 10.2\n" + "coeff = -(2.2 - (-2.2)) / 2 = -2.2\n" + "angle = (M_PI * (3.1 - 10.2)) / (3.1 - 14.7) ~ 1.923\n" + "-2.2 * cos(1.923) + (2.2 + (-2.2)) / 2 ~ 0.759\n"; + + EXPECT_NEAR(ksn::sinusoidalmap(10.2, 3.1, 14.7, 2.2, -2.2), -0.759, 0.001) + << "clamp(10.2, 3.1, 14.7) = 10.2\n" + "coeff = -(-2.2 - 2.2) / 2 = 2.2\n" + "angle = (M_PI * (3.1 - 10.2)) / (3.1 - 14.7) ~ 1.923\n" + "2.2 * cos(1.923) + (-2.2 + 2.2) / 2 ~ -0.759\n"; + + EXPECT_NEAR(ksn::sinusoidalmap(10.2, 14.7, 3.1, 2.2, -2.2), 0.759, 0.001) + << "clamp(10.2, 14.7, 3.1) = 10.2\n" + "coeff = -(-2.2 - 2.2) / 2 = 2.2\n" + "angle = (M_PI * (14.7 - 10.2)) / (14.7 - 3.1) = 1.219\n" + "2.2 * cos(1.219) + (2.2 + (-2.2)) / 2 ~ 0.759\n"; + + EXPECT_NEAR(ksn::sinusoidalmap(10.2, 14.7, 3.1, -2.2, 2.2), -0.759, 0.001) + << "clamp(10.2, 14.7, 3.1) = 10.2\n" + "coeff = -(2.2 - (-2.2)) / 2 = -2.2\n" + "angle = (M_PI * (14.7 - 10.2)) / (14.7 - 3.1) = 1.219\n" + "-2.2 * cos(1.219) + (-2.2 + 2.2) / 2 ~ -0.759\n"; } TEST(NumberTest, ClampIntegral) @@ -251,121 +243,106 @@ TEST(NumberTest, ClampAngle) TEST(NumberTest, WrapIntegral) { - EXPECT_EQ(ksn::wrap(13, 10, 15), 13) << - "13 - 10 = 3\n" - "15 - 10 = 5\n" - "3 = 5 * 0 + 3\n" - "3 + 10 = 13"; - - EXPECT_EQ(ksn::wrap(31, 10, 15), 11) << - "31 - 10 = 21\n" - "15 - 10 = 5\n" - "21 = 5 * 4 + 1\n" - "1 + 10 = 11"; - - EXPECT_EQ(ksn::wrap(4, 10, 15), 14) << - "4 - 10 = -6\n" - "15 - 10 = 5\n" - "-6 = 5 * (-2) + 4\n" - "4 + 10 = 14"; + EXPECT_EQ(ksn::wrap(13, 10, 15), 13) << "13 - 10 = 3\n" + "15 - 10 = 5\n" + "3 = 5 * 0 + 3\n" + "3 + 10 = 13"; + + EXPECT_EQ(ksn::wrap(31, 10, 15), 11) << "31 - 10 = 21\n" + "15 - 10 = 5\n" + "21 = 5 * 4 + 1\n" + "1 + 10 = 11"; + + EXPECT_EQ(ksn::wrap(4, 10, 15), 14) << "4 - 10 = -6\n" + "15 - 10 = 5\n" + "-6 = 5 * (-2) + 4\n" + "4 + 10 = 14"; } TEST(NumberTest, WrapFloatingPoint) { - EXPECT_DOUBLE_EQ(ksn::wrap(0.1, -0.1, 0.3), 0.1) << - "0.1 - (-0.1) = 0.2\n" - "0.3 - (-0.1) = 0.4\n" - "0.2 = 0.4 * 0 + 0.2\n" - "0.2 + (-0.1) = 0.1"; - - EXPECT_DOUBLE_EQ(ksn::wrap(1.8, -0.1, 0.3), 0.2) << - "1.8 - (-0.1) = 1.9\n" - "0.3 - (-0.1) = 0.4\n" - "1.9 = 0.4 * 4 + 0.3\n" - "0.3 + (-0.1) = 0.2"; - - EXPECT_DOUBLE_EQ(ksn::wrap(0.1, 1.1, 1.5), 1.3) << - "0.1 - (1.1) = -1.0\n" - "1.5 - (1.1) = 0.4\n" - "-1.0 = 0.4 * (-3) + 0.2\n" - "0.2 + (1.1) = 1.3"; + EXPECT_DOUBLE_EQ(ksn::wrap(0.1, -0.1, 0.3), 0.1) << "0.1 - (-0.1) = 0.2\n" + "0.3 - (-0.1) = 0.4\n" + "0.2 = 0.4 * 0 + 0.2\n" + "0.2 + (-0.1) = 0.1"; + + EXPECT_DOUBLE_EQ(ksn::wrap(1.8, -0.1, 0.3), 0.2) << "1.8 - (-0.1) = 1.9\n" + "0.3 - (-0.1) = 0.4\n" + "1.9 = 0.4 * 4 + 0.3\n" + "0.3 + (-0.1) = 0.2"; + + EXPECT_DOUBLE_EQ(ksn::wrap(0.1, 1.1, 1.5), 1.3) << "0.1 - (1.1) = -1.0\n" + "1.5 - (1.1) = 0.4\n" + "-1.0 = 0.4 * (-3) + 0.2\n" + "0.2 + (1.1) = 1.3"; } TEST(NumberTest, CurveIntegral) { - EXPECT_EQ(ksn::curve(13, 10, 15, 2), 11) << - "clamp(13, 10, 15) = 13\n" - "10 + (15 - 10) * ((13 - 10) / (15-10))^2 = 11"; - - EXPECT_EQ(ksn::curve(31, 10, 15, 2), 15) << - "clamp(31, 10, 15) = 15\n" - "10 + (15 - 10) * ((15 - 10) / (15-10))^2 = 15"; - - EXPECT_EQ(ksn::curve(4, 10, 15, 2), 10) << - "clamp(4, 10, 15) = 10\n" - "10 + (15 - 10) * ((10 - 10) / (15-10))^2 = 10"; + EXPECT_EQ(ksn::curve(13, 10, 15, 2), 11) << "clamp(13, 10, 15) = 13\n" + "10 + (15 - 10) * ((13 - 10) / (15-10))^2 = 11"; + + EXPECT_EQ(ksn::curve(31, 10, 15, 2), 15) << "clamp(31, 10, 15) = 15\n" + "10 + (15 - 10) * ((15 - 10) / (15-10))^2 = 15"; + + EXPECT_EQ(ksn::curve(4, 10, 15, 2), 10) << "clamp(4, 10, 15) = 10\n" + "10 + (15 - 10) * ((10 - 10) / (15-10))^2 = 10"; } TEST(NumberTest, CurveFloatingPoint) { - EXPECT_EQ(ksn::curve(13.0, 10.0, 15.0, 2.0), 11.8) << - "clamp(13, 10, 15) = 13\n" - "10 + (15 - 10) * ((13 - 10) / (15-10))^2 = 11.8"; + EXPECT_EQ(ksn::curve(13.0, 10.0, 15.0, 2.0), 11.8) + << "clamp(13, 10, 15) = 13\n" + "10 + (15 - 10) * ((13 - 10) / (15-10))^2 = 11.8"; - EXPECT_EQ(ksn::curve(31.0, 10.0, 15.0, 2.0), 15.0) << - "clamp(31, 10, 15) = 15\n" - "10 + (15 - 10) * ((15 - 10) / (15-10))^2 = 15"; + EXPECT_EQ(ksn::curve(31.0, 10.0, 15.0, 2.0), 15.0) + << "clamp(31, 10, 15) = 15\n" + "10 + (15 - 10) * ((15 - 10) / (15-10))^2 = 15"; - EXPECT_EQ(ksn::curve(4.0, 10.0, 15.0, 2.0), 10.0) << - "clamp(4, 10, 15) = 10\n" - "10 + (15 - 10) * ((10 - 10) / (15-10))^2 = 10"; + EXPECT_EQ(ksn::curve(4.0, 10.0, 15.0, 2.0), 10.0) + << "clamp(4, 10, 15) = 10\n" + "10 + (15 - 10) * ((10 - 10) / (15-10))^2 = 10"; } TEST(NumberTest, LerpIntegral) { - EXPECT_EQ(ksn::lerp(0, 10, 0), 0) << - "0 + (10 - 0) * 0 = 0"; + EXPECT_EQ(ksn::lerp(0, 10, 0), 0) << "0 + (10 - 0) * 0 = 0"; - EXPECT_EQ(ksn::lerp(5, 15, 1), 15) << - "5 + (15 - 5) * 1 = 15"; + EXPECT_EQ(ksn::lerp(5, 15, 1), 15) << "5 + (15 - 5) * 1 = 15"; } TEST(NumberTest, LerpFloatingPoint) { - EXPECT_DOUBLE_EQ(ksn::lerp(0.0, 10.0, 0.5), 5.0) << - "0 + (10 - 0) * 0.5 = 0"; + EXPECT_DOUBLE_EQ(ksn::lerp(0.0, 10.0, 0.5), 5.0) << "0 + (10 - 0) * 0.5 = 0"; - EXPECT_DOUBLE_EQ(ksn::lerp(5.0, 15.0, 0.25), 7.5) << - "5 + (15 - 5) * 0.25 = 15"; + EXPECT_DOUBLE_EQ(ksn::lerp(5.0, 15.0, 0.25), 7.5) << "5 + (15 - 5) * 0.25 = 15"; } #define ASSERT_SMOOTH_NEAR(SOURCE, TARGET, RATIO, ...) \ - { \ - double _source = SOURCE; \ - double _values[] = {__VA_ARGS__}; \ - size_t index = 0; \ - while (_source < (TARGET - (TARGET * RATIO))) { \ - _source = ksn::smooth(_source, TARGET, RATIO); \ - ASSERT_NEAR(_source, _values[index++], 0.0001); \ - } \ + { \ + double _source = SOURCE; \ + double _values[] = {__VA_ARGS__}; \ + size_t index = 0; \ + while (_source < (TARGET - (TARGET * RATIO))) { \ + _source = ksn::smooth(_source, TARGET, RATIO); \ + ASSERT_NEAR(_source, _values[index++], 0.0001); \ + } \ } TEST(NumberTest, SmoothValue) { ASSERT_SMOOTH_NEAR( - 0.0, 10.0, 0.1, - 1, 1.9, 2.71, 3.439, 4.0951, 4.68559, 5.21703, 5.69533, 6.12579, 6.51322, 6.86189, 7.1757, - 7.45813, 7.71232, 7.94109, 8.14698, 8.33228, 8.49905, 8.64915, 8.78423, 8.90581, 9.01523); + 0.0, 10.0, 0.1, 1, 1.9, 2.71, 3.439, 4.0951, 4.68559, 5.21703, 5.69533, 6.12579, 6.51322, + 6.86189, 7.1757, 7.45813, 7.71232, 7.94109, 8.14698, 8.33228, 8.49905, 8.64915, 8.78423, + 8.90581, 9.01523); ASSERT_SMOOTH_NEAR( - 5.0, 25.0, 0.08, - 6.6, 8.072, 9.42624, 10.6721, 11.8184, 12.8729, 13.8431, 14.7356, 15.5568, 16.3122, 17.0073, - 17.6467, 18.2349, 18.7761, 19.2741, 19.7321, 20.1536, 20.5413, 20.898, 21.2261, 21.528, 21.8058, - 22.0613, 22.2964, 22.5127, 22.7117, 22.8948, 23.0632); + 5.0, 25.0, 0.08, 6.6, 8.072, 9.42624, 10.6721, 11.8184, 12.8729, 13.8431, 14.7356, 15.5568, + 16.3122, 17.0073, 17.6467, 18.2349, 18.7761, 19.2741, 19.7321, 20.1536, 20.5413, 20.898, + 21.2261, 21.528, 21.8058, 22.0613, 22.2964, 22.5127, 22.7117, 22.8948, 23.0632); ASSERT_SMOOTH_NEAR( - 8.0, 101.0, 0.08, - 15.44, 22.2848, 28.582, 34.3755, 39.7054, 44.609, 49.1203, 53.2706, 57.089, 60.6019, 63.8337, - 66.807, 69.5425, 72.0591, 74.3743, 76.5044, 78.464, 80.2669, 81.9256, 83.4515, 84.8554, 86.147, - 87.3352, 88.4284, 89.4341, 90.3594, 91.2106, 91.9938, 92.7143, 93.3771); + 8.0, 101.0, 0.08, 15.44, 22.2848, 28.582, 34.3755, 39.7054, 44.609, 49.1203, 53.2706, 57.089, + 60.6019, 63.8337, 66.807, 69.5425, 72.0591, 74.3743, 76.5044, 78.464, 80.2669, 81.9256, 83.4515, + 84.8554, 86.147, 87.3352, 88.4284, 89.4341, 90.3594, 91.2106, 91.9938, 92.7143, 93.3771); }