/***************************************************************************
*                                                                          *
*  Copyright (C) Golaem S.A.  All Rights Reserved.                         *
*                                                                          *
***************************************************************************/

#pragma once

#include "glmLooseQuadtreeNode.h"

namespace glm
{
	/**
	* \brief 2D quad tree node, root "specialization"
	*
	* \ingroup ...
	*
	* \author Golaem <dev@golaem.com>
	*
	* \tparam Data The data contained in each cell of the grid.
	*/
	class LooseQuadtreeRootNode : public LooseQuadtreeNode
	{

	public:
		class Shape
		{
		public:
			enum Value
			{
				NOSHAPE = 0,
				POINT = 1,
				QUAD = 2,
				POLYGON = 3,
				CIRCLE = 4
			};
		};

	public:

		GLM_CLASS_STAT_ID( glm::MemoryStatIds::Simulation)

		/**
		* \brief Root node construction.
		*/
		LooseQuadtreeRootNode(const Vector2& worldSize, unsigned int depth = 0, Vector2 resolution = Vector2(1.0, 1.0));

		/**
		* \brief Destructor.
		*/
		virtual ~LooseQuadtreeRootNode();

		/**
		* \brief Retrieve worldSize.
		*/
		void setWorldSize(const Vector2& worldSize);
		const Vector2& getWorldSize() const;

		/**
		* \brief Retrieve shape.
		*/
		LooseQuadtreeRootNode::Shape::Value getShape() const;

		/**
		* \brief Retrieve polygon.
		*/
		const glm::Array< Vector2 >& getPolygon() const;

		/**
		* \brief Retrieve shape.
		*/
		const Circle2& getCircle() const;

		/**
		* \brief Retrieve shape.
		*/
		const Box2& getQuad() const;

		/**
		* \brief Set the point quad mask for the children generation.
		*/
		void addPoint(const Vector2& pointQuadSize);

		/**
		* \brief Set the quad mask for the children generation.
		*/
		void addQuad(const Vector2& quadSize);

		/**
		* \brief Set the polygon mask for the children generation.
		*/
		void addPolygon(const glm::Array< Vector2 >& polygon);

		/**
		* \brief Set the circle mask for the children generation.
		*/
		void addCircle(const Circle2& circle);

		/**
		* \brief add an anchored to the SE corner.
		*/
        void anchorMin(const Vector2& min);

    public:

		/// Precision
		float _precision;

		/// LooseQuadTreeNodes
        glm::PODArray<LooseQuadtreeNode*> _looseQuadtreeNodes;

        unsigned int _maxDepth = 10;

    private:
        /// shape type
        Shape::Value _shape;

        /// World size
        Vector2 _worldSize;

        /// Quad
		Vector2 _quadSize;
		Box2 _centeredQuad;

		/// Polygon
		glm::Array< Vector2 > _polygon;

		/// Circle
		Circle2 _circle;
	};
}
