Преглед изворни кода

Add initial implementation of Vector2 class

Patrick-Christopher Mattulat пре 2 година
родитељ
комит
674162ed05

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+.idea
+cmake-build-*

+ 0 - 8
.idea/ls-math.iml

@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module type="CPP_MODULE" version="4">
-  <component name="NewModuleRootManager">
-    <content url="file://$MODULE_DIR$" />
-    <orderEntry type="inheritedJdk" />
-    <orderEntry type="sourceFolder" forTests="false" />
-  </component>
-</module>

+ 5 - 5
CMakeLists.txt

@@ -89,7 +89,7 @@ endif()
 
 # define which goals can run tests
 
-if (${BUILD_LS_MATH_WITH_TESTS} AND ${BUILD_GOAL_PREFIX_PLACE_HOLDER_MODULE})
+if (${BUILD_LS_MATH_WITH_TESTS} AND ${BUILD_LS_MATH_MODULE})
     message("${PROJECT_NAME}: [Error] building \"${GOAL}\" with tests is not supported... terminated!")
     return()
 endif ()
@@ -98,8 +98,8 @@ endif ()
 # Conan Setup
 ######################################################
 
-include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
-conan_basic_setup()
+# include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+# conan_basic_setup()
 
 ######################################################
 # Include Directories
@@ -134,7 +134,7 @@ endif ()
 ####################################################################################################################
 
 set(SOURCE_FILES_LS_MATH_VECTOR
-        )
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-math/vector/Vector2.cpp)
 
 ####################################################################################################################
 ####################################################################################################################
@@ -146,7 +146,7 @@ set(SOURCE_FILES_LS_MATH_VECTOR
 
 if (${BUILD_LS_MATH_WITH_TESTS})
     set(TEST_FILES_LS_MATH_VECTOR
-            )
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/vector/Vector2Test.cpp)
 endif ()
 
 ####################################################################################################################

+ 21 - 0
include/ls-math/core/types/VectorTypes.hpp

@@ -0,0 +1,21 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-08-05
+ * Changed:         2022-08-05
+ *
+ * */
+
+#ifndef LS_MATH_VECTOR_TYPES_HPP
+#define LS_MATH_VECTOR_TYPES_HPP
+
+#include <array>
+
+namespace ls::math::core::type
+{
+  using vector2_component = double;
+  using vector2_components = std::array<ls::math::core::type::vector2_component, 2>;
+}
+
+#endif

+ 15 - 0
include/ls-math/ls_math_core.hpp

@@ -0,0 +1,15 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-08-05
+ * Changed:         2022-08-05
+ *
+ * */
+
+#ifndef LS_MATH_LS_MATH_CORE_HPP
+#define LS_MATH_LS_MATH_CORE_HPP
+
+#include <ls-math/core/types/VectorTypes.hpp>
+
+#endif

+ 15 - 0
include/ls-math/ls_math_vector.hpp

@@ -0,0 +1,15 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-08-05
+ * Changed:         2022-08-05
+ *
+ * */
+
+#ifndef LS_MATH_LS_MATH_VECTOR_HPP
+#define LS_MATH_LS_MATH_VECTOR_HPP
+
+#include <ls-math/vector/Vector2.hpp>
+
+#endif

+ 0 - 1
include/ls-math/remove_me.txt

@@ -1 +0,0 @@
-Add header files here!

+ 33 - 0
include/ls-math/vector/Vector2.hpp

@@ -0,0 +1,33 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-08-05
+ * Changed:         2022-08-05
+ *
+ * */
+
+#ifndef LS_MATH_VECTOR2_HPP
+#define LS_MATH_VECTOR2_HPP
+
+#include <ls-math/core/types/VectorTypes.hpp>
+#include <cstdlib>
+
+namespace ls::math::vector
+{
+  class Vector2
+  {
+    public:
+
+      Vector2(const ls::math::core::type::vector2_component& _x, const ls::math::core::type::vector2_component& _y);
+      ~Vector2() = default;
+
+      ls::math::core::type::vector2_component getComponent(size_t _index);
+
+    private:
+
+      ls::math::core::type::vector2_components components{};
+  };
+}
+
+#endif

+ 0 - 1
source/ls-math/remove_me.txt

@@ -1 +0,0 @@
-Add source files here!

+ 21 - 0
source/ls-math/vector/Vector2.cpp

@@ -0,0 +1,21 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-08-05
+ * Changed:         2022-08-05
+ *
+ * */
+
+#include <ls-math/vector/Vector2.hpp>
+
+ls::math::vector::Vector2::Vector2(const ls::math::core::type::vector2_component &_x, const ls::math::core::type::vector2_component &_y)
+{
+  this->components[0] = _x;
+  this->components[1] = _y;
+}
+
+ls::math::core::type::vector2_component ls::math::vector::Vector2::getComponent(std::size_t _index)
+{
+  return this->components.at(_index); // TODO: throw IndexOutOfBoundsException
+}

+ 0 - 1
test/cases/remove_me.txt

@@ -1 +0,0 @@
-Add your test cases here!

+ 38 - 0
test/cases/vector/Vector2Test.cpp

@@ -0,0 +1,38 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-08-05
+ * Changed:         2022-08-05
+ *
+ * */
+
+#include <gtest/gtest.h>
+#include <ls-math/ls_math_vector.hpp>
+
+using namespace ls::math::vector;
+
+namespace
+{
+  class Vector2Test : public ::testing::Test
+  {
+    protected:
+
+      Vector2Test() = default;
+      ~Vector2Test() override = default;
+
+      void SetUp() override
+      {}
+
+      void TearDown() override
+      {}
+  };
+
+  TEST_F(Vector2Test, getComponent)
+  {
+    Vector2 a{3, 4};
+
+    ASSERT_FLOAT_EQ(3, a.getComponent(0));
+    ASSERT_FLOAT_EQ(4, a.getComponent(1));
+  }
+}