diff --git a/libs/main/containers/pivector2d.h b/libs/main/containers/pivector2d.h index e1006d46..15e38c2c 100644 --- a/libs/main/containers/pivector2d.h +++ b/libs/main/containers/pivector2d.h @@ -25,7 +25,6 @@ #ifndef PIVECTOR2D_H #define PIVECTOR2D_H -#include "pipair.h" #include "pivector.h" //! \addtogroup Containers @@ -598,6 +597,10 @@ public: PIVector * p_; public: + using ColConst::operator[]; + using ColConst::data; + using ColConst::size; + //! \~english Accesses the element at the given row index within the column. //! \~russian Доступ к элементу по заданному индексу строки в столбце. //! \return Reference to the element. @@ -618,7 +621,7 @@ public: if (p_ == other.p_ && this->col_ == other.col_) return *this; const size_t sz = piMin(this->sz_, other.sz_); for (size_t i = 0; i < sz; ++i) - (*p_)[i * this->step_ + this->col_] = other.ColConst::operator[](i); + (*p_)[i * this->step_ + this->col_] = other[i]; return *this; } @@ -942,7 +945,7 @@ public: inline Index indexOf(const T & e) const { ssize_t flat = mat.indexOf(e); if (flat < 0 || cols_ == 0) return Index{-1, -1}; - return Index{flat / cols_, flat % cols_}; + return Index{flat / static_cast(cols_), flat % static_cast(cols_)}; } //! \~english Returns the first index (row, col) in the 2D array that passes the `test`. @@ -951,7 +954,7 @@ public: inline Index indexWhere(std::function test, ssize_t start = 0) const { ssize_t flat = mat.indexWhere(test, start); if (flat < 0 || cols_ == 0) return Index{-1, -1}; - return Index{flat / cols_, flat % cols_}; + return Index{flat / static_cast(cols_), flat % static_cast(cols_)}; } //! \~english Returns the last index (row, col) of `e` in the 2D array. @@ -960,7 +963,7 @@ public: inline Index lastIndexOf(const T & e, ssize_t start = -1) const { ssize_t flat = mat.lastIndexOf(e, start); if (flat < 0 || cols_ == 0) return Index{-1, -1}; - return Index{flat / cols_, flat % cols_}; + return Index{flat / static_cast(cols_), flat % static_cast(cols_)}; } //! \~english Returns the last index (row, col) in the 2D array that passes the `test`. @@ -969,7 +972,7 @@ public: inline Index lastIndexWhere(std::function test, ssize_t start = -1) const { ssize_t flat = mat.lastIndexWhere(test, start); if (flat < 0 || cols_ == 0) return Index{-1, -1}; - return Index{flat / cols_, flat % cols_}; + return Index{flat / static_cast(cols_), flat % static_cast(cols_)}; } diff --git a/plans/pivector2d.md b/plans/pivector2d.md index c59c0cf5..6e9c751a 100644 --- a/plans/pivector2d.md +++ b/plans/pivector2d.md @@ -3,32 +3,26 @@ ## Этап 1: Сборка ### 1.1 Собрать проект -- собери проект, при необходимости поправь ошибки +- [x] собери проект, при необходимости поправь ошибки ## Этап 2: Проверить и поправить тесты ### 2.1 Запустить тесты -- Запустить: `./build/tests/pip_math_test --gtest_filter="*Vector2D*"` -- В случае ошибок внести правки в pivector2d.h +- [x] Запустить: `./build/tests/pip_math_test --gtest_filter="*Vector2D*"` +- [x] В случае ошибок внести правки в pivector2d.h --- ## Этап 3: Заменить PIPair на PIVector2DIndex ### 3.1 Создать структуру PIVector2DIndex -```cpp -struct Index { - ssize_t row; - ssize_t col; -}; -``` +- [x] Создано: `struct Index { ssize_t row; ssize_t col; };` ### 3.2 Обновить return types -Методы для изменения: -- indexOf() -> возвращает PIVector2DIndex вместо PIPair -- lastIndexOf() -- indexWhere() -- lastIndexWhere() +- [x] indexOf() -> возвращает Index вместо PIPair +- [x] lastIndexOf() +- [x] indexWhere() +- [x] lastIndexWhere() --- diff --git a/tests/math/testpivector2d.cpp b/tests/math/testpivector2d.cpp index e0f626ae..c12aa631 100644 --- a/tests/math/testpivector2d.cpp +++ b/tests/math/testpivector2d.cpp @@ -952,38 +952,38 @@ TEST_F(Vector2DTest, forEach_modifying_changes_elements) { TEST_F(Vector2DTest, indexOf_returns_correct_pair) { auto p = vec.indexOf(vec.element(10, 15)); - EXPECT_EQ(p.row, 10); - EXPECT_EQ(p.col, 15); + EXPECT_EQ(p.row, 10); + EXPECT_EQ(p.col, 15); p = vec.indexOf(-999); - EXPECT_EQ(p.row, -1); - EXPECT_EQ(p.col, -1); + EXPECT_EQ(p.row, -1); + EXPECT_EQ(p.col, -1); } TEST_F(Vector2DTest, indexWhere_returns_correct_pair) { vec.element(5, 5) = -42; auto isTarget = [](const int & e) { return e == -42; }; auto p = vec.indexWhere(isTarget); - EXPECT_EQ(p.row, 5); - EXPECT_EQ(p.col, 5); + EXPECT_EQ(p.row, 5); + EXPECT_EQ(p.col, 5); } TEST_F(Vector2DTest, lastIndexOf_works) { int val = vec.element(10, 10); vec.element(20, 20) = val; // duplicate auto p = vec.lastIndexOf(val); - EXPECT_EQ(p.row, 20); - EXPECT_EQ(p.col, 20); + EXPECT_EQ(p.row, 20); + EXPECT_EQ(p.col, 20); } TEST_F(Vector2DTest, lastIndexWhere_works) { auto isLarge = [](const int & e) { return e > 500; }; auto p = vec.lastIndexWhere(isLarge); - EXPECT_GE(p.row, 0); - EXPECT_GE(p.col, 0); + EXPECT_GE(p.row, 0); + EXPECT_GE(p.col, 0); // The last element with value >500 should be the largest index size_t lastFlat = p.row * vec.cols() + p.col; size_t expectedLastFlat = vec.size() - 1; - EXPECT_EQ(lastFlat, expectedLastFlat); + EXPECT_EQ(lastFlat, expectedLastFlat); } TEST_F(Vector2DTest, reduce_accumulates_correctly) {