
/* 3d class is used to represent both points and vectors */

#include "data structures.h"

double xyz::normalize()
{
	double dist;
	dist=sqrt((x*x)+(y*y)+(z*z));
	x = x/dist;
	y = y/dist;
	z = z/dist;
	return(dist);
}

int color::gamma_correct_r()
{
	int ival;
	double dval;
	dval = r/255.0;
	if(dval>1.0) dval=1.0;
	if(dval<0.0) dval=0.0;
	/* gamma correction */
	dval=exp(log(dval)/1.8);    //value of gamma is 1.8
	/*convert to integer range 255 */
	dval *=255.0;
	ival=(int) (dval+0.5);
	return(ival);
}

int color::gamma_correct_g()
{
	int ival;
	double dval;
	dval = g/255.0;
	if(dval>1.0) dval=1.0;
	if(dval<0.0) dval=0.0;
	/* gamma correction */
	dval=exp(log(dval)/1.8);    //value of gamma is 1.8
	/*convert to integer range 255 */
	dval *=255.0;
	ival=(int) (dval+0.5);
	return(ival);
}

int color::gamma_correct_b()
{
	int ival;
	double dval;
	dval = b/255.0;
	if(dval>1.0) dval=1.0;
	if(dval<0.0) dval=0.0;
	/* gamma correction */
	dval=exp(log(dval)/1.8);    //value of gamma is 1.8
	/*convert to integer range 255 */
	dval *=255.0;
	ival=(int) (dval+0.5);
	return(ival);
}

void color :: operator =(color x)
{

		r=x.r;
		g=x.g;
		b=x.b;
}

xyz xyz:: operator +(xyz b)
{
	xyz temp;

	temp.x=x+b.x;
	temp.y=y+b.y;
	temp.z=z+b.z;
	return(temp);

}

xyz xyz:: operator -(xyz b)
{
	xyz temp;

	temp.x=x-b.x;
	temp.y=y-b.y;
	temp.z=z-b.z;
	return(temp);

}

void xyz:: operator =(xyz b)
{
	x=b.x;
	y=b.y;
	z=b.z;
}

xyz xyz:: operator /(double b)
{
	
	this->x=(this->x)/b;
	this->y=(this->y)/b;
	this->z=(this->z)/b;
	return(*this);

}

xyz xyz:: operator -()
{
	this->x=-(this->x);
	this->y=-(this->y);
	this->z=-(this->z);
	return(*this);
}

/*color color:: operator *(double d)
{
	
	this->r=(this->r)*d;
	this->g=(this->g)*d;
	this->b=(this->b)*d;
	return(*this);

}
*/

color color:: operator +(color d)
{
	color temp;

	temp.r=r+d.r;
	temp.g=g+d.g;
	temp.b=b+d.b;
	return(temp);

}