Compare commits
2 Commits
117a3481db
...
e57bd40991
| Author | SHA1 | Date | |
|---|---|---|---|
| e57bd40991 | |||
| c408c76027 |
5
App/.vscode/settings.json
vendored
5
App/.vscode/settings.json
vendored
@ -42,7 +42,10 @@
|
|||||||
"xstddef": "cpp",
|
"xstddef": "cpp",
|
||||||
"xstring": "cpp",
|
"xstring": "cpp",
|
||||||
"xtr1common": "cpp",
|
"xtr1common": "cpp",
|
||||||
"xutility": "cpp"
|
"xutility": "cpp",
|
||||||
|
"list": "cpp",
|
||||||
|
"vector": "cpp",
|
||||||
|
"xtree": "cpp"
|
||||||
},
|
},
|
||||||
"cmake.configureOnOpen": true
|
"cmake.configureOnOpen": true
|
||||||
}
|
}
|
||||||
@ -8,6 +8,9 @@ namespace Core
|
|||||||
class Vector2
|
class Vector2
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
|
||||||
Vector2();
|
Vector2();
|
||||||
Vector2(float x, float y);
|
Vector2(float x, float y);
|
||||||
|
|
||||||
@ -15,18 +18,15 @@ namespace Core
|
|||||||
Vector2 operator-(Vector2 const& other);
|
Vector2 operator-(Vector2 const& other);
|
||||||
Vector2 operator*(Vector2 const& other);
|
Vector2 operator*(Vector2 const& other);
|
||||||
Vector2 operator/(Vector2 const& other);
|
Vector2 operator/(Vector2 const& other);
|
||||||
Vector2 operator+=(Vector2 const& other);
|
Vector2& operator+=(Vector2 const& other);
|
||||||
Vector2 operator-=(Vector2 const& other);
|
Vector2& operator-=(Vector2 const& other);
|
||||||
Vector2 operator*=(Vector2 const& other);
|
Vector2& operator*=(Vector2 const& other);
|
||||||
Vector2 operator/=(Vector2 const& other);
|
Vector2& operator/=(Vector2 const& other);
|
||||||
|
|
||||||
bool operator==(Vector2 const& other);
|
bool operator==(Vector2 const& other);
|
||||||
bool operator!=(Vector2 const& other);
|
bool operator!=(Vector2 const& other);
|
||||||
|
|
||||||
Vector2 operator*(float const& scalar);
|
Vector2 operator*(float const& scalar);
|
||||||
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Vector3
|
class Vector3
|
||||||
@ -37,14 +37,18 @@ namespace Core
|
|||||||
float z;
|
float z;
|
||||||
float w;
|
float w;
|
||||||
|
|
||||||
|
Vector3();
|
||||||
|
Vector3(float x, float y, float z);
|
||||||
|
Vector3(float x, float y, float z, float w);
|
||||||
|
|
||||||
Vector3 operator+(Vector3 const& other);
|
Vector3 operator+(Vector3 const& other);
|
||||||
Vector3 operator-(Vector3 const& other);
|
Vector3 operator-(Vector3 const& other);
|
||||||
Vector3 operator*(Vector3 const& other);
|
Vector3 operator*(Vector3 const& other);
|
||||||
Vector3 operator/(Vector3 const& other);
|
Vector3 operator/(Vector3 const& other);
|
||||||
Vector3 operator+=(Vector3 const& other);
|
Vector3& operator+=(Vector3 const& other);
|
||||||
Vector3 operator-=(Vector3 const& other);
|
Vector3& operator-=(Vector3 const& other);
|
||||||
Vector3 operator*=(Vector3 const& other);
|
Vector3& operator*=(Vector3 const& other);
|
||||||
Vector3 operator/=(Vector3 const& other);
|
Vector3& operator/=(Vector3 const& other);
|
||||||
|
|
||||||
bool operator==(Vector3 const& other);
|
bool operator==(Vector3 const& other);
|
||||||
bool operator!=(Vector3 const& other);
|
bool operator!=(Vector3 const& other);
|
||||||
|
|||||||
@ -27,7 +27,143 @@ namespace Core
|
|||||||
|
|
||||||
Vector2 Vector2::operator/(Vector2 const &other)
|
Vector2 Vector2::operator/(Vector2 const &other)
|
||||||
{
|
{
|
||||||
|
// TODO(Eero): Add Zero checks
|
||||||
return Vector2(this->x/other.x, this->y/other.y);
|
return Vector2(this->x/other.x, this->y/other.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector2& Vector2::operator+=(Vector2 const &other)
|
||||||
|
{
|
||||||
|
this->x += other.x;
|
||||||
|
this->y += other.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2& Vector2::operator-=(Vector2 const &other)
|
||||||
|
{
|
||||||
|
this->x -= other.x;
|
||||||
|
this->y -= other.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2& Vector2::operator*=(Vector2 const &other)
|
||||||
|
{
|
||||||
|
this->x *= other.x;
|
||||||
|
this->y *= other.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2& Vector2::operator/=(Vector2 const &other)
|
||||||
|
{
|
||||||
|
// TODO(Eero): Add Zero checks
|
||||||
|
this->x /= other.x;
|
||||||
|
this->y /= other.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vector2::operator==(Vector2 const &other)
|
||||||
|
{
|
||||||
|
return (this->x == other.x && this->y == other.y) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vector2::operator!=(Vector2 const &other)
|
||||||
|
{
|
||||||
|
return (this->x != other.x || this->y != other.y) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 Vector2::operator*(float const &scalar)
|
||||||
|
{
|
||||||
|
return Vector2(scalar * this->x, scalar * this->y);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3::Vector3() : x(0), y(0), z(0), w(1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3::Vector3(float x, float y, float z) : x(x), y(y), z(z), w(1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3::Vector3(float x, float y, float z, float w) : x(x), y(y), z(z), w(w)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 Vector3::operator+(Vector3 const &other)
|
||||||
|
{
|
||||||
|
return Vector3(this->x+other.x, this->y+other.y, this->z+other.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 Vector3::operator-(Vector3 const &other)
|
||||||
|
{
|
||||||
|
return Vector3(this->x-other.x, this->y-other.y, this->z-other.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 Vector3::operator*(Vector3 const &other)
|
||||||
|
{
|
||||||
|
return Vector3(this->x*other.x, this->y*other.y, this->z*other.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 Vector3::operator/(Vector3 const &other)
|
||||||
|
{
|
||||||
|
// TODO(Eero): Add Zero checks
|
||||||
|
return Vector3(this->x/other.x, this->y/other.y, this->z/other.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3& Vector3::operator+=(Vector3 const &other)
|
||||||
|
{
|
||||||
|
this->x += other.x;
|
||||||
|
this->y += other.y;
|
||||||
|
this->z += other.z;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3& Vector3::operator-=(Vector3 const &other)
|
||||||
|
{
|
||||||
|
this->x -= other.x;
|
||||||
|
this->y -= other.y;
|
||||||
|
this->z -= other.z;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3& Vector3::operator*=(Vector3 const &other)
|
||||||
|
{
|
||||||
|
this->x *= other.x;
|
||||||
|
this->y *= other.y;
|
||||||
|
this->z *= other.z;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3& Vector3::operator/=(Vector3 const &other)
|
||||||
|
{
|
||||||
|
// TODO(Eero): Add Zero checks
|
||||||
|
this->x /= other.x;
|
||||||
|
this->y /= other.y;
|
||||||
|
this->z /= other.z;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vector3::operator==(Vector3 const &other)
|
||||||
|
{
|
||||||
|
return (
|
||||||
|
this->x == other.x
|
||||||
|
&& this->y == other.y
|
||||||
|
&& this->z == other.z
|
||||||
|
&& this->w == other.w // TODO(Eero): Is w check required?
|
||||||
|
) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vector3::operator!=(Vector3 const &other)
|
||||||
|
{
|
||||||
|
return (
|
||||||
|
this->x != other.x
|
||||||
|
|| this->y != other.y
|
||||||
|
|| this->z != other.z
|
||||||
|
|| this->w != other.w // TODO(Eero): Is w check required?
|
||||||
|
) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 Vector3::operator*(float const &scalar)
|
||||||
|
{
|
||||||
|
return Vector3(scalar * this->x, scalar * this->y, scalar * this->z);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
@ -7,9 +7,16 @@ add_executable(
|
|||||||
MathTest.cpp
|
MathTest.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package(GTest CONFIG REQUIRED)
|
target_include_directories(App PUBLIC "${CMAKE_SOURCE_DIR}/AppLib/include/AppLib")
|
||||||
target_link_libraries(AppTest PRIVATE GTest::gtest GTest::gtest_main GTest::gmock GTest::gmock_main)
|
|
||||||
|
|
||||||
|
find_package(GTest CONFIG REQUIRED)
|
||||||
|
target_link_libraries(AppTest PRIVATE
|
||||||
|
GTest::gtest
|
||||||
|
GTest::gtest_main
|
||||||
|
GTest::gmock
|
||||||
|
GTest::gmock_main
|
||||||
|
AppLib
|
||||||
|
)
|
||||||
|
|
||||||
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
||||||
set_property(TARGET AppLib PROPERTY CXX_STANDARD 20)
|
set_property(TARGET AppLib PROPERTY CXX_STANDARD 20)
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include "Math.hh"
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
|
|
||||||
// Demonstrate some basic assertions.
|
// Demonstrate some basic assertions.
|
||||||
TEST(AppTest, BasicAssertions) {
|
TEST(AppTest, BasicAssertions) {
|
||||||
@ -8,6 +11,15 @@ TEST(AppTest, BasicAssertions) {
|
|||||||
EXPECT_EQ(7 * 6, 42);
|
EXPECT_EQ(7 * 6, 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Math, Vector2_Add)
|
||||||
|
{
|
||||||
|
Vector2 vec1(1,2);
|
||||||
|
Vector2 vec2(1.5, -2.5);
|
||||||
|
Vector2 result(vec1.x+vec2.x, vec1.y+vec2.y);
|
||||||
|
ASSERT_FLOAT_EQ(result.x, 2.5);
|
||||||
|
ASSERT_FLOAT_EQ(result.y, -0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user