소스 검색

Add getter method for components for Vector2 class

Patrick-Christopher Mattulat 1 년 전
부모
커밋
73c404cc03
3개의 변경된 파일15개의 추가작업 그리고 0개의 파일을 삭제
  1. 1 0
      include/ls-math/vector/Vector2.hpp
  2. 5 0
      source/ls-math/vector/Vector2.cpp
  3. 9 0
      test/cases/vector/Vector2Test.cpp

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

@@ -39,6 +39,7 @@ namespace ls::math::vector
 
       static ls::math::vector::Vector2 add(const ls::math::vector::Vector2& _leftAddend, const ls::math::vector::Vector2& _rightAddend);
       static ls::math::core::type::vector_scalar dot(const ls::math::vector::Vector2& _leftAddend, const ls::math::vector::Vector2& _rightAddend);
+      ls::math::core::type::vector2_components getComponents();
       double getLength();
       ls::math::core::type::vector2_component getX();
       ls::math::core::type::vector2_component getY();

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

@@ -61,6 +61,11 @@ ls::math::core::type::vector_scalar ls::math::vector::Vector2::dot(const ls::mat
   return ls::math::vector::Vector2::_dot(_leftAddend, _rightAddend);
 }
 
+ls::math::core::type::vector2_components ls::math::vector::Vector2::getComponents()
+{
+  return this->components;
+}
+
 double ls::math::vector::Vector2::getLength()
 {
   return ls::math::vector::Vector2::_getLength(this->components[0], this->components[1]);

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

@@ -111,6 +111,15 @@ namespace
     ASSERT_FLOAT_EQ(27, scalar);
   }
 
+  TEST_F(Vector2Test, getComponents)
+  {
+    Vector2 a{6.0f, 8.0f};
+    vector2_components components = a.getComponents();
+
+    ASSERT_FLOAT_EQ(6.0f, components[0]);
+    ASSERT_FLOAT_EQ(8.0f, components[1]);
+  }
+
   TEST_F(Vector2Test, getLength)
   {
     Vector2 a{6, 8};