<commit_before>#ifndef __ENVIRE_MAPS_GRIDBASE_HPP__
#define __ENVIRE_MAPS_GRIDBASE_HPP__

#include <Eigen/Core>
#include <Eigen/Geometry>

#include <boost/intrusive_ptr.hpp>
#include <boost/function.hpp>

#include "GridConfig.hpp"

namespace envire
{
    namespace maps 
    {
        /** Base class for all maps that function as regular grids
         *
         * This map offers a common interface for all maps that are regular grids
         *
         * The create() static method can be used as a factory method for all
         * subclasses that are registered on the serialization system
         *
         * A generic implementation as a template is Grid<T>, declared in Grid.hpp.
         * Specialized implementation for common types of maps can be found in
         * Grids.hpp (such as: ElevationMap, OccupancyGrid, ...)
         */
        class GridBase
        {
            public:
                typedef boost::intrusive_ptr<GridBase> Ptr;

                /** Internal structure used to represent a position on the grid itself,
                 * as a cell index
                 */
                struct Index
                {
                    /** The cell position along the X axis */
                    size_t x;
                    /** The cell position along the Y axis */
                    size_t y;

                    Index() : x(0), y(0) {}
                    Index( size_t x, size_t y ) : x(x), y(y) {}
                    explicit Index( const Eigen::Vector2i &index ) : x(index.x()), y(index.y()) {}

                    bool operator<( const Index& other ) const
                    {
                        if( x < other.x )
                            return true;
                        else
                        {
                            if( x == other.x )
                                return y < other.y;
                            else
                                return false;
                        }
                    }

                    bool operator==( const Index& other ) const
                    {
                        return x == other.x && y == other.y;
                    }

                    bool operator!=( const Index& other ) const
                    {
                        return x != other.x || y != other.y;
                    }

                    Index operator+(const Index& second) const
                    {
                        return Index(x + second.x, y + second.y);
                    }

                    Index operator-(const Index& second) const
                    {
                        return Index(x - second.x, y - second.y);
                    }
                };          

                explicit GridBase();

                /** @brief Constructor of the abstract GridBase class
                 * 
                 * Defines the extends and positioning of the grid. The grid is assumed
                 * to be on the x-y plane of the reference frame. The number of grid
                 * cells is given by the cellSizeX and cellSizeY params. Each dimension
                 * also has an scaling and offset parameter, such that the origin of the
                 * grid can be moved around and the grid scaled.
                 *
                 * The relation between the grid cell index xi and the value for the
                 * dimension x is:
                 * @verbatim
                 * x = xi * scale_x + offset_x
                 * @endverbatim<commit_msg>add some todos to GridBase Index<commit_after>#ifndef __ENVIRE_MAPS_GRIDBASE_HPP__
#define __ENVIRE_MAPS_GRIDBASE_HPP__

#include <Eigen/Core>
#include <Eigen/Geometry>

#include <boost/intrusive_ptr.hpp>
#include <boost/function.hpp>

#include "GridConfig.hpp"

namespace envire
{
    namespace maps 
    {
        /** Base class for all maps that function as regular grids
         *
         * This map offers a common interface for all maps that are regular grids
         *
         * The create() static method can be used as a factory method for all
         * subclasses that are registered on the serialization system
         *
         * A generic implementation as a template is Grid<T>, declared in Grid.hpp.
         * Specialized implementation for common types of maps can be found in
         * Grids.hpp (such as: ElevationMap, OccupancyGrid, ...)
         */
        class GridBase
        {
            public:
                typedef boost::intrusive_ptr<GridBase> Ptr;

                /** Internal structure used to represent a position on the grid itself,
                 * as a cell index
                 */
                // TODO: probably replace the Index with Vector2i or extend it
                struct Index
                {
                    /** The cell position along the X axis */
                    size_t x;
                    /** The cell position along the Y axis */
                    size_t y;

                    Index() : x(0), y(0) {}
                    Index( size_t x, size_t y ) : x(x), y(y) {}
                    explicit Index( const Eigen::Vector2i &index ) : x(index.x()), y(index.y()) {}

                    bool operator<( const Index& other ) const
                    {
                        if( x < other.x )
                            return true;
                        else
                        {
                            if( x == other.x )
                                return y < other.y;
                            else
                                return false;
                        }
                    }

                    bool operator==( const Index& other ) const
                    {
                        return x == other.x && y == other.y;
                    }

                    bool operator!=( const Index& other ) const
                    {
                        return x != other.x || y != other.y;
                    }

                    Index operator+(const Index& second) const
                    {
                        return Index(x + second.x, y + second.y);
                    }

                    // TODO: what should we do if the second index are bigger than the first one?
                    Index operator-(const Index& second) const
                    {
                        return Index(x - second.x, y - second.y);
                    }
                };          

                explicit GridBase();

                /** @brief Constructor of the abstract GridBase class
                 * 
                 * Defines the extends and positioning of the grid. The grid is assumed
                 * to be on the x-y plane of the reference frame. The number of grid
                 * cells is given by the cellSizeX and cellSizeY params. Each dimension
                 * also has an scaling and offset parameter, such that the origin of the
                 * grid can be moved around and the grid scaled.
                 *
                 * The relation between the grid cell index xi and the value for the
                 * dimension x is:
                 * @verbatim
                 * x = xi * scale_x + offset_x
                 * @endverbatim
{'fraction_non_alphanumeric': 0.06772853185595568, 'fraction_numerical': 0.0009695290858725762, 'mean_word_length': 1.0684617588083645, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1951416', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1592, 'n_words': 629}