//
// Created by m on 12/11/21.
//

#ifndef RLA_IIPP_GRID2D_HPP
#define RLA_IIPP_GRID2D_HPP


#include <vector>
#include <range/v3/view.hpp>
#include "point.hpp"
template<typename  T>
class Grid2D {
private:
    std::vector<std::vector<T>> grid{};
public:
    Grid2D(int width, int height) {
        grid = std::vector<std::vector<T>>(height, std::vector<T>(width));
    }
    int get_width() {
        return grid[0].size();
    }
    int get_height() {
        return grid.size();
    }
    void insert(int x, int y, T arg) {
        grid[y][x] = arg;
    }
    T get(int x, int y) {
        return grid[y][x];
    }
    ranges::any_view<Point> get_range() {
        int height = get_height();
        int width = get_width();
        return ranges::views::iota(0, height) | ranges::views::transform([height, width](int y) {
           return ranges::views::iota(0, width) | ranges::views::transform([y](int x) {
               return Point{x,y};
           });
        }) | ranges::views::join;
    }
};


#endif //RLA_IIPP_GRID2D_HPP
