3.8.0
Freundlich's C++ toolkit
Classes | Typedefs | Functions
fcppt.container.grid

Description

A simple n-dimensional array.

Introduction

fcppt::container::grid::object is a simple multi-dimensional array similar to boost::multi_array. Let's first take a look at how to use a simple three dimensional grid of ints.

void use_grid()
{
// Create a 5 by 10 by 20 grid.
int3d_grid grid(int3d_grid::dim(5U, 10U, 20U), 0);
// Set the value on position (1,2,3) to 42
grid.get_unsafe(int3d_grid::pos(1U, 2U, 3U)) = 42;
fcppt::io::cout() << grid.get_unsafe(int3d_grid::pos(1U, 2U, 3U)) << FCPPT_TEXT('\n');
}

Grid uses fcppt::math::dim::object to specify its size and fcppt::math::vector::object to obtain an element.

Initialization

There are three ways to initialize a grid:

Here is a small example:

// Initialize all cells to 42
int2d_grid const all_42(int2d_grid::dim(3U, 2U), 42);
// Initialize using a function
int2d_grid const init_function(int2d_grid::dim(3U, 2U), [](int2d_grid::pos const &_pos) {
return _pos.x() == _pos.y() ? 1 : 0;
});

Ranges

To conveniently iterate over a grid, two ranges are provided:

Here is an example for pos ranges:

// Outputs: (0,0), (1,0), (0,1), (1,1), (0,2), (1,2)
for (pos2 const pos : fcppt::container::grid::make_pos_range(dim2{2U, 3U}))
{
std::cout << pos << '\n';
}

Pos ref ranges can be used to iterate over a grid's positions and elements simultaneously. Here is an example:

uint2_grid const grid(uint2_grid::dim{2U, 2U}, [](uint2_grid::pos const &_pos) {
return fcppt::cast::size<unsigned>(_pos.x() + _pos.y());
});
// Outputs: (0,0): 0, (1,0): 1, (0,1): 1, (1,1): 2
for (pos_ref const ref : fcppt::container::grid::make_pos_ref_crange(grid))
{
std::cout << ref.pos() << ": " << ref.value() << '\n';
}

Additionally, you can iterate over sub ranges which are denoted by a pair of fcppt::container::grid::min and fcppt::container::grid::sup. Here, min denotes the first element in the range while sup is ''one past the end''. A range is empty if at least one element of min is greater or equal to the corresponding element in sup. It is often necessary to clamp positions to a valid range that doesn't exceed the size of a grid. There are three functions for this: fcppt::container::grid::clamped_min, fcppt::container::grid::clamped_sup and fcppt::container::grid::clamped_sup_signed. An unsigned min doesn't need to be clamped. Here is an example:

void pos_ref_sub_range(uint2_grid::pos const &_min, uint2_grid::pos const &_sup)
{
uint2_grid const grid(uint2_grid::dim{2U, 2U}, 42U);
grid,
// unsigned positions cannot underflow
{
std::cout << ref.pos() << ": " << ref.value() << '\n';
}
}

Layout

Internally, the grid uses a std::vector to linearly represent the grid. The iterators returned by the grid are iterators over that internal storage array, so they're not special in any way (other than begin random-access). This also means that iteration is...

Here is an example:

namespace
{
}
int main()
{
int1d_grid one_dimensional(int1d_grid::dim(3U), 0);
one_dimensional.get_unsafe(int1d_grid::pos(0U)) = 0;
one_dimensional.get_unsafe(int1d_grid::pos(1U)) = 1;
one_dimensional.get_unsafe(int1d_grid::pos(2U)) = 2;
// Outputs 0, 1, 2
for (auto const &elem : one_dimensional)
{
fcppt::io::cout() << elem << FCPPT_TEXT(' ');
}
int2d_grid two_dimensional(int2d_grid::dim(3U, 2U), 0);
two_dimensional.get_unsafe(int2d_grid::pos(0U, 0U)) = 0;
two_dimensional.get_unsafe(int2d_grid::pos(1U, 0U)) = 1;
two_dimensional.get_unsafe(int2d_grid::pos(2U, 0U)) = 2;
two_dimensional.get_unsafe(int2d_grid::pos(0U, 1U)) = 3;
two_dimensional.get_unsafe(int2d_grid::pos(1U, 1U)) = 4;
two_dimensional.get_unsafe(int2d_grid::pos(2U, 1U)) = 5;
// Outputs 0, 1, 2, 3, 4, 5
for (auto const &elem : two_dimensional)
{
fcppt::io::cout() << elem << FCPPT_TEXT(' ');
}
}

Resizing

To resize a grid, we can use fcppt::container::grid::resize. Here's an example:

