Got vector unit tests compiling

This commit is contained in:
2025-02-03 11:59:49 -05:00
parent ae4806510b
commit 4a25414b92
8 changed files with 137 additions and 58 deletions

View File

@@ -1,73 +1,99 @@
#ifdef MATRIX_H_ // since the .cpp file has to be included by the .hpp file this
// will evaluate to true
#include "Vector3D.hpp"
#ifdef VECTOR3D_H_ // since the .cpp file has to be included by the .hpp file this
// will evaluate to true
#include <cmath>
#include <type_traits>
template <typename Type>
constexpr V3D<type>::V3D(const Matrix<1, 3> &other) : x(other[0][0]), y(other[0][1]), z(other[0][2]) {}
V3D<Type>::V3D(const Matrix<1, 3> &other)
{
this->x = other.Get(0, 0);
this->y = other.Get(0, 1);
this->z = other.Get(0, 2);
}
template <typename Type>
constexpr V3D<type>::V3D(const Matrix<3, 1> &other) : x(other[0][0]), y(other[1][0]), z(other[2][0]) {}
V3D<Type>::V3D(const Matrix<3, 1> &other)
{
this->x = other.Get(0, 0);
this->y = other.Get(1, 0);
this->z = other.Get(2, 0);
}
template <typename Type>
constexpr V3D<type>::V3D(const V3D &other) : x(other.x),
y(other.y),
z(other.z)
V3D<Type>::V3D(const V3D &other) : x(other.x),
y(other.y),
z(other.z)
{
static_assert(std::is_arithmetic<Type>::value, "Type must be a number");
}
template <typename Type>
constexpr V3D<type>::V3D(Type x = 0, Type y = 0, Type z = 0) : x(x),
y(y),
z(z)
V3D<Type>::V3D(Type x, Type y, Type z) : x(x),
y(y),
z(z)
{
static_assert(std::is_arithmetic<Type>::value, "Type must be a number");
}
template <typename Type, typename OtherType>
constexpr V3D<type>::V3D(const V3D<OtherType> other) : x(static_cast<Type>(other.x)),
y(static_cast<Type>(other.y)),
z(static_cast<Type>(other.z))
template <typename Type>
template <typename OtherType>
V3D<Type>::V3D(const V3D<OtherType> &other)
{
static_assert(std::is_arithmetic<Type>::value, "Type must be a number");
static_assert(std::is_arithmetic<OtherType>::value, "OtherType must be a number");
this->x = static_cast<Type>(other.x);
this->y = static_cast<Type>(other.y);
this->z = static_cast<Type>(other.z);
}
template <typename Type>
std::array<Type, 3> V3D<type>::ToArray()
std::array<Type, 3> V3D<Type>::ToArray()
{
return {this->x, this->y, this->z};
}
template <typename Type>
V3D &V3D<type>::operator=(const V3D &other)
void V3D<Type>::operator=(const V3D<Type> &other)
{
this->x = other.x;
this->y = other.y;
this->z = other.z;
return *this;
}
template <typename Type>
V3D &V3D<type>::operator+=(const V3D &other)
V3D<Type> V3D<Type>::operator+(const V3D<Type> &other)
{
this->x += other.x;
this->y += other.y;
this->z += other.z;
return *this;
return V3D<Type>{this->x + other.x, this->y + other.y, this->z + other.z};
}
template <typename Type>
V3D &V3D<type>::operator-=(const V3D &other)
V3D<Type> V3D<Type>::operator-(const V3D<Type> &other)
{
this->x -= other.x;
this->y -= other.y;
this->z -= other.z;
return V3D<Type>{this->x - other.x, this->y - other.y, this->z - other.z};
}
template <typename Type>
V3D<Type> V3D<Type>::operator*(Type scalar)
{
return V3D<Type>{this->x * scalar, this->y * scalar, this->z * scalar};
}
template <typename Type>
V3D<Type> &V3D<Type>::operator+=(const V3D<Type> &other)
{
*this = *this + other;
return *this;
}
template <typename Type>
V3D &V3D<type>::operator/=(const Type scalar)
V3D<Type> &V3D<Type>::operator-=(const V3D<Type> &other)
{
*this = *this - other;
return *this;
}
template <typename Type>
V3D<Type> &V3D<Type>::operator/=(Type scalar)
{
if (scalar == 0)
{
@@ -80,7 +106,7 @@ V3D &V3D<type>::operator/=(const Type scalar)
}
template <typename Type>
V3D &V3D<type>::operator*=(const Type scalar)
V3D<Type> &V3D<Type>::operator*=(Type scalar)
{
this->x *= scalar;
this->y *= scalar;
@@ -89,15 +115,15 @@ V3D &V3D<type>::operator*=(const Type scalar)
}
template <typename Type>
bool V3D<type>::operator==(const V3D &other)
bool V3D<Type>::operator==(const V3D<Type> &other)
{
return this->x == other.x && this->y == other.y && this->z == other.z;
}
template <typename Type>
float V3D<type>::magnitude()
float V3D<Type>::magnitude()
{
return std::sqrt(static_cast<float>(this->x * this->x + this->y * this->y + this->z * this->z));
}
#endif // MATRIX_H_
#endif // VECTOR3D_H_