Refactored file layout because platformio failed to find things

This commit is contained in:
2025-02-08 23:57:43 -05:00
parent 2385446ac5
commit f51afb42e0
15 changed files with 91 additions and 125 deletions

View File

@@ -16,17 +16,5 @@
],
"license": "None Yet",
"frameworks": "*",
"platforms": "*",
"build": {
"srcDir": "src",
"flags": [
"-std=c++17",
"-I src/Vector3D",
"-I src/Matrix",
"-I src/Quaternion"
],
"srcFilter": [
"-<*/unit-tests/>"
]
}
"platforms": "*"
}

View File

@@ -1,4 +1,59 @@
add_subdirectory(Matrix)
add_subdirectory(Quaternion)
add_subdirectory(Vector3D)
# Quaternion Interface
add_library(vector-3d-intf
INTERFACE
)
target_include_directories(vector-3d-intf
INTERFACE
.
)
target_link_libraries(vector-3d-intf
INTERFACE
)
# Quaternion
add_library(quaternion
STATIC
Quaternion.cpp
)
target_link_libraries(quaternion
PUBLIC
vector-3d-intf
PRIVATE
)
set_target_properties(quaternion
PROPERTIES
LINKER_LANGUAGE CXX
)
# Vector3d
add_library(vector-3d
STATIC
Vector3D.cpp
)
target_link_libraries(vector-3d
PUBLIC
vector-3d-intf
PRIVATE
)
# Matrix
add_library(matrix
STATIC
Matrix.cpp
)
target_link_libraries(matrix
PUBLIC
vector-3d-intf
PRIVATE
)
set_target_properties(matrix
PROPERTIES
LINKER_LANGUAGE CXX
)

View File

@@ -1,35 +0,0 @@
# Matrix Interface
add_library(matrix-intf
INTERFACE
)
target_include_directories(matrix-intf
INTERFACE
.
)
# Matrix
add_library(matrix
STATIC
Matrix.cpp
)
target_link_libraries(matrix
PUBLIC
matrix-intf
PRIVATE
)
set_target_properties(matrix
PROPERTIES
LINKER_LANGUAGE CXX
)
# matrix tests
add_executable(matrix-tests unit-tests/matrix-tests.cpp)
target_link_libraries(matrix-tests
PRIVATE
matrix-intf
Catch2::Catch2WithMain
)

View File

@@ -49,7 +49,7 @@ Quaternion Quaternion::operator*(float scalar) const
Quaternion Quaternion::operator+(const Quaternion &other) const
{
return Quaternion{this->w * other.w, this->v1 * other.v1, this->v2 * other.v2, this->v3 * other.v3};
return Quaternion{this->w + other.w, this->v1 + other.v1, this->v2 + other.v2, this->v3 + other.v3};
}
Quaternion &
@@ -81,6 +81,10 @@ Quaternion &Quaternion::Rotate(Quaternion &other, Quaternion &buffer) const
void Quaternion::Normalize()
{
float magnitude = sqrt(this->v1 * this->v1 + this->v2 * this->v2 + this->v3 * this->v3 + this->w * this->w);
if (magnitude == 0)
{
return;
}
this->v1 /= magnitude;
this->v2 /= magnitude;
this->v3 /= magnitude;

View File

@@ -2,7 +2,6 @@
#define QUATERNION_H_
#include "Matrix.hpp"
class Quaternion : public Matrix<1, 4>
{
public:
@@ -70,7 +69,7 @@ public:
*/
void Normalize();
Matrix<3,3> ToRotationMatrix() const;
Matrix<3, 3> ToRotationMatrix() const;
// Give people an easy way to access the elements
float &w{matrix[0]};

View File

@@ -1,40 +0,0 @@
# Quaternion Interface
add_library(quaternion-intf
INTERFACE
)
target_include_directories(quaternion-intf
INTERFACE
.
)
target_link_libraries(quaternion-intf
INTERFACE
matrix-intf
)
# Quaternion
add_library(quaternion
STATIC
Quaternion.cpp
)
target_link_libraries(quaternion
PUBLIC
quaternion-intf
PRIVATE
)
set_target_properties(quaternion
PROPERTIES
LINKER_LANGUAGE CXX
)
# Quaternion tests
add_executable(quaternion-tests unit-tests/quaternion-tests.cpp)
target_link_libraries(quaternion-tests
PRIVATE
quaternion
Catch2::Catch2WithMain
)

View File

@@ -1,31 +0,0 @@
# Vector 3D Interface
add_library(vector-3d-intf
INTERFACE
)
target_include_directories(vector-3d-intf
INTERFACE
.
)
# Vector3d
add_library(vector-3d
STATIC
Vector3D.cpp
)
target_link_libraries(vector-3d
PUBLIC
vector-3d-intf
PRIVATE
)
# vector tests
add_executable(vector-tests unit-tests/vector-tests.cpp)
target_link_libraries(vector-tests
PRIVATE
matrix-intf
vector-3d-intf
Catch2::Catch2WithMain
)

26
unit-tests/CMakeLists.txt Normal file
View File

@@ -0,0 +1,26 @@
# Quaternion tests
add_executable(quaternion-tests unit-tests/quaternion-tests.cpp)
target_link_libraries(quaternion-tests
PRIVATE
vector-3d-intf
Catch2::Catch2WithMain
)
# matrix tests
add_executable(matrix-tests unit-tests/matrix-tests.cpp)
target_link_libraries(matrix-tests
PRIVATE
vector-3d-intf
Catch2::Catch2WithMain
)
# Vector 3D Tests
add_executable(vector-3d-tests unit-tests/vector-tests.cpp)
target_link_libraries(vector-3d-tests
PRIVATE
vector-3d-intf
Catch2::Catch2WithMain
)