namespace
{
void resize_grid()
{
int2d_grid const grid(
int2d_grid::dim(2U, 3U),
// Initialize the grid with numbers 0 to 5
[](int2d_grid::pos const &) {
static int count{0};
return count++;
});
fcppt::io::cout() << grid << FCPPT_TEXT('\n');
int2d_grid const new_grid(
// Give the grid one more row and column and initialize those with 42.
grid, int2d_grid::dim(3U, 4U), [](int2d_grid::pos const &) { return 42; }));
fcppt::io::cout() << grid << FCPPT_TEXT('\n');
}
}

Classes

class  fcppt::container::grid::object< T, N, A >
 An n-dimensional array. More...
 
class  fcppt::container::grid::pos_iterator< SizeType, Size >
 An iterator over grid position. More...
 
class  fcppt::container::grid::pos_range< SizeType, Size >
 A range over grid position. More...
 
class  fcppt::container::grid::pos_ref_iterator< Grid >
 An iterator over grid references. More...
 
class  fcppt::container::grid::pos_ref_range< Grid >
 A range over grid references. More...
 
class  fcppt::container::grid::pos_reference< Grid >
 A reference to a grid cell and its position. More...
 

Typedefs

template<typename SizeType , fcppt::container::grid::size_type N>
using fcppt::container::grid::dim = fcppt::math::dim::static_< SizeType, N >
 The type of a grid's size. More...
 
template<typename Grid >
using fcppt::container::grid::dim_type = typename fcppt::container::grid::detail::dim_type< Grid >::type
 The dim type of a grid. More...
 
template<typename Type >
using fcppt::container::grid::is_static_row = fcppt::array::is_object< Type >
 Checks if a type is an fcppt::container::grid::static_row. More...
 
template<typename Pos >
using fcppt::container::grid::min_from_pos = fcppt::container::grid::min< fcppt::type_traits::value_type< Pos >, Pos::static_size::value >
 Creates the min from a pos type. More...
 
template<typename SizeType , fcppt::container::grid::size_type Size>
using fcppt::container::grid::min = fcppt::strong_typedef< fcppt::container::grid::pos< SizeType, Size >, fcppt::container::grid::min_tag >
 The start type of a pos range. More...
 
template<typename Pos >
using fcppt::container::grid::moore_neighbor_array = fcppt::array::object< Pos, 8 >
 The type return by fcppt::container::grid::moore_neighbors. More...
 
template<typename Pos >
using fcppt::container::grid::neumann_neighbor_array = fcppt::array::object< Pos, 4 >
 The type return by fcppt::container::grid::neumann_neighbors. More...
 
template<typename SizeType , fcppt::container::grid::size_type N>
using fcppt::container::grid::pos = fcppt::math::vector::static_< SizeType, N >
 The type used to index a grid. More...
 
template<typename Grid >
using fcppt::container::grid::pos_type = typename fcppt::container::grid::detail::pos_type< Grid >::type
 The pos type of a grid. More...
 
using fcppt::container::grid::size_type = fcppt::math::size_type
 An unsigned type used to count grid dimensions. More...
 
template<typename T , fcppt::container::grid::size_type N>
using fcppt::container::grid::static_row_type = fcppt::array::object< T, N >
 The type of a static row (an array). More...
 
template<typename Pos >
using fcppt::container::grid::sup_from_pos = fcppt::container::grid::sup< fcppt::type_traits::value_type< Pos >, Pos::static_size::value >
 Creates the sup from a pos type. More...
 
template<typename SizeType , fcppt::container::grid::size_type Size>
using fcppt::container::grid::sup = fcppt::strong_typedef< fcppt::container::grid::pos< SizeType, Size >, fcppt::container::grid::sup_tag >
 The one-past-the-end type of a pos range. More...
 

Functions

template<typename Function , typename Grid1 , typename... Grids>
auto fcppt::container::grid::apply (Function const &_function, Grid1 &&_grid1, Grids &&..._grids) -> fcppt::container::grid::object< decltype(_function(fcppt::move_if_rvalue< Grid1 >(_grid1.get_unsafe(std::declval< fcppt::container::grid::pos_type< fcppt::type_traits::remove_cv_ref_t< Grid1 >>>())), fcppt::move_if_rvalue< Grids >(_grids.get_unsafe(std::declval< fcppt::container::grid::pos_type< fcppt::type_traits::remove_cv_ref_t< Grid1 >>>()))...)), fcppt::type_traits::remove_cv_ref_t< Grid1 >::static_size::value >
 Applies a function to multiple grids of the same size. More...
 
template<typename Grid >
fcppt::optional::reference< fcppt::container::to_value_type< Grid > > fcppt::container::grid::at_optional (Grid &_grid, fcppt::container::grid::pos_type< std::remove_cv_t< Grid >> const _pos)
 Returns a grid element as an optional. More...
 
template<typename Source , fcppt::container::grid::size_type Size>
fcppt::container::grid::min< std::make_unsigned_t< Source >, Size > fcppt::container::grid::clamped_min (fcppt::container::grid::pos< Source, Size > const _pos)
 Clamps a signed position to min. More...
 
