Fixed quaternion equals operator

This commit is contained in:
2025-02-09 11:32:46 -05:00
parent b897b13880
commit b21236e5db
4 changed files with 21 additions and 14 deletions

View File

@@ -30,9 +30,9 @@ float Quaternion::operator[](uint8_t index) const
return 1e+6; return 1e+6;
} }
void Quaternion::operator=(const Quaternion &other) const void Quaternion::operator=(const Quaternion &other)
{ {
static_cast<Matrix<1, 4>>(this->matrix) = static_cast<Matrix<1, 4>>(other.matrix); memcpy(&(this->matrix), &(other.matrix), 4 * sizeof(float));
} }
Quaternion Quaternion::operator*(const Quaternion &other) const Quaternion Quaternion::operator*(const Quaternion &other) const

View File

@@ -29,7 +29,7 @@ public:
/** /**
* @brief Assign one quaternion to another * @brief Assign one quaternion to another
*/ */
void operator=(const Quaternion &other) const; void operator=(const Quaternion &other);
/** /**
* @brief Do quaternion multiplication * @brief Do quaternion multiplication

View File

@@ -323,28 +323,25 @@ TEST_CASE("Elementary Matrix Operations", "Matrix")
4, 5, 6, 4, 5, 6,
7, 8, 9}; 7, 8, 9};
Matrix<2, 2> mat5{0}; Matrix<2, 2> mat5 = mat4.SubMatrix<2, 2, 0, 0>();
mat4.SubMatrix(mat5, 0, 0);
REQUIRE(mat5.Get(0, 0) == 1); REQUIRE(mat5.Get(0, 0) == 1);
REQUIRE(mat5.Get(0, 1) == 2); REQUIRE(mat5.Get(0, 1) == 2);
REQUIRE(mat5.Get(1, 0) == 4); REQUIRE(mat5.Get(1, 0) == 4);
REQUIRE(mat5.Get(1, 1) == 5); REQUIRE(mat5.Get(1, 1) == 5);
mat4.SubMatrix(mat5, 1, 1); mat5 = mat4.SubMatrix<2, 2, 1, 1>();
REQUIRE(mat5.Get(0, 0) == 5); REQUIRE(mat5.Get(0, 0) == 5);
REQUIRE(mat5.Get(0, 1) == 6); REQUIRE(mat5.Get(0, 1) == 6);
REQUIRE(mat5.Get(1, 0) == 8); REQUIRE(mat5.Get(1, 0) == 8);
REQUIRE(mat5.Get(1, 1) == 9); REQUIRE(mat5.Get(1, 1) == 9);
Matrix<3, 1> mat6{0}; Matrix<3, 1> mat6 = mat4.SubMatrix<3, 1, 0, 0>();
mat4.SubMatrix(mat6, 0, 0);
REQUIRE(mat6.Get(0, 0) == 1); REQUIRE(mat6.Get(0, 0) == 1);
REQUIRE(mat6.Get(1, 0) == 4); REQUIRE(mat6.Get(1, 0) == 4);
REQUIRE(mat6.Get(2, 0) == 7); REQUIRE(mat6.Get(2, 0) == 7);
Matrix<1, 3> mat7{0}; Matrix<1, 3> mat7 = mat4.SubMatrix<1, 3, 0, 0>();
mat4.SubMatrix(mat7, 0, 0);
REQUIRE(mat7.Get(0, 0) == 1); REQUIRE(mat7.Get(0, 0) == 1);
REQUIRE(mat7.Get(0, 1) == 2); REQUIRE(mat7.Get(0, 1) == 2);
REQUIRE(mat7.Get(0, 2) == 3); REQUIRE(mat7.Get(0, 2) == 3);

View File

@@ -53,6 +53,16 @@ TEST_CASE("Vector Math", "Vector")
REQUIRE(q6.v3 == 4); REQUIRE(q6.v3 == 4);
} }
SECTION("Equals")
{
Quaternion q3{0, 0, 0, 0};
q3 = q1;
REQUIRE(q3.w == 1);
REQUIRE(q3.v1 == 2);
REQUIRE(q3.v2 == 3);
REQUIRE(q3.v3 == 4);
}
SECTION("Array access") SECTION("Array access")
{ {
REQUIRE(q1[0] == 1); REQUIRE(q1[0] == 1);
@@ -64,10 +74,10 @@ TEST_CASE("Vector Math", "Vector")
SECTION("Addition") SECTION("Addition")
{ {
Quaternion q3 = q1 + q2; Quaternion q3 = q1 + q2;
REQUIRE(q3.w == 5); REQUIRE(q3.w == 6);
REQUIRE(q3.v1 == 12); REQUIRE(q3.v1 == 8);
REQUIRE(q3.v2 == 21); REQUIRE(q3.v2 == 10);
REQUIRE(q3.v3 == 32); REQUIRE(q3.v3 == 12);
} }
SECTION("Multiplication") SECTION("Multiplication")