From 3908dd75438de89ebec2b0737634faf23ce93884 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 16 Feb 2022 19:42:50 +0100 Subject: refactor: delete vector2 copy --- src/app/maze.tpp | 11 ++++++----- src/engine/vector2.cpp | 5 ----- src/engine/vector2.hpp | 7 ------- 3 files changed, 6 insertions(+), 17 deletions(-) (limited to 'src') 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 #include #include @@ -24,7 +25,7 @@ std::vector> get_neighbours(Matrix *matrix, if (pos->y() != 1U) { - auto pos_down = (*pos - Vector2({.x = 0U, .y = 2U})).copy(); + auto pos_down = std::make_shared(*pos - Vector2({.x = 0U, .y = 2U})); if (matrix->get(*pos_down) != space_element) { @@ -34,7 +35,7 @@ std::vector> get_neighbours(Matrix *matrix, if (pos->y() != matrix->rows() - 2U) { - auto pos_up = (*pos + Vector2({.x = 0U, .y = 2U})).copy(); + auto pos_up = std::make_shared(*pos + Vector2({.x = 0U, .y = 2U})); if (matrix->get(*pos_up) != space_element) { @@ -44,7 +45,7 @@ std::vector> get_neighbours(Matrix *matrix, if (pos->x() != 1U) { - auto pos_left = (*pos - Vector2({.x = 2U, .y = 0U})).copy(); + auto pos_left = std::make_shared(*pos - Vector2({.x = 2U, .y = 0U})); if (matrix->get(*pos_left) != space_element) { @@ -54,7 +55,7 @@ std::vector> get_neighbours(Matrix *matrix, if (pos->x() != matrix->columns() - 2U) { - auto pos_right = (*pos + Vector2({.x = 2U, .y = 0U})).copy(); + auto pos_right = std::make_shared(*pos + Vector2({.x = 2U, .y = 0U})); if (matrix->get(*pos_right) != space_element) { @@ -132,7 +133,7 @@ void matrix_to_maze(Matrix *matrix, std::shared_ptr start_pos, auto next_pos = neighbours[random_gen->in_range( 0U, static_cast(neighbours.size()) - 1U)]; - auto between_pos = pos->copy(); + auto between_pos = std::make_shared(*pos); if (next_pos->y() != pos->y()) { diff --git a/src/engine/vector2.cpp b/src/engine/vector2.cpp index d091ea5..2d2283b 100644 --- a/src/engine/vector2.cpp +++ b/src/engine/vector2.cpp @@ -24,11 +24,6 @@ void Vector2::y(unsigned int y) _y = y; } -std::shared_ptr Vector2::copy() -{ - return std::make_shared(*this); -} - Vector2 Vector2::operator*(const Vector2 &vector2) const { return Vector2({.x = _x * vector2.x(), .y = _y * vector2.y()}); diff --git a/src/engine/vector2.hpp b/src/engine/vector2.hpp index 8423431..f69008f 100644 --- a/src/engine/vector2.hpp +++ b/src/engine/vector2.hpp @@ -43,13 +43,6 @@ public: */ void y(unsigned int y); - /** - * Creates a copy of the 2D vector. - * - * @returns A identical 2D vector. - */ - std::shared_ptr copy(); - Vector2 operator*(const Vector2 &vector2) const; Vector2 operator+(const Vector2 &vector2) const; Vector2 operator-(const Vector2 &vector2) const; -- cgit v1.2.3-18-g5258