#include <math.h>
#include "myVector.h"
#include <stdio.h>


MyVec4f::MyVec4f(){
}


MyVec4f::MyVec4f(const float& a, const float& b, const float& c, 
		       const float& d){
  this->data[0]=a;
  this->data[1]=b;
  this->data[2]=c;
  this->data[3]=d;
}


MyVec4f::MyVec4f(const MyVec4f& copied){
  this->data[0]=copied.data[0];
 this->data[1]=copied.data[1];
 this->data[2]=copied.data[2];
 this->data[3]=copied.data[3];
}

MyVec4f::~MyVec4f(){

}

void MyVec4f::print(){
  printf("%.2f %.2f %.2f\n", data[0], data[1], data[2]);
}


void MyVec4f::print(char *string){
  printf("%s:  %.2f %.2f %.2f\n", data[0], data[1], data[2]);
}

void MyVec4f::set(float& a, float& b, float& c, float& d){
  this->data[0]=a;
  this->data[1]=b;
  this->data[2]=c;
  this->data[3]=d;
}

float MyVec4f::norm(){
  return(sqrt((this->data[0]*this->data[0])+
	      (this->data[1]*this->data[1])+
	      (this->data[2]*this->data[2])+
	      (this->data[3]*this->data[3])));
}

void MyVec4f::normalize(){
    float length =this->norm();
    if (length != 0){
      this->data[0] /= length;
      this->data[1] /= length;
      this->data[2] /= length;
      this->data[3] /= length;
    }
}

void MyVec4f::zero(){
  this->data[0]=0;
  this->data[1]=0;
  this->data[2]=0;
  this->data[3]=0;
}

 MyVec4f MyVec4f::operator = (const MyVec4f &other){
   //assign this to be the other ;)
   if (&other != this){
     this->data[0] = other.data[0];
     this->data[1] = other.data[1];
     this->data[2] = other.data[2];
     this->data[3] = other.data[3];
   }
   return *this;
 }
 
 MyVec4f MyVec4f::operator + (const MyVec4f &other){
   MyVec4f temp;
   temp.data[0] = this->data[0] + other.data[0];
   temp.data[1] = this->data[1] + other.data[1];
   temp.data[2] = this->data[2] + other.data[2];
   temp.data[3] = this->data[3] + other.data[3];
   return temp;
 }

 MyVec4f MyVec4f::operator - (const MyVec4f &other){
   MyVec4f temp;
   temp.data[0] = this->data[0] - other.data[0];
   temp.data[1] = this->data[1] - other.data[1];
   temp.data[2] = this->data[2] - other.data[2];
   temp.data[3] = this->data[3] - other.data[3];
   return temp;
 }



 MyVec4f MyVec4f::operator += (const MyVec4f &other){
   this->data[0] += other.data[0];
   this->data[1] += other.data[1];
   this->data[2] += other.data[2];
   this->data[3] += other.data[3];
 }


 MyVec4f MyVec4f::operator -= (const MyVec4f &other){
   this->data[0] -= other.data[0];
   this->data[1] -= other.data[1];
   this->data[2] -= other.data[2];
   this->data[3] -= other.data[3];
 }
 MyVec4f MyVec4f::operator *= (const float &scalar){
   this->data[0] *= scalar;
   this->data[1] *= scalar;
   this->data[2] *= scalar;
   this->data[3] *= scalar;
 }
 bool MyVec4f::operator == (const MyVec4f &other){
   if(&other != this) {
     if (other.data[0] != this->data [0]) return false;
     if (other.data[1] != this->data [1]) return false;
     if (other.data[2] != this->data [2]) return false;
     if (other.data[3] != this->data [3]) return false;
   }
   return true;
 }
 bool MyVec4f::operator != (const MyVec4f &other){
   if(&other != this)
     {
       if (other.data[0] != this->data [0]) return true;
       if (other.data[1] != this->data [1]) return true;
       if (other.data[2] != this->data [2]) return true;
       if (other.data[3] != this->data [3]) return true;
     }
   return false;
 }

 MyVec4f operator *(const float &s, const MyVec4f &v){
   MyVec4f temp;
   temp.data[0] = s * v.data[0];
   temp.data[1] = s * v.data[1];
   temp.data[2] = s * v.data[2];
   temp.data[3] = s * v.data[3];
   return temp;
 }
 MyVec4f operator *(const MyVec4f &v, const float &s){
   MyVec4f temp;
   temp.data[0] = s * v.data[0];
   temp.data[1] = s * v.data[1];
   temp.data[2] = s * v.data[2];
   temp.data[3] = s * v.data[3];
   return temp;
 }
  
  
 MyVec4f cross_product(const MyVec4f &LHV, const MyVec4f &RHV){

	MyVec4f temp;
	if (temp.data[3] != 1){
	  printf("Possible Error:  Program assumes hommogeneous vector\n");
	}
	temp.data[0] = LHV.data[1]*RHV.data[2] - LHV.data[2]*RHV.data[1];
	temp.data[1] = LHV.data[0]*RHV.data[2] - LHV.data[2]*RHV.data[0];
	temp.data[2] = LHV.data[0]*RHV.data[1] - LHV.data[1]*RHV.data[0];
	
	return temp;
 }

 float dot_product(const MyVec4f &LHV, const MyVec4f &RHV){
   	return LHV.data[0]*RHV.data[0] + LHV.data[1]*RHV.data[1] + LHV.data[2]*RHV.data[2] + LHV.data[3]*RHV.data[3];
 }