Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
SquareGrid8.hpp
Go to the documentation of this file.
1
6// Copyright (c) 2017 Czech Technical University in Prague | Faculty of Information Technology. All rights reserved.
7
8#pragma once
9
10#include <alib/pair>
11#include <alib/tuple>
12
13#include "SquareGrid.hpp"
14
15namespace grid {
16
17template<typename TCoordinate, typename TEdge>
18class SquareGrid8 final : public SquareGrid<TCoordinate, TEdge> {
19// ---------------------------------------------------------------------------------------------------------------------
20
21 public:
22 using coordinate_type = TCoordinate;
23 using edge_type = TEdge;
26
27// =====================================================================================================================
28// Constructor, Destructor, Operators
29 public:
30 explicit SquareGrid8(TCoordinate height, TCoordinate width);
31
32// =====================================================================================================================
33// GridBase interface
34 public:
35 auto operator <=> ( const SquareGrid8 & other ) const {
36 return std::tie(this->m_obstacles, this->m_height, this->m_width) <=> std::tie(other.getObstacleList(), other.getHeight(), other.getWidth());
37 }
38
39 bool operator == ( const SquareGrid8 & other ) const {
40 return std::tie(this->m_obstacles, this->m_height, this->m_width) == std::tie(other.getObstacleList(), other.getHeight(), other.getWidth());
41 }
42
43// =====================================================================================================================
44// GridInterface interface
45
46 public:
47
48 bool isValidDirection(direction_type direction) const override;
49
50// ---------------------------------------------------------------------------------------------------------------------
51
52 protected:
53 TEdge createEdge(const node_type &a, const node_type &b) const override;
54
55// ---------------------------------------------------------------------------------------------------------------------
56// =====================================================================================================================
57// GraphInterface interface
58
59 std::string name() const override;
60
61// ---------------------------------------------------------------------------------------------------------------------
62
63};
64
65// =====================================================================================================================
66
67template<typename TCoordinate, typename TEdge>
68SquareGrid8<TCoordinate, TEdge>::SquareGrid8(TCoordinate height, TCoordinate width)
69 : SquareGrid<TCoordinate, TEdge>(height, width) {
70}
71
72// ---------------------------------------------------------------------------------------------------------------------
73
74template<typename TCoordinate, typename TEdge>
76 const SquareGrid8::node_type &b) const {
77 return TEdge(a, b);
78}
79
80// ---------------------------------------------------------------------------------------------------------------------
81
82template<typename TCoordinate, typename TEdge>
84 return SQUARE_GRID_DIRECTIONS.find(direction) != SQUARE_GRID_DIRECTIONS.end();
85}
86
87// ---------------------------------------------------------------------------------------------------------------------
88
89template<typename TCoordinate, typename TEdge>
91 return "SquareGrid8";
92}
93
94// ---------------------------------------------------------------------------------------------------------------------
95
96} // namespace grid
97
98// =====================================================================================================================
99
100namespace core {
101
108template<typename TCoordinate, typename TEdge>
109struct normalize < grid::SquareGrid8 < TCoordinate, TEdge > > {
111 grid::SquareGrid8<> grid(value.getHeight(), value.getWidth());
112
113 // Copy obstacles
114 for (auto &&i: ext::make_mover(std::move(value).getObstacleList())) {
116 obstacle = graph::GraphNormalize::normalizeObstacle(std::move(i));
117
118 grid.addObstacle(std::move(obstacle));
119 }
120
121 return grid;
122 }
123};
124
125} // namespace grid
126
127// =====================================================================================================================
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
static ext::pair< DefaultCoordinateType, DefaultCoordinateType > normalizeObstacle(ext::pair< TCoordinate, TCoordinate > &&obstacle)
Definition: Normalize.hpp:82
TCoordinate coordinate_type
Definition: GridInterface.hpp:23
TEdge edge_type
Definition: GridInterface.hpp:24
Definition: SquareGrid8.hpp:18
SquareGridDirections direction_type
Definition: SquareGrid8.hpp:25
SquareGrid8(TCoordinate height, TCoordinate width)
Definition: SquareGrid8.hpp:68
bool operator==(const SquareGrid8 &other) const
Definition: SquareGrid8.hpp:39
std::string name() const override
Definition: SquareGrid8.hpp:90
bool isValidDirection(direction_type direction) const override
Definition: SquareGrid8.hpp:83
auto operator<=>(const SquareGrid8 &other) const
Definition: SquareGrid8.hpp:35
ext::pair< TCoordinate, TCoordinate > node_type
Definition: SquareGrid8.hpp:24
TEdge createEdge(const node_type &a, const node_type &b) const override
Definition: SquareGrid8.hpp:75
Definition: SquareGrid.hpp:29
TCoordinate getHeight() const
Definition: SquareGrid.hpp:155
TCoordinate getWidth() const
Definition: SquareGrid.hpp:160
TCoordinate m_height
Definition: SquareGrid.hpp:41
TCoordinate m_width
Definition: SquareGrid.hpp:42
ext::set< node_type > m_obstacles
Definition: SquareGrid.hpp:43
const ext::set< node_type > & getObstacleList() const &
Definition: SquareGrid.hpp:142
int i
Definition: AllEpsilonClosure.h:118
Definition: normalize.hpp:10
constexpr tuple< Elements &... > tie(Elements &... args) noexcept
Helper of extended tuple of references construction. The tuple is constructed to reffer to values in ...
Definition: tuple.hpp:218
reference_mover< T > make_mover(T &param)
Move adaptor construction function specialized to lvalue reference parameter.
Definition: iterator.hpp:468
Definition: GridDirection.hpp:12
const ext::set< SquareGridDirections > SQUARE_GRID_DIRECTIONS
Definition: GridDirection.hpp:28
SquareGridDirections
Definition: GridDirection.hpp:16
static grid::SquareGrid8 eval(grid::SquareGrid8< TCoordinate, TEdge > &&value)
Definition: SquareGrid8.hpp:110
Definition: normalize.hpp:13