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

#pragma once

#include "glmVector2.h"
#include "glmRTTI.h"

namespace glm
{
	class RandomNumberGenerator;

	/** 
	* \brief Class representing a 2D circle
	*
	* \ingroup geometry2
	* \author Golaem <dev@golaem.com>
	*
	* \param float Manipulated scalar type (\ref Expression, double, float...)
	*/

	class GLM_CORE_API Circle2
	{
	public: 

		GLM_CLASS_STAT_ID( glm::MemoryStatIds::GolaemShared)

		/**
		* \name Construction/Destruction
		*/
		//@{
		/** 
		* \brief Constructor from a radius, the circle will be centered on (0,0)
		* \param radius The radius (default is 1.0)
		* \param exp2 If true, the given radius is considered as the squared radius (default is false).
		*/
		Circle2(float radius = 1.f, bool exp2=false);

		/** 
		* \brief Constructor form a center and a radus.
		*
		* \param center The center of the circle.
		* \param radius The radius (default is 1.0).
		* \param exp2 If true, the given radius is considered as the squared radius (default is false).
		*/
		Circle2(const Vector2 & center, float radius = 1.f, bool exp2=false);

		/**
		* \brief Destructor
		*/
		~Circle2();
		//@}
		/**
		* \name Accessors
		*/
		//@{
		float getRadius() const;
		void setRadius(float radius);
		float getRadius2() const;
		void setRadius2(float radius2);
		const Vector2& getCenter() const;
		void setCenter(const Vector2& center);
		//@}

		/** 
		* \brief Compute and returns a random point inside this circle.
		* The method used here is the "corrected disc sampling" from the 
		* book "Essential mathematics for games & interactive application" 
		* by James M. Van Verth and Lars M. Bishop (pp 532-533).
		* \param rng The random number generator to use.
		*/
		Vector2 randomPoint(RandomNumberGenerator& rng) const;

		/** 
		* \name Comparisons
		*/
		//@{
		bool operator==(const Circle2& circle2) const;
		bool operator!=(const Circle2& circle2) const;
		//@}

	protected:

		/** 
		* \brief The center of the circle.
		*/	
		Vector2 _center;
		/** 
		* \brief Squared radius of the circle.
		*/
		float _radius2;
	};

	/** 
	* \brief Compute the two tangents to a circle to which a given belongs.
	* \param[in] circle The circle.
	* \param[in] point The point.
	* \param[out] leftTangentPoint The circle point defining the left tangent (ie the tangent on the left of the ray defined from the given point to the circle's center).
	* \param[out] rightTangentPoint The circle point defining the right tangent.
	* \return False if the point is inside the circle.
	*/

	bool circleTangents(const Circle2& circle, const Vector2& point, Vector2& leftTangentPoint, Vector2& rightTangentPoint);
}

