#include "Utils.h"

void Clamp(double &arg, double min, double max)
{
	if (arg < min)	arg = min;
	if (arg > max)	arg = max;
}

double Distance(DataType dat1, DataType dat2)
{
	/*
	double tmp = 0;
	for(int i=0; i<5; ++i)
	{
		if(dat1.w[i] > dat2.w[i])
			tmp += (dat1.w[i] - dat2.w[i]);
		else
			tmp += (dat2.w[i] - dat1.w[i]);
	}
	return tmp;
	*/
	double dis = 0;
	for(int i=0; i<5; ++i)
	{
		dis += pow((dat1.w[i]-dat2.w[i]),2);
	}
	return sqrt(dis);
}

double EuclidDistance(DataType dat1, DataType dat2)
{
	double dis = 0;
	for(int i=0; i<5; ++i)
	{
		dis += pow((dat1.w[i]-dat2.w[i]),2);
	}
	return sqrt(dis);
}

ostream& operator<<(ostream& out, const vector<DataType>& v)
{
	for(unsigned int i=0; i<v.size(); ++i)
	{
		out << v[i] << endl;
	}
	return out;
}

ostream& operator<<(ostream& out, const DataType& s)
{
    out << s.ID;
    for(int i=0; i<5; ++i)
		out << "\t" << s.w[i];
    return out;
}

ifstream& operator>>(ifstream& in, DataType& s)
{
    in >> s.ID;
    for(int i=0; i<5; ++i)
		in >> s.w[i];
    return in;
}
