Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void fokin::MatrixShape::addShape(const shape_ptr &shape)
- {
- if (!shape)
- {
- throw std::invalid_argument("Object does not exist!");
- }
- size_t row = 0;
- size_t column = 0;
- bool add = false;
- for (size_t i = 0; (i < rows_) && (column != columns_) && !add; i++)
- {
- for (size_t j = 0; j < columns_; j++)
- {
- if (array_[i * columns_ + j] == nullptr)
- {
- column = j;
- add = true;
- break;
- }
- if (isOverlapped(shape, array_[i * columns_ + j]))
- {
- row = i + 1;
- break;
- }
- if (j == columns_ - 1)
- {
- column = columns_;
- break;
- }
- }
- }
- if (row == rows_)
- {
- if (columns_ == 0)
- {
- columns_++;
- }
- shape_array temp = std::make_unique<shape_ptr[]>(++rows_ * columns_);
- for (size_t i = 0; i < (rows_ - 1) * columns_; i++)
- {
- temp[i] = array_[i];
- }
- for (size_t i = (rows_ - 1) * columns_; i < rows_ * columns_; i++)
- {
- temp[i] = nullptr;
- }
- array_.swap(temp);
- array_[(rows_ - 1) * columns_] = shape;
- }
- else if (column == columns_)
- {
- shape_array temp = std::make_unique<shape_ptr[]>(rows_ * ++columns_);
- for (size_t i = 0; i < rows_; i++)
- {
- for (size_t j = 0; j < columns_ - 1; j++)
- {
- temp[i * columns_ + j] = array_[i * columns_ + j];
- }
- temp[i * columns_ + columns_ - 1] = nullptr;
- }
- array_.swap(temp);
- array_[row * columns_ + columns_ - 1] = shape;
- }
- else
- {
- array_[row * columns_ + column] = shape;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement