#include "stdafx.h"
#include "2DCommon.h"
#include <math.h>


DWORD GetClrRefFromByte( const BYTE& r, const BYTE& g, const BYTE& b )
{
	return (DWORD)(r + g*256 +b*65536);
}

DWORD GetLengthFromTwoPoints( const CPoint& ptl, const CPoint& ptr )
{
 	CSize sz = ptl-ptr;	
	return (DWORD)sqrt((double)(sz.cx*sz.cx + sz.cy*sz.cy));
}

void GetRGBFromClrRef( const DWORD cr, BYTE * r, BYTE * g, BYTE * b )
{
	*b = BYTE(cr/65536);
	DWORD szResult = cr % 65536;
	*g = BYTE(szResult / 256);
	*r = BYTE(szResult % 256);
}

int Factorial( int n )
{
	if (n==1 || n==0)
	{
		return 1;
	} 
	else
	{
		return n*Factorial(n-1);
	}
}

double Combination( int n, int i )
{
	return ((double)Factorial(n))/((double)(Factorial(i)*Factorial(n-i)));
}

double Power( double t, int n )
{
	double sum = 1.0;
	if (n==0)
	{
		return 1;
	}
	for (int i=0; i!=n; ++i)
	{
		sum*=t;
	}
	return sum;
}