template<typename Source , fcppt::container::grid::size_type Size>
fcppt::container::grid::sup< Source, Size > fcppt::container::grid::clamped_sup (fcppt::container::grid::pos< Source, Size > const _pos, fcppt::container::grid::dim< Source, Size > const _size)
 Clamps a position to a grid's size. More...
 
template<typename Dest , typename Source , fcppt::container::grid::size_type Size>
fcppt::container::grid::sup< Dest, Size > fcppt::container::grid::clamped_sup_signed (fcppt::container::grid::pos< Source, Size > const _pos, fcppt::container::grid::dim< Dest, Size > const _size)
 Clamps a signed position to a grid's size. More...
 
template<typename T , fcppt::container::grid::size_type N, typename A >
bool fcppt::container::grid::operator== (fcppt::container::grid::object< T, N, A > const &_a, fcppt::container::grid::object< T, N, A > const &_b)
 Compares two grids for equality. More...
 
template<typename T , fcppt::container::grid::size_type N, typename A >
bool fcppt::container::grid::operator!= (fcppt::container::grid::object< T, N, A > const &_a, fcppt::container::grid::object< T, N, A > const &_b)
 !(a == b) More...
 
template<typename T , fcppt::container::grid::size_type N, typename A >
bool fcppt::container::grid::operator< (fcppt::container::grid::object< T, N, A > const &_a, fcppt::container::grid::object< T, N, A > const &_b)
 Lexicographically compares two grids. More...
 
template<typename T , fcppt::container::grid::size_type N, typename A >
bool fcppt::container::grid::operator> (fcppt::container::grid::object< T, N, A > const &_a, fcppt::container::grid::object< T, N, A > const &_b)
 b < a More...
 
template<typename T , fcppt::container::grid::size_type N, typename A >
bool fcppt::container::grid::operator<= (fcppt::container::grid::object< T, N, A > const &_a, fcppt::container::grid::object< T, N, A > const &_b)
 !(a > b) More...
 
template<typename T , fcppt::container::grid::size_type N, typename A >
bool fcppt::container::grid::operator>= (fcppt::container::grid::object< T, N, A > const &_a, fcppt::container::grid::object< T, N, A > const &_b)
 !(a < b) More...
 
template<typename SizeType , fcppt::container::grid::size_type Size>
fcppt::container::grid::pos< SizeType, Size > fcppt::container::grid::end_position (fcppt::container::grid::min< SizeType, Size > const _min, fcppt::container::grid::sup< SizeType, Size > const _sup)
 The end position of a range. More...
 
template<typename T , fcppt::container::grid::size_type N, typename A , typename Function >
void fcppt::container::grid::fill (fcppt::container::grid::object< T, N, A > &_grid, Function const &_function)
 Fills a grid using a function. More...
 
template<typename T , fcppt::container::grid::size_type N, typename A >
bool fcppt::container::grid::in_range (fcppt::container::grid::object< T, N, A > const &_grid, fcppt::container::grid::pos_type< fcppt::container::grid::object< T, N, A >> const &_pos)
 Checks if the given position _pos is out of bounds. More...
 
template<typename T , fcppt::container::grid::size_type N>
bool fcppt::container::grid::in_range_dim (fcppt::container::grid::dim< T, N > const _dim, fcppt::container::grid::pos< T, N > const _pos)
 Checks if the given position _pos is out of bounds. More...
 
template<typename T , fcppt::container::grid::size_type N, typename A , typename F , typename Interpolator >
fcppt::container::grid::interpolate (fcppt::container::grid::object< T, N, A > const &_grid, fcppt::math::vector::static_< F, N > const &_floating_point_position, Interpolator const &_interpolator)
 Interpolates a value inside the grid cells. More...
 
template<typename SizeType , fcppt::container::grid::size_type N>
fcppt::container::grid::min_from_pos< fcppt::container::grid::pos< SizeType, N > > fcppt::container::grid::make_min (fcppt::container::grid::pos< SizeType, N > const _pos)
 Creates min from a pos value. More...
 
template<typename SizeType , fcppt::container::grid::size_type Size>
fcppt::container::grid::pos_range< SizeType, Size > fcppt::container::grid::make_pos_range (fcppt::container::grid::dim< SizeType, Size > const _size)
 A range over all positions. More...
 
template<typename SizeType , fcppt::container::grid::size_type Size>
fcppt::container::grid::pos_range< SizeType, Size > fcppt::container::grid::make_pos_range_start_end (fcppt::container::grid::min< SizeType, Size > const _min, fcppt::container::grid::sup< SizeType, Size > const _sup)
 A sub range over positions. More...
 
template<typename Grid >
fcppt::container::grid::pos_ref_range< Grid const > fcppt::container::grid::make_pos_ref_crange (Grid const &_grid)
 A const pos ref range over a grid. More...
 
