//-----------------------------------------------------------------------------------------------
// Capsule2D.hpp
//
#pragma once
#ifndef INCLUDED_Capsule2D
#define INCLUDED_Capsule2D

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


/////////////////////////////////////////////////////////////////////////////////////////////////
class Capsule2D
{
public:
	Vector2		start;
	Vector2		end;
	float		radius;

public:
	// Constructors
	~Capsule2D() {}
	Capsule2D() {}
	Capsule2D( const Capsule2D& copy );
	explicit Capsule2D( float startX, float startY, float endX, float endY, float initialRadius );
	explicit Capsule2D( const Vector2& startCenter, const Vector2& endCenter, 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 Capsule2D operator + ( const Vector2& translation ) const;
	const Capsule2D operator - ( const Vector2& antiTranslation ) const;
	void operator += ( const Vector2& translation );
	void operator -= ( const Vector2& antiTranslation );
};


//-----------------------------------------------------------------------------------------------
inline Capsule2D::Capsule2D( const Capsule2D& copy )
	: start( copy.start )
	, end( copy.end )
	, radius( copy.radius )
{
}


//-----------------------------------------------------------------------------------------------
inline Capsule2D::Capsule2D( float startX, float startY, float endX, float endY, float initialRadius )
	: start( startX, startY )
	, end( endX, endY )
	, radius( initialRadius )
{
}


//-----------------------------------------------------------------------------------------------
inline Capsule2D::Capsule2D( const Vector2& startCenter, const Vector2& endCenter, float initialRadius )
	: start( startCenter )
	, end( endCenter )
	, radius( initialRadius )
{
}


//-----------------------------------------------------------------------------------------------
inline void Capsule2D::StretchToIncludePoint( const Vector2& point )
{
	UNUSED( point );
	FATAL_ERROR( "Capsule2D::StretchToIncludePoint() - NOT YET IMPLEMENTED" );
}


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


//-----------------------------------------------------------------------------------------------
inline void Capsule2D::Translate( const Vector2& translation )
{
	start += translation;
	end += translation;
}


//-----------------------------------------------------------------------------------------------
inline bool Capsule2D::IsPointInside( const Vector2& point ) const
{
	float distSquared = CalcDistanceSquaredPointToLineSegment2D( point, start, end );
	return( distSquared < (radius * radius) );
}


//-----------------------------------------------------------------------------------------------
inline const Capsule2D Capsule2D::operator + ( const Vector2& translation ) const
{
	return Capsule2D( start + translation, end + translation, radius );
}


//-----------------------------------------------------------------------------------------------
inline const Capsule2D Capsule2D::operator - ( const Vector2& antiTranslation ) const
{
	return Capsule2D( start - antiTranslation, end - antiTranslation, radius );
}


//-----------------------------------------------------------------------------------------------
inline void Capsule2D::operator += ( const Vector2& translation )
{
	start += translation;
	end += translation;
}


//-----------------------------------------------------------------------------------------------
inline void Capsule2D::operator -= ( const Vector2& antiTranslation )
{
	start -= antiTranslation;
	end -= antiTranslation;
}


#endif // INCLUDED_Capsule2D
