//-----------------------------------------------------------------------------------------------
// Disc2D.hpp
//
#pragma once
#ifndef INCLUDED_Disc2D
#define INCLUDED_Disc2D

//-----------------------------------------------------------------------------------------------
#include "Engine/Core/MathBase.hpp"
#include "Engine/Core/Vector2.hpp"


/////////////////////////////////////////////////////////////////////////////////////////////////
class Disc2D
{
public:
	Vector2 center;
	float	radius;

public:
	static const Disc2D UNIT_CIRCLE;

public:
	// Constructors
	~Disc2D() {}
	Disc2D() {}
	Disc2D( const Disc2D& copy );
	explicit Disc2D( float initialX, float initialY, float initialRadius );
	explicit Disc2D( const Vector2& initialCenter, float initialRadius );

	// Mutators
	void StretchToIncludePoint( const Vector2& point );
	void AddPadding( float paddingRadius );
	void Translate( const Vector2& translation );

	// Accessors
	bool IsPointInside( const Vector2& point ) const;

	// Operators
	const Disc2D operator + ( const Vector2& translation ) const;
	const Disc2D operator - ( const Vector2& antiTranslation ) const;
	void operator += ( const Vector2& translation );
	void operator -= ( const Vector2& antiTranslation );
};


//-----------------------------------------------------------------------------------------------
inline Disc2D::Disc2D( const Disc2D& copy )
	: center( copy.center )
	, radius( copy.radius )
{
}


//-----------------------------------------------------------------------------------------------
inline Disc2D::Disc2D( float initialX, float initialY, float initialRadius )
	: center( initialX, initialY )
	, radius( initialRadius )
{
}


//-----------------------------------------------------------------------------------------------
inline Disc2D::Disc2D( const Vector2& initialCenter, float initialRadius )
	: center( initialCenter )
	, radius( initialRadius )
{
}


//-----------------------------------------------------------------------------------------------
inline void Disc2D::StretchToIncludePoint( const Vector2& point )
{
	float distSquaredToPoint = CalcDistanceSquared( center, point );
	if( distSquaredToPoint > (radius * radius) )
	{
		radius = sqrt( distSquaredToPoint );
	}
}


//-----------------------------------------------------------------------------------------------
inline void Disc2D::AddPadding( float paddingRadius )
{
	radius += paddingRadius;
}


//-----------------------------------------------------------------------------------------------
inline void Disc2D::Translate( const Vector2& translation )
{
	center += translation;
}


//-----------------------------------------------------------------------------------------------
inline bool Disc2D::IsPointInside( const Vector2& point ) const
{
	float distSquaredToPoint = CalcDistanceSquared( center, point );
	return( distSquaredToPoint < (radius * radius) );
}


//-----------------------------------------------------------------------------------------------
inline const Disc2D Disc2D::operator + ( const Vector2& translation ) const
{
	return Disc2D( center + translation, radius );
}


//-----------------------------------------------------------------------------------------------
inline const Disc2D Disc2D::operator - ( const Vector2& antiTranslation ) const
{
	return Disc2D( center - antiTranslation, radius );
}


//-----------------------------------------------------------------------------------------------
inline void Disc2D::operator += ( const Vector2& translation )
{
	center += translation;
}


//-----------------------------------------------------------------------------------------------
inline void Disc2D::operator -= ( const Vector2& antiTranslation )
{
	center -= antiTranslation;
}


#endif // INCLUDED_Disc2D
