Horizon Official Technical Documentation
Coordinates< MAX_COORDINATES > Class Template Reference

#include <Coordinates.hpp>

Public Member Functions

 Coordinates (int16_t x=0, int16_t y=0)
 
 Coordinates (const Coordinates< MAX_COORDINATES > &obj)
 
Coordinates< MAX_COORDINATES > operator= (const Coordinates< MAX_COORDINATES > &right)
 
bool operator== (Coordinates< MAX_COORDINATES > const &right) const
 
bool operator!= (Coordinates< MAX_COORDINATES > const &right) const
 
Coordinates< MAX_COORDINATES > operator+ (Coordinates< MAX_COORDINATES > const &right) const
 
Coordinates< MAX_COORDINATES > operator- (Coordinates< MAX_COORDINATES > const &right) const
 
template<int16_t BOUNDS>
bool is_within_range (Coordinates< BOUNDS > const &bounds, int range) const
 
template<int16_t BOUNDS>
Coordinates< BOUNDS > at_range (int range) const
 
template<int16_t BOUNDS>
int distance_from (Coordinates< BOUNDS > const &bounds) const
 
template<int16_t BLOCK_SIZE, int16_t BLOCK_COUNT>
Coordinates< BLOCK_COUNT > scale () const
 
int16_t x () const
 
int16_t y () const
 
int16_t move_cost () const
 
void set_move_cost (int16_t move_cost)
 
void inc_x (int16_t val)
 
void dec_x (int16_t val)
 
void inc_y (int16_t val)
 
void dec_y (int16_t val)
 
bool valid () const
 

Private Attributes

int16_t _x {0}
 
int16_t _y {0}
 
int16_t _move_cost {0}
 

Constructor & Destructor Documentation

◆ Coordinates() [1/2]

template<int16_t MAX_COORDINATES>
Coordinates< MAX_COORDINATES >::Coordinates ( int16_t  x = 0,
int16_t  y = 0 
)
inline
42 : _x(x), _y(y), _move_cost(0)
43 {
44 //
45 }
int16_t _x
Definition: Coordinates.hpp:162
int16_t y() const
Definition: Coordinates.hpp:120
int16_t _move_cost
Definition: Coordinates.hpp:164
int16_t _y
Definition: Coordinates.hpp:163
int16_t x() const
Definition: Coordinates.hpp:119

◆ Coordinates() [2/2]

template<int16_t MAX_COORDINATES>
Coordinates< MAX_COORDINATES >::Coordinates ( const Coordinates< MAX_COORDINATES > &  obj)
inline
48 : _x(obj._x), _y(obj._y), _move_cost(obj._move_cost)
49 {
50 //
51 }

Member Function Documentation

◆ at_range()

template<int16_t MAX_COORDINATES>
template<int16_t BOUNDS>
Coordinates< BOUNDS > Coordinates< MAX_COORDINATES >::at_range ( int  range) const
inline
92 {
93 int x = std::max(0, std::min((_x + range), (int) BOUNDS));
94 int y = std::max(0, std::min((_y + range), (int) BOUNDS));
95
96 return Coordinates<BOUNDS>(x, y);
97 }
Definition: Coordinates.hpp:39

References Coordinates< MAX_COORDINATES >::_x, Coordinates< MAX_COORDINATES >::_y, Coordinates< MAX_COORDINATES >::x(), and Coordinates< MAX_COORDINATES >::y().

Referenced by Horizon::Zone::Map::visit_in_range().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dec_x()

template<int16_t MAX_COORDINATES>
void Coordinates< MAX_COORDINATES >::dec_x ( int16_t  val)
inline
133 {
134 if (_x > val)
135 _x -= val;
136 else
137 _x = 0;
138 }

References Coordinates< MAX_COORDINATES >::_x.

◆ dec_y()

template<int16_t MAX_COORDINATES>
void Coordinates< MAX_COORDINATES >::dec_y ( int16_t  val)
inline
149 {
150 if (_y > val)
151 _y -= val;
152 else
153 _y = 0;
154 }

References Coordinates< MAX_COORDINATES >::_y.

◆ distance_from()

template<int16_t MAX_COORDINATES>
template<int16_t BOUNDS>
int Coordinates< MAX_COORDINATES >::distance_from ( Coordinates< BOUNDS > const &  bounds) const
inline
102 {
103 int distance = std::sqrt(std::pow(bounds.x() - _x, 2) + std::pow(bounds.y() - _y, 2));
104 return distance;
105 }

References Coordinates< MAX_COORDINATES >::_x, Coordinates< MAX_COORDINATES >::_y, Coordinates< MAX_COORDINATES >::x(), and Coordinates< MAX_COORDINATES >::y().

+ Here is the call graph for this function:

◆ inc_x()

template<int16_t MAX_COORDINATES>
void Coordinates< MAX_COORDINATES >::inc_x ( int16_t  val)
inline
125 {
126 if (_x + val < MAX_COORDINATES)
127 _x += val;
128 else
129 _x = MAX_COORDINATES - 1;
130 }

