Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
GridFunction.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/set>
13
14namespace grid {
15
17// ---------------------------------------------------------------------------------------------------------------------
18 public:
19
20 template<typename TCoordinate>
21 static
25
26// ---------------------------------------------------------------------------------------------------------------------
27 template<typename TCoordinate>
28 static
31
32// ---------------------------------------------------------------------------------------------------------------------
33
34 static
37
38// ---------------------------------------------------------------------------------------------------------------------
39
40 static
41 bool
43
44 static
45 bool
47
48// ---------------------------------------------------------------------------------------------------------------------
49
50};
51
52// =====================================================================================================================
53
54template<typename TCoordinate>
58 using direction_type = grid::SquareGridDirections;
59
60 TCoordinate x = b.first - a.first;
61 TCoordinate y = b.second - a.second;
62
63 if (x < 0 && y == 0) return direction_type::north;
64 else if (x > 0 && y == 0) return direction_type::south;
65 else if (x == 0 && y < 0) return direction_type::west;
66 else if (x == 0 && y > 0) return direction_type::east;
67 else if (x < 0 && y < 0) return direction_type::north_west;
68 else if (x > 0 && y < 0) return direction_type::south_west;
69 else if (x < 0 && y > 0) return direction_type::north_east;
70 else if (x > 0 && y > 0) return direction_type::south_east;
71 else return direction_type::none;
72}
73
74// ---------------------------------------------------------------------------------------------------------------------
75
76template<typename TCoordinate>
79 using direction_type = grid::SquareGridDirections;
81
82 switch (direction) {
83 case direction_type::north: return node_type(-1, 0);
84 case direction_type::south: return node_type(1, 0);
85 case direction_type::west: return node_type(0, -1);
86 case direction_type::east: return node_type(0, 1);
87 case direction_type::north_west: return node_type(-1, -1);
88 case direction_type::south_west: return node_type(1, -1);
89 case direction_type::north_east: return node_type(-1, 1);
90 case direction_type::south_east: return node_type(1, 1);
91 default: return node_type(0, 0);
92 }
93}
94
95// ---------------------------------------------------------------------------------------------------------------------
96
97} // namespace grid
98
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Definition: set.hpp:44
Definition: GridFunction.hpp:16
static bool sqaureGridDirectionIsDiagonal(grid::SquareGridDirections direction)
Definition: GridFunction.cpp:40
static ext::pair< TCoordinate, TCoordinate > squareGridDirectionVector(grid::SquareGridDirections direction)
Definition: GridFunction.hpp:78
static ext::set< grid::SquareGridDirections > squareGridDirectionDecompose(grid::SquareGridDirections direction)
Definition: GridFunction.cpp:15
static bool sqaureGridDirectionIsCardinal(grid::SquareGridDirections direction)
Definition: GridFunction.cpp:50
static grid::SquareGridDirections squareGridDirection(const ext::pair< TCoordinate, TCoordinate > &a, const ext::pair< TCoordinate, TCoordinate > &b)
Definition: GridFunction.hpp:56
Definition: GridDirection.hpp:12
SquareGridDirections
Definition: GridDirection.hpp:16