//-----------------------------------------------------------------------------------------------
// Vector2.cpp
//
#include "GypsyPrecompiledHeader.hpp"

//-----------------------------------------------------------------------------------------------
#include "Engine/Core/Vector2.hpp"
#include "Engine/Core/IntVector2.hpp"
#include "Engine/Core/ErrorWarningAssert.hpp"
#include <stdlib.h>


//-----------------------------------------------------------------------------------------------
STATIC const Vector2 Vector2::ZERO		( 0.f, 0.f );
STATIC const Vector2 Vector2::ONE		( 1.f, 1.f );


//-----------------------------------------------------------------------------------------------
Vector2::Vector2( const IntVector2& fromIntVec2 )
	: x( static_cast< float >( fromIntVec2.x ) )
	, y( static_cast< float >( fromIntVec2.y ) )
{
}


//-----------------------------------------------------------------------------------------------
void Vector2::SetFromText( const char* asText )
{
	const int MAX_BUFFER_LENGTH = 1024;
	char writeBuffer[ MAX_BUFFER_LENGTH ];
	const char* readScan = asText;
	char* writeScan = writeBuffer;
	char* startOfSecondValue = writeBuffer;
	char* endOfTempBuffer = &writeBuffer[ MAX_BUFFER_LENGTH - 1 ];
	
	while( *readScan != '\0' && writeScan != endOfTempBuffer )
	{
		if( *readScan == ',' )
		{
			*writeScan = '\0';
			startOfSecondValue = writeScan + 1;
		}
		else
		{
			*writeScan = *readScan;
		}

		++ readScan;
		++ writeScan;
	}

	*writeScan = '\0';
	x = (float) atof( writeBuffer );
	y = (float) atof( startOfSecondValue );
}

