#include "Grid1d.h"

const double GridMaker1d::INTERP_TOLERANCE_DEFAULT = 1e-15;

void GridMaker1d::make_grid_zero_center(size_t number_of_gridpoints, double grid_spread, double variance, gelib::d_vector& grid)
{

	double grid_max = grid_spread * std::sqrt(variance);
	double spacing = grid_max * 2 / (number_of_gridpoints - 1);

	grid.resize(number_of_gridpoints);

	grid[0] = -grid_max;

	for (size_t i = 1; i < number_of_gridpoints; ++i)
	{
		grid[i] = grid[0] + spacing * i;
	}

}

void GridMaker1d::make_grid(size_t number_of_gridpoints, double grid_spread, double grid_center, double variance, gelib::d_vector& grid)
{
	make_grid_zero_center(number_of_gridpoints, grid_spread, variance, grid);
	recenter_grid(grid_center, grid);
}

void GridMaker1d::recenter_grid(double x, gelib::d_vector& grid)
{
	std::transform(grid.begin(), grid.end(), grid.begin(), [&x](double y) -> double {return x + y; });
}
