//-----------------------------------------------------------------------------------------------
// IntRange.hpp
//
#pragma once
#ifndef INCLUDED_IntRange
#define INCLUDED_IntRange

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


/////////////////////////////////////////////////////////////////////////////////////////////////
class IntRange
{
public:
	int min;
	int max;

public:
	static const IntRange kZero;
	static const IntRange kOne;
	static const IntRange kZeroOrOne;

public:
	// Constructors
	~IntRange() {}
	IntRange() {}
	IntRange( const IntRange& copy );
	explicit IntRange( int initialMin, int initialMax );
	explicit IntRange( const char* asText );

	// Mutators
	void SetFromText( const char* asText );
	void SetMinMax( int newMin, int newMax );

	// Accessors
	void GetMinMax( int& out_min, int& out_max ) const;
	const int* GetAsIntArray() const { return &min; }
	int* GetAsIntArray() { return &min; }

	// Operators
	const bool operator == ( const IntRange& comparison ) const;
	const bool operator != ( const IntRange& comparison ) const;
	const IntRange operator + ( const IntRange& rangeToAdd ) const;
	const IntRange operator - ( const IntRange& rangeToSubtract ) const;
	const IntRange operator * ( const float scale ) const;
	const IntRange operator + ( const int translation ) const;
	IntRange& operator += ( const int translation );
};


//-----------------------------------------------------------------------------------------------
inline IntRange::IntRange( const IntRange& copy )
	: min( copy.min )
	, max( copy.max )
{
}


//-----------------------------------------------------------------------------------------------
inline IntRange::IntRange( const int initialMin, const int initialMax )
	: min( initialMin )
	, max( initialMax )
{
}


//-----------------------------------------------------------------------------------------------
inline void IntRange::SetMinMax( int newMin, int newMax )
{
	min = newMin;
	max = newMax;
}


//-----------------------------------------------------------------------------------------------
inline const bool IntRange::operator == ( const IntRange& comparison ) const
{
	return( min == comparison.min && max == comparison.max );
}


//-----------------------------------------------------------------------------------------------
inline const bool IntRange::operator != ( const IntRange& comparison ) const
{
	return( min != comparison.min || max != comparison.max );
}


//-----------------------------------------------------------------------------------------------
inline const IntRange IntRange::operator + ( const IntRange& rangeToAdd ) const
{
	return IntRange( min + rangeToAdd.min, max + rangeToAdd.max );
}


//-----------------------------------------------------------------------------------------------
inline const IntRange IntRange::operator - ( const IntRange& rangeToSubtract ) const
{
	return IntRange( min - rangeToSubtract.min, max - rangeToSubtract.max );
}


//-----------------------------------------------------------------------------------------------
inline const IntRange IntRange::operator + ( const int translation ) const
{
	return IntRange( min + translation, max + translation );
}


//-----------------------------------------------------------------------------------------------
inline IntRange& IntRange::operator += ( const int translation )
{
	min += translation;
	max += translation;
	return *this;
}


//-----------------------------------------------------------------------------------------------
inline const IntRange IntRange::operator * ( const float scale ) const
{
	double dScale = scale;
	IntRange scaled;
	double scaledX = dScale * static_cast< double >( min );
	double scaledY = dScale * static_cast< double >( max );
	scaled.min = static_cast< int >( scaledX );
	scaled.max = static_cast< int >( scaledY );
	return scaled;
}



#endif // INCLUDED_IntRange