template<typename Grid >
fcppt::container::grid::pos_ref_range< Grid const > fcppt::container::grid::make_pos_ref_crange_start_end (Grid const &_grid, typename fcppt::container::grid::pos_ref_range< Grid const >::min_type const _min, typename fcppt::container::grid::pos_ref_range< Grid const >::sup_type const _sup)
 A const pos ref range over a sub-grid. More...
 
template<typename Grid >
fcppt::container::grid::pos_ref_range< Grid > fcppt::container::grid::make_pos_ref_range (Grid &_grid)
 A pos ref range over a grid. More...
 
template<typename Grid >
fcppt::container::grid::pos_ref_range< Grid > fcppt::container::grid::make_pos_ref_range_start_end (Grid &_grid, typename fcppt::container::grid::pos_ref_range< Grid >::min_type const _min, typename fcppt::container::grid::pos_ref_range< Grid >::sup_type const _sup)
 A pos ref range over a sub-grid. More...
 
template<typename SizeType , fcppt::container::grid::size_type N>
fcppt::container::grid::sup_from_pos< fcppt::container::grid::pos< SizeType, N > > fcppt::container::grid::make_sup (fcppt::container::grid::pos< SizeType, N > const _pos)
 Creates sup from a pos value. More...
 
template<typename Source , typename Function >
auto fcppt::container::grid::map (Source &&_source, Function const &_function) -> fcppt::container::grid::object< decltype(_function(fcppt::move_if_rvalue< Source >(_source.get_unsafe(std::declval< fcppt::container::grid::pos_type< fcppt::type_traits::remove_cv_ref_t< Source >>>())))), fcppt::type_traits::remove_cv_ref_t< Source >::static_size::value >
 Maps over grids. More...
 
template<typename SizeType , fcppt::container::grid::size_type Size>
bool fcppt::container::grid::min_less_sup (fcppt::container::grid::min< SizeType, Size > const _min, fcppt::container::grid::sup< SizeType, Size > const _sup)
 Checks if min is strictly less than sup. More...
 
template<typename T , fcppt::container::grid::size_type N>
fcppt::container::grid::moore_neighbor_array< fcppt::container::grid::pos< T, N > > fcppt::container::grid::moore_neighbors (fcppt::container::grid::pos< T, N > const _pos)
 Computes the Moore neighbors. More...
 
template<typename T , fcppt::container::grid::size_type N>
fcppt::container::grid::neumann_neighbor_array< fcppt::container::grid::pos< T, N > > fcppt::container::grid::neumann_neighbors (fcppt::container::grid::pos< T, N > const _pos)
 Computes the von Neumann neighbors. More...
 
template<typename SizeType , fcppt::container::grid::size_type Size>
fcppt::container::grid::pos< SizeType, Size > fcppt::container::grid::next_position (fcppt::container::grid::pos< SizeType, Size > const _current, fcppt::container::grid::min< SizeType, Size > const _min, fcppt::container::grid::sup< SizeType, Size > const _sup)
 Returns the next position in a grid range. More...
 
template<typename SizeType , fcppt::container::grid::size_type Size>
SizeType fcppt::container::grid::offset (fcppt::container::grid::pos< SizeType, Size > const &_pos, fcppt::container::grid::dim< SizeType, Size > const &_size)
 Returns the absolute offset of a position. More...
 
template<typename Ch , typename Traits , typename T , fcppt::container::grid::size_type N, typename A >
std::basic_ostream< Ch, Traits > & fcppt::container::grid::operator<< (std::basic_ostream< Ch, Traits > &_stream, fcppt::container::grid::object< T, N, A > const &_object)
 Outputs a grid. More...
 
template<typename SizeType , fcppt::container::grid::size_type Size>
fcppt::container::grid::dim< SizeType, Size > fcppt::container::grid::range_dim (fcppt::container::grid::min< SizeType, Size > const _min, fcppt::container::grid::sup< SizeType, Size > const _sup)
 The dimension of a grid range. More...
 
template<typename SizeType , fcppt::container::grid::size_type Size>
SizeType fcppt::container::grid::range_size (fcppt::container::grid::min< SizeType, Size > const _min, fcppt::container::grid::sup< SizeType, Size > const _sup)
 The number of elements in a grid range. More...
 
template<typename Grid , typename Function >
fcppt::type_traits::remove_cv_ref_t< Grid > fcppt::container::grid::resize (Grid &&_grid, fcppt::container::grid::dim_type< fcppt::type_traits::remove_cv_ref_t< Grid >> const &_new_size, Function const &_init)
 Returns a resized grid with potentially new elements. More...
 
