/* Copyright 2015, Michele Santullo
 * This file is part of DoorKeeper.
 *
 * DoorKeeper is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DoorKeeper is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with DoorKeeper.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef id753CAC41D3AE48A1A1D1EC399FD3DADF
#define id753CAC41D3AE48A1A1D1EC399FD3DADF

#include "doorkeeper/primitivetypes.hpp"
#include "doorkeeper/implem/vector.hpp"
#include <cstdint>
#include <cstddef>
#include <algorithm>
#include <limits>
#include <type_traits>

namespace dk {
	template <uint32_t D>
	class TileCoords {
		static_assert(D >= 1, "Invalid dimension");
		static_assert(D <= static_cast<std::size_t>(-1), "Dimension is too large");
	public:
		typedef Vector<D> coords;

		TileCoords ( void ) = default;
		TileCoords ( const TileCoords& ) = default;
		explicit TileCoords ( const coords& parSize );
		TileCoords ( const coords& parValue, const coords& parSize );

		TileCoords& operator++ ( void ); //pre
		TileCoords operator++ ( int ); //post
		TileCoords& operator-- ( void ); //pre
		TileCoords operator-- ( int ); //post
		const TileCoords& operator+= ( CoordinateScalarType parValue );
		const TileCoords& operator-= ( CoordinateScalarType parValue );
		bool operator== ( const TileCoords& parOther ) const;
		bool operator!= ( const TileCoords& parOther ) const;
		TileCoords& operator= ( const TileCoords& ) = default;
		const CoordinateScalarType& operator[] ( int parIndex ) const;
		CoordinateScalarType& operator[] ( int parIndex );

		void set_position ( const coords& parPos );
		const coords& position ( void ) const;
		const coords& upper ( void ) const;

	private:
		coords m_pos;
		coords m_size;
	};

	namespace implem {
		CoordinateScalarType sum_mod ( CoordinateScalarType parA, CoordinateScalarType parB, CoordinateScalarType parDiv ) a_pure;
		CoordinateScalarType sum_div ( CoordinateScalarType parA, CoordinateScalarType parB, CoordinateScalarType parDiv ) a_pure;
		CoordinateScalarType sub_mod ( CoordinateScalarType parA, CoordinateScalarType parB, CoordinateScalarType parDiv ) a_pure;
		CoordinateScalarType sub_div ( CoordinateScalarType parA, CoordinateScalarType parB, CoordinateScalarType parDiv ) a_pure;
	} //namespace implem

	template <uint32_t D>
	CoordinateDistType to_index ( const Vector<D>& parPos, const Vector<D>& parUpper ) a_pure;

	template <uint32_t D>
	CoordinateDistType to_index ( const TileCoords<D>& parTC ) a_pure;
} //namespace dk

#include "doorkeeper/implem/tilecoords.inl"

#endif
