готово

This commit is contained in:
2026-02-27 00:18:40 +03:00
parent 42a1507536
commit b01aecc2fe
3 changed files with 28 additions and 31 deletions

View File

@@ -25,7 +25,6 @@
#ifndef PIVECTOR2D_H #ifndef PIVECTOR2D_H
#define PIVECTOR2D_H #define PIVECTOR2D_H
#include "pipair.h"
#include "pivector.h" #include "pivector.h"
//! \addtogroup Containers //! \addtogroup Containers
@@ -598,6 +597,10 @@ public:
PIVector<T> * p_; PIVector<T> * p_;
public: public:
using ColConst::operator[];
using ColConst::data;
using ColConst::size;
//! \~english Accesses the element at the given row index within the column. //! \~english Accesses the element at the given row index within the column.
//! \~russian Доступ к элементу по заданному индексу строки в столбце. //! \~russian Доступ к элементу по заданному индексу строки в столбце.
//! \return Reference to the element. //! \return Reference to the element.
@@ -618,7 +621,7 @@ public:
if (p_ == other.p_ && this->col_ == other.col_) return *this; if (p_ == other.p_ && this->col_ == other.col_) return *this;
const size_t sz = piMin<size_t>(this->sz_, other.sz_); const size_t sz = piMin<size_t>(this->sz_, other.sz_);
for (size_t i = 0; i < sz; ++i) 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; return *this;
} }
@@ -942,7 +945,7 @@ public:
inline Index indexOf(const T & e) const { inline Index indexOf(const T & e) const {
ssize_t flat = mat.indexOf(e); ssize_t flat = mat.indexOf(e);
if (flat < 0 || cols_ == 0) return Index{-1, -1}; if (flat < 0 || cols_ == 0) return Index{-1, -1};
return Index{flat / cols_, flat % cols_}; return Index{flat / static_cast<ssize_t>(cols_), flat % static_cast<ssize_t>(cols_)};
} }
//! \~english Returns the first index (row, col) in the 2D array that passes the `test`. //! \~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<bool(const T & e)> test, ssize_t start = 0) const { inline Index indexWhere(std::function<bool(const T & e)> test, ssize_t start = 0) const {
ssize_t flat = mat.indexWhere(test, start); ssize_t flat = mat.indexWhere(test, start);
if (flat < 0 || cols_ == 0) return Index{-1, -1}; if (flat < 0 || cols_ == 0) return Index{-1, -1};
return Index{flat / cols_, flat % cols_}; return Index{flat / static_cast<ssize_t>(cols_), flat % static_cast<ssize_t>(cols_)};
} }
//! \~english Returns the last index (row, col) of `e` in the 2D array. //! \~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 { inline Index lastIndexOf(const T & e, ssize_t start = -1) const {
ssize_t flat = mat.lastIndexOf(e, start); ssize_t flat = mat.lastIndexOf(e, start);
if (flat < 0 || cols_ == 0) return Index{-1, -1}; if (flat < 0 || cols_ == 0) return Index{-1, -1};
return Index{flat / cols_, flat % cols_}; return Index{flat / static_cast<ssize_t>(cols_), flat % static_cast<ssize_t>(cols_)};
} }
//! \~english Returns the last index (row, col) in the 2D array that passes the `test`. //! \~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<bool(const T & e)> test, ssize_t start = -1) const { inline Index lastIndexWhere(std::function<bool(const T & e)> test, ssize_t start = -1) const {
ssize_t flat = mat.lastIndexWhere(test, start); ssize_t flat = mat.lastIndexWhere(test, start);
if (flat < 0 || cols_ == 0) return Index{-1, -1}; if (flat < 0 || cols_ == 0) return Index{-1, -1};
return Index{flat / cols_, flat % cols_}; return Index{flat / static_cast<ssize_t>(cols_), flat % static_cast<ssize_t>(cols_)};
} }

View File

@@ -3,32 +3,26 @@
## Этап 1: Сборка ## Этап 1: Сборка
### 1.1 Собрать проект ### 1.1 Собрать проект
- собери проект, при необходимости поправь ошибки - [x] собери проект, при необходимости поправь ошибки
## Этап 2: Проверить и поправить тесты ## Этап 2: Проверить и поправить тесты
### 2.1 Запустить тесты ### 2.1 Запустить тесты
- Запустить: `./build/tests/pip_math_test --gtest_filter="*Vector2D*"` - [x] Запустить: `./build/tests/pip_math_test --gtest_filter="*Vector2D*"`
- В случае ошибок внести правки в pivector2d.h - [x] В случае ошибок внести правки в pivector2d.h
--- ---
## Этап 3: Заменить PIPair<ssize_t, ssize_t> на PIVector2DIndex ## Этап 3: Заменить PIPair<ssize_t, ssize_t> на PIVector2DIndex
### 3.1 Создать структуру PIVector2DIndex ### 3.1 Создать структуру PIVector2DIndex
```cpp - [x] Создано: `struct Index { ssize_t row; ssize_t col; };`
struct Index {
ssize_t row;
ssize_t col;
};
```
### 3.2 Обновить return types ### 3.2 Обновить return types
Методы для изменения: - [x] indexOf() -> возвращает Index вместо PIPair<ssize_t, ssize_t>
- indexOf() -> возвращает PIVector2DIndex вместо PIPair<ssize_t, ssize_t> - [x] lastIndexOf()
- lastIndexOf() - [x] indexWhere()
- indexWhere() - [x] lastIndexWhere()
- lastIndexWhere()
--- ---