template<typename Arg1 , typename... Args, typename = std::enable_if_t<std::conjunction_v<std::is_same< fcppt::type_traits::remove_cv_ref_t<Args>, fcppt::type_traits::remove_cv_ref_t<Arg1>>...>>>
fcppt::container::grid::static_row_type< fcppt::type_traits::remove_cv_ref_t< Arg1 >, fcppt::cast::size< fcppt::container::grid::size_type >sizeof...(Args)+1U)> fcppt::container::grid::static_row (Arg1 &&_arg1, Args &&..._args)
 Creates an fcppt::container::grid::static_row_type. More...
 

Typedef Documentation

◆ dim

template<typename SizeType , fcppt::container::grid::size_type N>
using fcppt::container::grid::dim = typedef fcppt::math::dim::static_<SizeType, N>

The type of a grid's size.

◆ dim_type

template<typename Grid >
using fcppt::container::grid::dim_type = typedef typename fcppt::container::grid::detail::dim_type<Grid>::type

The dim type of a grid.

Template Parameters
GridMust be an fcppt::container::grid::object.

◆ is_static_row

template<typename Type >
using fcppt::container::grid::is_static_row = typedef fcppt::array::is_object<Type>

Checks if a type is an fcppt::container::grid::static_row.

◆ min

template<typename SizeType , fcppt::container::grid::size_type Size>
using fcppt::container::grid::min = typedef fcppt:: strong_typedef<fcppt::container::grid::pos<SizeType, Size>, fcppt::container::grid::min_tag>

The start type of a pos range.

◆ min_from_pos

template<typename Pos >
using fcppt::container::grid::min_from_pos = typedef fcppt::container::grid::min<fcppt::type_traits::value_type<Pos>, Pos::static_size::value>

Creates the min from a pos type.

◆ moore_neighbor_array

template<typename Pos >
using fcppt::container::grid::moore_neighbor_array = typedef fcppt::array::object< Pos, 8 >

The type return by fcppt::container::grid::moore_neighbors.

Template Parameters
PosMust be an fcppt::container::grid::pos

◆ neumann_neighbor_array

template<typename Pos >
using fcppt::container::grid::neumann_neighbor_array = typedef fcppt::array::object<Pos, 4>

The type return by fcppt::container::grid::neumann_neighbors.

Template Parameters
PosMust be an fcppt::container::grid::pos

◆ pos

template<typename SizeType , fcppt::container::grid::size_type N>
using fcppt::container::grid::pos = typedef fcppt::math::vector::static_<SizeType, N>

The type used to index a grid.

◆ pos_type

template<typename Grid >
using fcppt::container::grid::pos_type = typedef typename fcppt::container::grid::detail::pos_type<Grid>::type

The pos type of a grid.

Template Parameters
GridMust be an fcppt::container::grid::object.

◆ size_type

An unsigned type used to count grid dimensions.

◆ static_row_type

template<typename T , fcppt::container::grid::size_type N>
using fcppt::container::grid::static_row_type = typedef fcppt::array::object<T, N>

The type of a static row (an array).

◆ sup

template<typename SizeType , fcppt::container::grid::size_type Size>
using fcppt::container::grid::sup = typedef fcppt:: strong_typedef<fcppt::container::grid::pos<SizeType, Size>, fcppt::container::grid::sup_tag>

The one-past-the-end type of a pos range.

◆ sup_from_pos

template<typename Pos >
using fcppt::container::grid::sup_from_pos = typedef fcppt::container::grid::sup<fcppt::type_traits::value_type<Pos>, Pos::static_size::value>

Creates the sup from a pos type.

Function Documentation

◆ apply()

template<typename Function , typename Grid1 , typename... Grids>
auto fcppt::container::grid::apply ( Function const &  _function,
Grid1 &&  _grid1,
Grids &&...  _grids 
) -> fcppt::container::grid::object< decltype(_function( fcppt::move_if_rvalue<Grid1>( _grid1.get_unsafe(std::declval<fcppt::container::grid::pos_type< fcppt::type_traits::remove_cv_ref_t<Grid1>>>())), fcppt::move_if_rvalue<Grids>( _grids.get_unsafe(std::declval<fcppt::container::grid::pos_type< fcppt::type_traits::remove_cv_ref_t<Grid1>>>()))...)), fcppt::type_traits::remove_cv_ref_t<Grid1>::static_size::value>

Applies a function to multiple grids of the same size.

For grids g_1 = _grid1 and g_2, ..., g_n = _grids, if g_1,...,g_n are all of the same size s, the result r is a grid of size s such that for every position p < s, r[p] = _function(g_1[p],...,g_n[p]). If g_1,...g_n are not of the same size, the result is an empty grid.

◆ at_optional()

template<typename Grid >
fcppt::optional::reference<fcppt::container::to_value_type<Grid> > fcppt::container::grid::at_optional ( Grid &  _grid,
fcppt::container::grid::pos_type< std::remove_cv_t< Grid >> const  _pos 
)

Returns a grid element as an optional.

