aboutsummaryrefslogtreecommitdiff
path: root/src/app/maze.tpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-02-16 19:42:50 +0100
committerHampusM <hampus@hampusmat.com>2022-02-16 19:42:50 +0100
commit3908dd75438de89ebec2b0737634faf23ce93884 (patch)
treecd4183ab6a3b07e747b75dafafb1e8a819304e10 /src/app/maze.tpp
parent91286f9dbb85fc2805345ba72468d5f145228be8 (diff)
refactor: delete vector2 copy
Diffstat (limited to 'src/app/maze.tpp')
-rw-r--r--src/app/maze.tpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/app/maze.tpp b/src/app/maze.tpp
index 1ed69ac..f0098a1 100644
--- a/src/app/maze.tpp
+++ b/src/app/maze.tpp
@@ -4,6 +4,7 @@
#include "app/stack.hpp"
+#include <memory>
#include <utility>
#include <vector>
@@ -24,7 +25,7 @@ std::vector<std::shared_ptr<Vector2>> get_neighbours(Matrix<Element> *matrix,
if (pos->y() != 1U)
{
- auto pos_down = (*pos - Vector2({.x = 0U, .y = 2U})).copy();
+ auto pos_down = std::make_shared<Vector2>(*pos - Vector2({.x = 0U, .y = 2U}));
if (matrix->get(*pos_down) != space_element)
{
@@ -34,7 +35,7 @@ std::vector<std::shared_ptr<Vector2>> get_neighbours(Matrix<Element> *matrix,
if (pos->y() != matrix->rows() - 2U)
{
- auto pos_up = (*pos + Vector2({.x = 0U, .y = 2U})).copy();
+ auto pos_up = std::make_shared<Vector2>(*pos + Vector2({.x = 0U, .y = 2U}));
if (matrix->get(*pos_up) != space_element)
{
@@ -44,7 +45,7 @@ std::vector<std::shared_ptr<Vector2>> get_neighbours(Matrix<Element> *matrix,
if (pos->x() != 1U)
{
- auto pos_left = (*pos - Vector2({.x = 2U, .y = 0U})).copy();
+ auto pos_left = std::make_shared<Vector2>(*pos - Vector2({.x = 2U, .y = 0U}));
if (matrix->get(*pos_left) != space_element)
{
@@ -54,7 +55,7 @@ std::vector<std::shared_ptr<Vector2>> get_neighbours(Matrix<Element> *matrix,
if (pos->x() != matrix->columns() - 2U)
{
- auto pos_right = (*pos + Vector2({.x = 2U, .y = 0U})).copy();
+ auto pos_right = std::make_shared<Vector2>(*pos + Vector2({.x = 2U, .y = 0U}));
if (matrix->get(*pos_right) != space_element)
{
@@ -132,7 +133,7 @@ void matrix_to_maze(Matrix<Element> *matrix, std::shared_ptr<Vector2> start_pos,
auto next_pos = neighbours[random_gen->in_range(
0U, static_cast<unsigned int>(neighbours.size()) - 1U)];
- auto between_pos = pos->copy();
+ auto between_pos = std::make_shared<Vector2>(*pos);
if (next_pos->y() != pos->y())
{