import { Box3 } from '../math/Box3';
import { Line } from '../objects/Line';
import { LineBasicMaterial } from '../materials/LineBasicMaterial';
import { Float32BufferAttribute } from '../core/BufferAttribute';
import { BufferGeometry } from '../core/BufferGeometry';

/**
  * @author WestLangley / http://github.com/WestLangley
  *
 */

function PlaneHelper( plane, size, hex ) {

	this.type = 'PlaneHelper';

	this.plane = plane;

	this.size = ( size === undefined ) ? 1 : size;

	var color = ( hex !== undefined ) ? hex : 0xffff00;

	var positions = [ 1, - 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, - 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0 ];

	var geometry = new BufferGeometry();

	geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );

	Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );

	this.geometry.computeBoundingSphere();

	//

	var positions = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];

	var geometry = new BufferGeometry();

	geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );

	var child = new THREE.Mesh( geometry, new LineBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) );

	child.geometry.computeBoundingSphere();

	this.add( child );

	//

	this.onBeforeRender();

}

PlaneHelper.prototype = Object.create( Line.prototype );
PlaneHelper.prototype.constructor = PlaneHelper;

PlaneHelper.prototype.onBeforeRender = function () {

	var scale = - this.plane.constant;

	if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter

	this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );

	this.lookAt( this.plane.normal );

};

export { PlaneHelper };

@@ -687,33 +687,32 @@
 fferGeometry();%0A
-%0A
 %09geometry.addAtt
@@ -776,16 +776,51 @@
 , 3 ) );
+%0A%09geometry.computeBoundingSphere();
 %0A%0A%09Line.
@@ -891,49 +891,8 @@
 );%0A%0A
-%09this.geometry.computeBoundingSphere();%0A%0A
 %09//%0A
@@ -898,32 +898,33 @@
 %0A%0A%09var positions
+2
  = %5B 1, 1, 1, - 
@@ -986,32 +986,33 @@
 ;%0A%0A%09var geometry
+2
  = new BufferGeo
@@ -1020,17 +1020,16 @@
 etry();%0A
-%0A
 %09geometr
@@ -1021,32 +1021,33 @@
 try();%0A%09geometry
+2
 .addAttribute( '
@@ -1086,32 +1086,33 @@
 ibute( positions
+2
 , 3 ) );%0A%0A%09var c
@@ -1108,21 +1108,55 @@
  );%0A
-%0A%09var child =
+%09geometry2.computeBoundingSphere();%0A%0A%09this.add(
  new
@@ -1168,32 +1168,33 @@
 E.Mesh( geometry
+2
 , new LineBasicM
@@ -1278,69 +1278,8 @@
  ) )
-;%0A%0A%09child.geometry.computeBoundingSphere();%0A%0A%09this.add( child
  );%0A

Clean up.