If _pos is in the range of _grid, the element at _pos is returned. Otherwise, the result is an empty optional.

◆ clamped_min()

template<typename Source , fcppt::container::grid::size_type Size>
fcppt::container::grid::min<std::make_unsigned_t<Source>, Size> fcppt::container::grid::clamped_min ( fcppt::container::grid::pos< Source, Size > const  _pos)

Clamps a signed position to min.

◆ clamped_sup()

template<typename Source , fcppt::container::grid::size_type Size>
fcppt::container::grid::sup<Source, Size> fcppt::container::grid::clamped_sup ( fcppt::container::grid::pos< Source, Size > const  _pos,
fcppt::container::grid::dim< Source, Size > const  _size 
)

Clamps a position to a grid's size.

◆ clamped_sup_signed()

template<typename Dest , typename Source , fcppt::container::grid::size_type Size>
fcppt::container::grid::sup<Dest, Size> fcppt::container::grid::clamped_sup_signed ( fcppt::container::grid::pos< Source, Size > const  _pos,
fcppt::container::grid::dim< Dest, Size > const  _size 
)

Clamps a signed position to a grid's size.

◆ end_position()

template<typename SizeType , fcppt::container::grid::size_type Size>
fcppt::container::grid::pos<SizeType, Size> fcppt::container::grid::end_position ( fcppt::container::grid::min< SizeType, Size > const  _min,
fcppt::container::grid::sup< SizeType, Size > const  _sup 
)

The end position of a range.

Returns the end position of a grid range that is formed by _min and _sup. This position is usually further than one past the last element.

◆ fill()

template<typename T , fcppt::container::grid::size_type N, typename A , typename Function >
void fcppt::container::grid::fill ( fcppt::container::grid::object< T, N, A > &  _grid,
Function const &  _function 
)

Fills a grid using a function.

Template Parameters
FunctionA function callable as T (dim<size_type, N>).

◆ in_range()

template<typename T , fcppt::container::grid::size_type N, typename A >
bool fcppt::container::grid::in_range ( fcppt::container::grid::object< T, N, A > const &  _grid,
fcppt::container::grid::pos_type< fcppt::container::grid::object< T, N, A >> const &  _pos 
)
inline

Checks if the given position _pos is out of bounds.

Returns
true if is not out of bounds, false otherwise.

◆ in_range_dim()

template<typename T , fcppt::container::grid::size_type N>
bool fcppt::container::grid::in_range_dim ( fcppt::container::grid::dim< T, N > const  _dim,
fcppt::container::grid::pos< T, N > const  _pos 
)
inline

Checks if the given position _pos is out of bounds.

Returns
true if is not out of bounds, false otherwise.

◆ interpolate()

template<typename T , fcppt::container::grid::size_type N, typename A , typename F , typename Interpolator >
T fcppt::container::grid::interpolate ( fcppt::container::grid::object< T, N, A > const &  _grid,
fcppt::math::vector::static_< F, N > const &  _floating_point_position,
Interpolator const &  _interpolator 
)

Interpolates a value inside the grid cells.

With fcppt::container::grid::object grid::object alone, you can only access values at discrete points (since the fcppt::container::grid::object::dim object::dim type used to specify positions has an integral value_type).

Sometimes, however, you want to take a value in between the grid nodes. Think about a magnifying filter for textures, or drawing a line from one plot point to the next (in a one-dimensional grid). This is called interpolation, and it works in all dimensions.

To interpolate, you specify the _grid, the _floating_point_position and an _interpolator. The latter will determine what kind of interpolation is used (linear, trigonometric, ...). You can choose one of the functions in fcppt::math::interpolation or you can write your own interpolator function.

Here's an example:

void interpolate_grid()
{
float2d_grid const grid(float2d_grid::dim(2U, 2U), [](float2d_grid::pos const &) {
static int value{0};
return fcppt::cast::int_to_float<float>(value++);
});
grid, float2d_vector{0.5F, 0.5F}, [](float const _f, float const _v1, float const _v2) {
return fcppt::math::interpolation::linear(_f, _v1, _v2);
})};
// Will bilinearly interpolate ALL the grid points and return something
// inbetween (too lazy to calculate)
}
Template Parameters
FThe floating point type used for calculations.
InterpolatorA function callable as T (F, T, T).

◆ make_min()

template<typename SizeType , fcppt::container::grid::size_type N>
fcppt::container::grid::min_from_pos<fcppt::container::grid::pos<SizeType, N> > fcppt::container::grid::make_min ( fcppt::container::grid::pos< SizeType, N > const  _pos)
inline

Creates min from a pos value.

◆ make_pos_range()

template<typename SizeType , fcppt::container::grid::size_type Size>
fcppt::container::grid::pos_range<SizeType, Size> fcppt::container::grid::make_pos_range ( fcppt::container::grid::dim< SizeType, Size > const  _size)
inline

A range over all positions.

