// Might be nifty for some calculations
// var d = require('euclidean-distance');

/* Rounding function */
function roundNum(value, decimals) {
    return Number(Math.round(value+'e'+decimals)+'e-'+decimals);
}

// Takes a decimal from 1 to 0.0 and returns .333... to .666...
// TODO: Not working for numbers that are the same!

function percentageToDec (percentage) {
	var value;
	value = percentage / 100;
	return value;
}

function decToPercent (dec) {
	var value;
	value = dec * 100;
	return value;
}

// Take coordinate sets for two points of any amount of 
// dimensions and find the midpoint

// Parameters: two coordinate points (Arrays), 
// and amount of skew of 0.0 - 1.0 (decimal)
function point(arrays, amount) {
	var midpoint;
	var dimensions = [];

	// var multiplier = percentageToDec(amount);

	// Push a value into the array for each dimension we have
	// for (var i = 0; i < arrays[0].length; i++) {
	// 	dimensions.push(0);
	// };

	// Add up the coordinate point values for each dimension (X, Y, Z, etc,) 
	// for (var i = 0; i < arrays.length; i++) {
	// 	dimensions[0] =	arrays[i][0] + dimensions[0];
	// 	dimensions[1] =	arrays[i][1] + dimensions[1];
	// 	dimensions[2] =	arrays[i][2] + dimensions[2];
	// };

	// for (var i = 0; i < arrays.length; i++) {
	// 	dimensions[0] =	arrays[i][0] + dimensions[0];
	// 	dimensions[1] =	arrays[i][1] + dimensions[1];
	// 	dimensions[2] =	arrays[i][2] + dimensions[2];
	// };

	// Divide them by two and round
	// midpoint = [dimensions[0] * multiplier, dimensions[1] * multiplier, dimensions[2] * multiplier];


	//var percentage = (Math.max(arrays[0][0], arrays[1][0])) / (Math.min(arrays[0][0], arrays[1][0])) * 0;
	var skew = ((Math.max(arrays[0][0], arrays[1][0]) - Math.min(arrays[0][0], arrays[1][0])) * percentageToDec(amount)) + Math.min(arrays[0][0], arrays[1][0]);

	// value = ((max - min) * percentage) + min
	console.log(Math.max(arrays[0][0], arrays[1][0]));
	console.log(Math.min(arrays[0][0], arrays[1][0]));

	//console.log(percentage);
	console.log('Skew: ' + skew);
	//console.log('Percentage > X1, X2 ' + (Math.max(arrays[0][0], arrays[1][0]) / Math.min(arrays[0][0], arrays[1][0])) * 100);

	//midpoint = [roundNum(dimensions[0] * multiplier, 2), roundNum(dimensions[1] * multiplier, 2), roundNum(dimensions[2] * multiplier, 2)];
	//return midpoint;
}	

// var euclideanDistance = (d([-3,4,0], [-3,8,0]));
var euclideanMidpoint = point([[16,8,0], [0,8,0]], 25);
console.log([16,8,0], [0,8,0]);

// console.log('euclideanDistance: ' + euclideanDistance);
//console.log('euclideanMidpoint: ' + euclideanMidpoint);
//console.log([0,0,0], [0,4,0], [4,0,0], [4,4,0]);

// Currently only for 2 dimensional spaces.
// Parameters: set of coordinate points (array)
function calcSpace (points) {  

	// This should scale to any dimension
	// Interpolate between the set of the first two points
	var betweenTwo = point(([points[0], points[1]]), .5);

	// Interpolate between the set of the second two points
	//var betweenTwoOthers = point(([points[2], points[3]]), .5);

	// Interpolate between both of those set points.
	//var sumTotal = point(([betweenTwo, betweenTwoOthers]), .5);

	// Return those the new interpolated coordinate.
	// return points
	//console.log('First Two: ' + betweenTwo);
	//console.log('Second Two: ' + betweenTwoOthers);

	//console.log(sumTotal);
}

//calcSpace([[0,0,0], [0,4,0], [4,0,0], [4,4,0]]);
