/* 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 id73F121AEE1EB4BA0980FAC025E5CDF05
#define id73F121AEE1EB4BA0980FAC025E5CDF05

#include "doorkeeper/primitivetypes.hpp"
#include "doorkeeper/implem/maptypes.hpp"
#include <cstdint>
#include <ciso646>

namespace dk {
	template <uint32_t D>
	class PixelConv {
	public:
		typedef Vector<D> coords;

		PixelConv ( MapTypes parType, const coords& parTileSize );

		virtual coords to_pixel ( const coords& parFrom, const coords& parOffset ) const = 0;
		virtual coords pick_tile ( const coords& parPixelPoint, const coords& parOffset ) const = 0;

		MapTypes map_type ( void ) const;
		const coords& tile_size ( void ) const;

	private:
		const coords m_tile_size;
		const MapTypes m_map_type;
	};

	template <uint32_t D>
	class PixelConvSquare : public PixelConv<D> {
	public:
		using base_class = PixelConv<D>;
		using typename base_class::coords;

		explicit PixelConvSquare ( const coords& parTileSize );
		virtual ~PixelConvSquare ( void ) noexcept = default;

		virtual coords to_pixel ( const coords& parFrom, const coords& parOffset ) const;
		virtual coords pick_tile ( const coords& parPixelPoint, const coords& parOffset ) const;
	};

	class PixelConvDiamond : public PixelConv<2> {
	public:
		using base_class = PixelConv<2>;
		using base_class::coords;

		PixelConvDiamond ( const coords& parTileSize, bool parStaggered, bool parFirstReentrant );
		PixelConvDiamond ( const coords& parTileSize, bool parStaggered, bool parFirstReentrant, const coords& parRatio );
		virtual ~PixelConvDiamond ( void ) noexcept = default;

		virtual coords to_pixel ( const coords& parFrom, const coords& parOffset ) const;
		virtual coords pick_tile ( const coords& parPixelPoint, const coords& parOffset ) const;

	protected:
		const coords m_ratio;
		const CoordinateScalarType m_first_reentr;
		const bool m_staggered;
	};

	class PixelConvHex : public PixelConv<2> {
	public:
		using base_class = PixelConv<2>;
		using base_class::coords;

		PixelConvHex ( const coords& parTileSize, bool parFirstReentrant );
		virtual ~PixelConvHex ( void ) noexcept = default;

		virtual coords to_pixel ( const coords& parFrom, const coords& parOffset ) const;
		virtual coords pick_tile ( const coords& parPixelPoint, const coords& parOffset ) const;

	private:
		const CoordinateScalarType m_first_reentr;
	};
} //namespace dk

#include "doorkeeper/implem/pixelconv.inl"

#endif