Creates a range of positions from "all zeroes" to, but not including, _size.

◆ make_pos_range_start_end()

template<typename SizeType , fcppt::container::grid::size_type Size>
fcppt::container::grid::pos_range<SizeType, Size> fcppt::container::grid::make_pos_range_start_end ( fcppt::container::grid::min< SizeType, Size > const  _min,
fcppt::container::grid::sup< SizeType, Size > const  _sup 
)
inline

A sub range over positions.

Creates a range of positions from _min to, but not including, _sup.

◆ make_pos_ref_crange()

template<typename Grid >
fcppt::container::grid::pos_ref_range<Grid const> fcppt::container::grid::make_pos_ref_crange ( Grid const &  _grid)
inline

A const pos ref range over a grid.

◆ make_pos_ref_crange_start_end()

template<typename Grid >
fcppt::container::grid::pos_ref_range<Grid const> fcppt::container::grid::make_pos_ref_crange_start_end ( Grid const &  _grid,
typename fcppt::container::grid::pos_ref_range< Grid const >::min_type const  _min,
typename fcppt::container::grid::pos_ref_range< Grid const >::sup_type const  _sup 
)
inline

A const pos ref range over a sub-grid.

Creates a const pos ref range from _min to, but not including, _sup.

◆ make_pos_ref_range()

template<typename Grid >
fcppt::container::grid::pos_ref_range<Grid> fcppt::container::grid::make_pos_ref_range ( Grid &  _grid)
inline

A pos ref range over a grid.

◆ make_pos_ref_range_start_end()

template<typename Grid >
fcppt::container::grid::pos_ref_range<Grid> fcppt::container::grid::make_pos_ref_range_start_end ( Grid &  _grid,
typename fcppt::container::grid::pos_ref_range< Grid >::min_type const  _min,
typename fcppt::container::grid::pos_ref_range< Grid >::sup_type const  _sup 
)
inline

A pos ref range over a sub-grid.

Creates a pos ref range from _min to, but not including, _sup.

◆ make_sup()

template<typename SizeType , fcppt::container::grid::size_type N>
fcppt::container::grid::sup_from_pos<fcppt::container::grid::pos<SizeType, N> > fcppt::container::grid::make_sup ( fcppt::container::grid::pos< SizeType, N > const  _pos)
inline

Creates sup from a pos value.

◆ map()

template<typename Source , typename Function >
auto fcppt::container::grid::map ( Source &&  _source,
Function const &  _function 
) -> fcppt::container::grid::object< decltype(_function(fcppt::move_if_rvalue<Source>(_source.get_unsafe( std::declval< fcppt::container::grid::pos_type<fcppt::type_traits::remove_cv_ref_t<Source>>>())))), fcppt::type_traits::remove_cv_ref_t<Source>::static_size::value>

Maps over grids.

For every element x at position p in _source, the result of _function(x) is inserted at p into the result.

Template Parameters
FunctionA function callable as R (Source::value_type) where R is the result type

◆ min_less_sup()

template<typename SizeType , fcppt::container::grid::size_type Size>
bool fcppt::container::grid::min_less_sup ( fcppt::container::grid::min< SizeType, Size > const  _min,
fcppt::container::grid::sup< SizeType, Size > const  _sup 
)

Checks if min is strictly less than sup.

Checks if _min is strictly less than _sup. If this is false, the range denoted by _min and _sup is empty.

◆ moore_neighbors()

template<typename T , fcppt::container::grid::size_type N>
fcppt::container::grid::moore_neighbor_array<fcppt::container::grid::pos<T, N> > fcppt::container::grid::moore_neighbors ( fcppt::container::grid::pos< T, N > const  _pos)

Computes the Moore neighbors.

Computes the Moore neighbors of _pos. No range checking is performed.

Parameters
_posThe position to compute the neighbors of
Returns
An array with four elements, containing the neighbors

◆ neumann_neighbors()

template<typename T , fcppt::container::grid::size_type N>
fcppt::container::grid::neumann_neighbor_array<fcppt::container::grid::pos<T, N> > fcppt::container::grid::neumann_neighbors ( fcppt::container::grid::pos< T, N > const  _pos)

Computes the von Neumann neighbors.

Computes the von Neumann neighbors of _pos. No range checking is performed.

Parameters
_posThe position to compute the neighbors of
Returns
An array with four elements, containing the neighbors

◆ next_position()

template<typename SizeType , fcppt::container::grid::size_type Size>
fcppt::container::grid::pos<SizeType, Size> fcppt::container::grid::next_position ( fcppt::container::grid::pos< SizeType, Size > const  _current,
fcppt::container::grid::min< SizeType, Size > const  _min,
fcppt::container::grid::sup< SizeType, Size > const  _sup 
)

Returns the next position in a grid range.

Given a range by _min and _sup, returns the next position after _current.

◆ offset()