References Coordinates< MAX_COORDINATES >::_x.

◆ inc_y()

template<int16_t MAX_COORDINATES>
void Coordinates< MAX_COORDINATES >::inc_y ( int16_t  val)
inline
141 {
142 if (_y + val < MAX_COORDINATES)
143 _y += val;
144 else
145 _y = MAX_COORDINATES - 1;
146 }

References Coordinates< MAX_COORDINATES >::_y.

◆ is_within_range()

template<int16_t MAX_COORDINATES>
template<int16_t BOUNDS>
bool Coordinates< MAX_COORDINATES >::is_within_range ( Coordinates< BOUNDS > const &  bounds,
int  range 
) const
inline
83 {
84 int x_diff = _x - bounds.x();
85 int y_diff = _y - bounds.y();
86
87 return abs(x_diff) <= range && abs(y_diff) <= range;
88 }

References Coordinates< MAX_COORDINATES >::_x, Coordinates< MAX_COORDINATES >::_y, Coordinates< MAX_COORDINATES >::x(), and Coordinates< MAX_COORDINATES >::y().

Referenced by BOOST_AUTO_TEST_CASE(), and Horizon::Zone::Unit::is_in_range_of().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ move_cost()

template<int16_t MAX_COORDINATES>
int16_t Coordinates< MAX_COORDINATES >::move_cost ( ) const
inline
121{ return _move_cost; }

References Coordinates< MAX_COORDINATES >::_move_cost.

Referenced by Horizon::Zone::AStar::Generator::findPath(), and Coordinates< MAX_COORDINATES >::set_move_cost().

+ Here is the caller graph for this function:

◆ operator!=()

template<int16_t MAX_COORDINATES>
bool Coordinates< MAX_COORDINATES >::operator!= ( Coordinates< MAX_COORDINATES > const &  right) const
inline
67 {
68 return !(*this == right);
69 }

◆ operator+()

template<int16_t MAX_COORDINATES>
Coordinates< MAX_COORDINATES > Coordinates< MAX_COORDINATES >::operator+ ( Coordinates< MAX_COORDINATES > const &  right) const
inline

◆ operator-()

template<int16_t MAX_COORDINATES>
Coordinates< MAX_COORDINATES > Coordinates< MAX_COORDINATES >::operator- ( Coordinates< MAX_COORDINATES > const &  right) const
inline

◆ operator=()

template<int16_t MAX_COORDINATES>
Coordinates< MAX_COORDINATES > Coordinates< MAX_COORDINATES >::operator= ( const Coordinates< MAX_COORDINATES > &  right)
inline

◆ operator==()

template<int16_t MAX_COORDINATES>
bool Coordinates< MAX_COORDINATES >::operator== ( Coordinates< MAX_COORDINATES > const &  right) const
inline
62 {
63 return (_x == right._x && _y == right._y);
64 }

References Coordinates< MAX_COORDINATES >::_x, and Coordinates< MAX_COORDINATES >::_y.

◆ scale()

template<int16_t MAX_COORDINATES>
template<int16_t BLOCK_SIZE, int16_t BLOCK_COUNT>
Coordinates< BLOCK_COUNT > Coordinates< MAX_COORDINATES >::scale ( ) const
inline
109 {
110 int x = _x / BLOCK_SIZE;
111 int y = _y / BLOCK_SIZE;
112
113 assert(x < BLOCK_COUNT && y < BLOCK_COUNT);
114 assert(x >= 0 && y >= 0);
115
117 }

References Coordinates< MAX_COORDINATES >::_x, Coordinates< MAX_COORDINATES >::_y, Coordinates< MAX_COORDINATES >::x(), and Coordinates< MAX_COORDINATES >::y().

Referenced by Horizon::Zone::Map::ensure_grid_for_unit(), and Horizon::Zone::Map::visit_in_range().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_move_cost()

template<int16_t MAX_COORDINATES>
void Coordinates< MAX_COORDINATES >::set_move_cost ( int16_t  move_cost)
inline
int16_t move_cost() const
Definition: Coordinates.hpp:121

References Coordinates< MAX_COORDINATES >::_move_cost, and Coordinates< MAX_COORDINATES >::move_cost().

Referenced by Horizon::Zone::AStar::Generator::findPath().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ valid()

template<int16_t MAX_COORDINATES>
bool Coordinates< MAX_COORDINATES >::valid ( ) const
inline
157 {
158 return _x < MAX_COORDINATES && _y < MAX_COORDINATES;
159 }

References Coordinates< MAX_COORDINATES >::_x, and Coordinates< MAX_COORDINATES >::_y.

◆ x()

◆ y()

Member Data Documentation

◆ _move_cost

template<int16_t MAX_COORDINATES>
int16_t Coordinates< MAX_COORDINATES >::_move_cost {0}
private

◆ _x

◆ _y


The documentation for this class was generated from the following file: