35 #ifndef NAV_GRID_VECTOR_NAV_GRID_H
36 #define NAV_GRID_VECTOR_NAV_GRID_H
60 data_.assign(this->
info_.
width * this->info_.height, this->default_value_);
76 std::vector<T> new_vector(new_info.
width * new_info.
height, this->default_value_);
77 unsigned int cols_to_move = std::min(this->
info_.
width, new_info.
width);
78 auto old_it =
data_.begin();
79 auto new_it = new_vector.begin();
81 for (
unsigned int row = 0; row < max_row; row++)
83 std::copy(old_it, old_it + cols_to_move, new_it);
85 new_it += new_info.
width;
87 data_.swap(new_vector);
94 this->
info_ = new_info;
110 if (this->
info_ == new_info)
123 int cell_ox, cell_oy;
127 int old_size_x =
static_cast<int>(this->
info_.
width);
128 int old_size_y =
static_cast<int>(this->
info_.
height);
131 int lower_left_x = std::min(std::max(cell_ox, 0), old_size_x);
132 int lower_left_y = std::min(std::max(cell_oy, 0), old_size_y);
133 int upper_right_x = std::min(std::max(cell_ox +
static_cast<int>(new_info.
width), 0), old_size_x);
134 int upper_right_y = std::min(std::max(cell_oy +
static_cast<int>(new_info.
height), 0), old_size_y);
136 unsigned int cell_size_x = upper_right_x - lower_left_x;
137 unsigned int cell_size_y = upper_right_y - lower_left_y;
140 std::vector<T> new_data(new_info.
width * new_info.
height, this->default_value_);
143 int start_x = lower_left_x - cell_ox;
144 int start_y = lower_left_y - cell_oy;
148 auto src_index =
data_.begin() + (lower_left_y * old_size_x + lower_left_x);
149 auto dest_index = new_data.begin() + (start_y * new_info.
width + start_x);
152 for (
unsigned int i = 0; i < cell_size_y; ++i)
154 std::copy(src_index, src_index + cell_size_x, dest_index);
156 dest_index += new_info.
width;
159 data_.swap(new_data);
171 void setValue(
const unsigned int x,
const unsigned int y,
const T& value)
override
176 T
getValue(
const unsigned int x,
const unsigned int y)
const override
203 inline unsigned int getIndex(
unsigned int mx,
unsigned int my)
const
214 inline unsigned int getIndex(
double x,
double y)
const
227 inline void indexToCells(
unsigned int index,
unsigned int& mx,
unsigned int& my)
const
239 #endif // NAV_GRID_VECTOR_NAV_GRID_H