template<typename SizeType , fcppt::container::grid::size_type Size>
SizeType fcppt::container::grid::offset ( fcppt::container::grid::pos< SizeType, Size > const &  _pos,
fcppt::container::grid::dim< SizeType, Size > const &  _size 
)

Returns the absolute offset of a position.

◆ operator!=()

template<typename T , fcppt::container::grid::size_type N, typename A >
bool fcppt::container::grid::operator!= ( fcppt::container::grid::object< T, N, A > const &  _a,
fcppt::container::grid::object< T, N, A > const &  _b 
)
inline

!(a == b)

◆ operator<()

template<typename T , fcppt::container::grid::size_type N, typename A >
bool fcppt::container::grid::operator< ( fcppt::container::grid::object< T, N, A > const &  _a,
fcppt::container::grid::object< T, N, A > const &  _b 
)

Lexicographically compares two grids.

The first component in the lexicographical order is the size of both grids. If both sizes are equal, std::lexicographical_compare is used.

◆ operator<<()

template<typename Ch , typename Traits , typename T , fcppt::container::grid::size_type N, typename A >
std::basic_ostream<Ch, Traits>& fcppt::container::grid::operator<< ( std::basic_ostream< Ch, Traits > &  _stream,
fcppt::container::grid::object< T, N, A > const &  _object 
)

Outputs a grid.

Outputs the grid _object to _stream. Every level of the grid will be wrapped in parenthesis. So, for example, a two dimensional grid of size (n,m) will be written as ((x_0, y_0), (x_1, y_0), ..., (x_0, y_1), ..., (x_n, y_m)).

Template Parameters
TMust be a type that has an appropriate operator<<
Parameters
_streamThe stream to write to
_objectThe grid to write
Returns
_stream

◆ operator<=()

template<typename T , fcppt::container::grid::size_type N, typename A >
bool fcppt::container::grid::operator<= ( fcppt::container::grid::object< T, N, A > const &  _a,
fcppt::container::grid::object< T, N, A > const &  _b 
)
inline

!(a > b)

◆ operator==()

template<typename T , fcppt::container::grid::size_type N, typename A >
bool fcppt::container::grid::operator== ( fcppt::container::grid::object< T, N, A > const &  _a,
fcppt::container::grid::object< T, N, A > const &  _b 
)

Compares two grids for equality.

◆ operator>()

template<typename T , fcppt::container::grid::size_type N, typename A >
bool fcppt::container::grid::operator> ( fcppt::container::grid::object< T, N, A > const &  _a,
fcppt::container::grid::object< T, N, A > const &  _b 
)
inline

b < a

◆ operator>=()

template<typename T , fcppt::container::grid::size_type N, typename A >
bool fcppt::container::grid::operator>= ( fcppt::container::grid::object< T, N, A > const &  _a,
fcppt::container::grid::object< T, N, A > const &  _b 
)
inline

!(a < b)

◆ range_dim()

template<typename SizeType , fcppt::container::grid::size_type Size>
fcppt::container::grid::dim<SizeType, Size> fcppt::container::grid::range_dim ( fcppt::container::grid::min< SizeType, Size > const  _min,
fcppt::container::grid::sup< SizeType, Size > const  _sup 
)

The dimension of a grid range.

The dimension of the range given by _min and _sup.

◆ range_size()

template<typename SizeType , fcppt::container::grid::size_type Size>
SizeType fcppt::container::grid::range_size ( fcppt::container::grid::min< SizeType, Size > const  _min,
fcppt::container::grid::sup< SizeType, Size > const  _sup 
)
inline

The number of elements in a grid range.

The number of elements in the range given by _min and _sup.

◆ resize()

template<typename Grid , typename Function >
fcppt::type_traits::remove_cv_ref_t<Grid> fcppt::container::grid::resize ( Grid &&  _grid,
fcppt::container::grid::dim_type< fcppt::type_traits::remove_cv_ref_t< Grid >> const &  _new_size,
Function const &  _init 
)

Returns a resized grid with potentially new elements.

Returns a grid g of size _new_size, such that for every position p in g we have that:

  • g[p] = _grid[p] if p is also a position in _grid, or
  • g[p] = _init(p) otherwise.
Template Parameters
GridMust be a grid.
FunctionA function callable as Grid::value_type (Grid::pos).

◆ static_row()

template<typename Arg1 , typename... Args, typename = std::enable_if_t<std::conjunction_v<std::is_same< fcppt::type_traits::remove_cv_ref_t<Args>, fcppt::type_traits::remove_cv_ref_t<Arg1>>...>>>
fcppt::container::grid::static_row_type< fcppt::type_traits::remove_cv_ref_t<Arg1>, fcppt::cast::size<fcppt::container::grid::size_type>sizeof...(Args) + 1U)> fcppt::container::grid::static_row ( Arg1 &&  _arg1,
Args &&...  _args 
)