#include "OctreeSupport.hpp"
#include <cmath>

#include <iostream>
/* Definitions of Vector functions:
For class and project design, look at the top of Octree.hpp
*/


/***************************************************/
double Vector::Norm() {
	return sqrt(x * x + y * y + z * z);
}
/***************************************************/
void Vector::MultiplyBy(const double scaleFactor) {
	x *= scaleFactor;
	y *= scaleFactor;
	z *= scaleFactor;
}
/***************************************************/
Vector& Vector::operator-=(const Vector& V) {
	x -= V.x;
	y -= V.y;
	z -= V.z;
	return *this;
}
/***************************************************/
Vector& Vector::operator+=(const Vector& V) {
	x += V.x;
	y += V.y;
	z += V.z;
	return *this;
}
/***************************************************/
void Vector::Print(void) const {
	std::cout << "X: " << x << "\tY: " << y << "\tZ: " << z << std::endl;
}
/***************************************************/
/***************************************************/
Vector operator+ (Vector U, const Vector& V) {
	U += V;
	return U;
}
Vector operator- (Vector U, const Vector& V) {
	U -= V;
	return U;
}
/***************************************************/
void Path::Print(void) const {
	std::cout << "X: " << x << "\tY: " << y << "\tZ: " << z << std::endl;
}


/* local funciton performs specific task similar to Matlab's [value,index] = min(stuff)
where negative values have been replaced with NaN
*/
int Octree_PickMinPositiveRatio(const double Xratio, const double Yratio, const double Zratio) {
	// positive is to filter out the '-1' cases from having directionVector component == 0
	if(Xratio >= 0) {
		if((Xratio < Yratio) || (Yratio < 0)) {
			if((Xratio < Zratio) || (Zratio < 0)) {
				return 1;//X ratio is the one we want
			}
			return 3;//Z
		}
		if((Yratio < Zratio) || (Zratio < 0)) {
			return 2;//Y
		}
		return 3;//Z
	}//X ratio not valid
	if(Yratio >= 0) {
		if((Yratio < Zratio) || (Zratio < 0)) {
			return 2;//Y
		}
		return 3;//Z
	}//Y ratio not valid
	if(Zratio >= 0) {
		return 3;//Z
	}
	return -1;//error
}


// local funcion performs specific task similar to Matlab's [val,index] = max(stuff)
int Octree_PickMaxRatio(double& Xratio, const double Yratio, const double Zratio) {
	// returns the 'index' of the maximum value, and sets the first input to the corresponding value.
	if(Xratio < Yratio) {
		if(Yratio < Zratio)	{
			Xratio = Zratio;
			return 3;
		}
		Xratio = Yratio;
		return 2;
	}
	if(Xratio < Zratio) {
		Xratio = Zratio;
		return 3;
	}
	return 1;
}

// local functions:
void OctreeNode_PrintTabs(int num) {
	for(int ii = 0; ii < num; ii++) {
		std::cout << "  ";
	}
}



