/*
 * Copyright 2013, kaj dijkstra , 
 * Author, Kaj Dijkstra.
 * All rights reserved.
 *
 */
  import {matrix3, vector3} from './math.js';

/**
 * Boundingbox
**/
class boundingBox {
	maxExtent = [0, 0, 0];
	minExtent = [0, 0, 0];
	intersectionVector;

	/**
	 * make boundingbox as big as point cloud
	 * @param {(array)} points
	**/
	fitBoxToPoints_( points, rotationMatrix ) {

	  var minVector;

	  for (var index = 0; index < 3; ++index) {
		  
		this.maxExtent[index] = this.minExtent[index] = points[index];

		for (var i = 1; i < points.length / 3; ++i) {
			
			
			var point = [points[i * 3], points[(i * 3) + 1], points[(i * 3) + 2]] ;
			
			if(rotationMatrix){
				var translation = rotationMatrix[3];
				
				if(translation) {
					point = vector3.add([translation[0], translation[1], translation[2]], point);
				}
				
				point = matrix3.transformPoint(rotationMatrix, point);
			
			
			}
			//if(this.minExtent[index] > point[i] && index == 1)
			//var minVector = point;

			this.minExtent[index] = Math.min(this.minExtent[index], point[index]);
			this.maxExtent[index] = Math.max(this.maxExtent[index], point[index]);
		}
	  }
	   
	  this.intersectionVector = minVector;

	  this.valid = true;
	}
}

export {boundingBox as default};