<commit_before>var Mode3D = (function (scope) {
	//Constructor
	function Mode3D(document){
		this.document = document;

		this.animId = null;

		this.leftView = null;
		this.leftCamera = null;
		this.leftRenderer = null;
		this.leftControls = null;
		this.leftMesh = null;

		this.rightView = null;
		this.rightCamera = null;
		this.rightRenderer = null;
		this.rightControls = null;

		this.leftMesh = null;
		this.rightMesh = null;

		this.labels = [];
	}

	// Creates the scene and everything
	Mode3D.prototype.init = function(div,gui){
		// Create two child divs
		var leftCanvas = document.getElementById("left-view").getElementsByTagName("canvas")[0];
		var rightCanvas = document.getElementById("right-view").getElementsByTagName("canvas")[0];

		var viewWidth = (window.innerWidth-50)/2;

		// Init gui
		gui.init("3D",this.callbacks,this);
		this.gui = gui;

		this.leftView = new THREE.Scene();
		this.leftCamera = new THREE.PerspectiveCamera( 75, viewWidth / window.innerHeight, 0.1, 1000 );
		this.leftCamera.position.set(5,10,20);
		this.leftRenderer = new THREE.WebGLRenderer({ canvas: leftCanvas, antialias: true });
		this.leftRenderer.setClearColor(0xffffff);
		this.leftRenderer.setSize( viewWidth, window.innerHeight );

		this.leftControls = new THREE.OrbitControls( this.leftCamera, this.leftRenderer.domElement );
		this.leftControls.enableKeys  = false;

		var GridHelper = new Grid();
		var grid = GridHelper.CreateGrid("XZ");
		this.leftView.add(grid);

		var axis = GridHelper.CreateAxis("X");
		this.leftView.add(axis);
		axis = GridHelper.CreateAxis("Y");
		this.leftView.add(axis);
		axis = GridHelper.CreateAxis("Z");
		this.leftView.add(axis);

		var leftXLabel = GridHelper.CreateLabel("X",12,0,0); this.labels.push(leftXLabel);
		this.leftView.add(leftXLabel);
		var leftYLabel = GridHelper.CreateLabel("Y",0,12,0); this.labels.push(leftYLabel);
		this.leftView.add(leftYLabel);
		var leftZLabel = GridHelper.CreateLabel("Z",0,0,12); this.labels.push(leftZLabel);
		this.leftView.add(leftZLabel);

		this.rightView = new THREE.Scene();
		this.rightCamera = new THREE.PerspectiveCamera( 75, viewWidth / window.innerHeight, 0.1, 1000 );
		this.rightCamera.position.set(0,0,20);
		this.rightRenderer = new THREE.WebGLRenderer({ canvas: rightCanvas, antialias: true });
		this.rightRenderer.setClearColor(0xffffff);
		this.rightRenderer.setSize( viewWidth, window.innerHeight );

		this.rightControls = new THREE.OrbitControls( this.rightCamera, this.rightRenderer.domElement );
		this.rightControls.enableRotate = false;
		this.rightControls.enableKeys  = false;

		grid = GridHelper.CreateGrid("XY");
		this.rightView.add(grid);

		axis = GridHelper.CreateAxis("X");
		this.rightView.add(axis);
		axis = GridHelper.CreateAxis("Y");
		this.rightView.add(axis);

		var rightXLabel = GridHelper.CreateLabel("X",12,0,0);
		this.rightXLabel = rightXLabel;
		this.rightView.add(rightXLabel);
		var rightYLabel = GridHelper.CreateLabel("Z",0,12,0);
		this.rightYLabel = rightYLabel;
		this.rightView.add(rightYLabel);
		// Add lights to the scene
		var lightSky = new THREE.HemisphereLight( 0xffffbb, 0x080820, .7 );
		this.leftView.add( lightSky );
		var lightGround = new THREE.HemisphereLight( 0xffffbb, 0x080820, .4 );
		this.leftView.add( lightGround );
		lightGround.position.y = -5;
		lightGround.position.x = 2;

		this.util = new Util();
		this.projector = new Projecting();
		this.slicer = new Slicing();

		this.intersectionPlane = this.CreateIntersectionPlane();
		this.intersectionPlane.position.y = this.gui.params.axis_value;
		this.leftView.add(this.intersectionPlane);

		this.animate();

		this.setMode();

		}

	Mode3D.prototype.CreateIntersectionPlane = function(){
		var color =  this.gui.colors.slices;

		var v1 = new THREE.Vector3( 10, 0, 10 );
		var v2 = new THREE.Vector3( -10, 0, 10 );
		var v3 = new THREE.Vector3( -10, 0, -10 );
		var v4 = new THREE.Vector3( 10, 0, -10 );

		var geometry = new THREE.Geometry();
		geometry.vertices.push( v1 );
		geometry.vertices.push( v2 );
		geometry.vertices.push( v3 );
		geometry.vertices.push( v4 );
		geometry.faces.push(new THREE.Face3(0,1,2));
		geometry.faces.push(new THREE.Face3(2,3,0));

		var material = new THREE.MeshPhongMaterial( {color: color, flatShading:true, transparent:true, opacity:0.5, side:THREE.DoubleSide} );
		var mesh = new THREE.Mesh( geometry, material );

		mesh.updatePosition = function(val){
			if(this.axis == "Y")
				this.position.y = val;
			if(this.axis == "X")
				this.position.x = val;
			if(this.axis == "Z")
				this.position.z = val;
		}

		mesh.flip = function(newAxis){
			this.rotation.z = 0;
			this.rotation.x = 0;
			this.position.x = 0;
			this.position.y = 0;
			this.position.z = 0;

			if(newAxis == "Y"){
				let label = this.rightXLabel;
				label.ctx.clearRect(0,0,label.canvas.width,label.canvas.height);
				label.ctx.fillText( "X", label.canvas.width/2, label.canvas.height/2);

				label = this.rightYLabel;
				label.ctx.clearRect(0,0,label.canvas.width,label.canvas.height);
				label.ctx.fillText( "Z", label.canvas.width/2, label.canvas.height/2);
			}
			if(newAxis == "X"){
				this.rotation.z = Math.PI/2;

				let label = this.rightXLabel;
				label.ctx.clearRect(0,0,label.canvas.width,label.canvas.height);
				label.ctx.fillText( "Y", label.canvas.width/2, label.canvas.height/2);

				label = this.rightYLabel;
				label.ctx.clearRect(0,0,label.canvas.width,label.canvas.height);
				label.ctx.fillText( "Z", label.canvas.width/2, label.canvas.height/2);
			}
			if(newAxis == "Z"){
				this.rotation.x = Math.PI/2;

				let label = this.rightXLabel;
				label.ctx.clearRect(0,0,label.canvas.width,label.canvas.height);
				label.ctx.fillText( "X", label.canvas.width/2, label.canvas.height/2);

				label = this.rightYLabel;
				label.ctx.clearRect(0,0,label.canvas.width,label.canvas.height);
				label.ctx.fillText( "Y", label.canvas.width/2, label.canvas.height/2);
			}

			this.rightXLabel.material.map.needsUpdate = true;
			this.rightYLabel.material.map.needsUpdate = true;
			this.axis = newAxis;


		}

		mesh.axis = "Y";
		mesh.rightYLabel = this.rightYLabel;
		mesh.rightXLabel = this.rightXLabel;

		return mesh;
	}

	Mode3D.prototype.CalculateIntersection = function(){
		// TODO: Compute and render intersection
	}

	// define a function to be called when each param is updated
	function updateParametricCallback(self,val){
		self.cleanupLeftMesh();
		self.initParametric()
	}

	function updateRenderShape(self,val,opacity_val){
		if(opacity_val === undefined){
			opacity_val = val ? 1 : 0;
		}
		// TODO: Toggle projection visibility
	}

	function updateRenderSlices(self,val,opacity_val){
		if(opacity_val === undefined){
			opacity_val = val ? 1 : 0;
		}
		var params = self.gui.params;
		var source = params.source;

		// TODO: Toggle making the slices hidden
	}

	Mode3D.prototype.callbacks = {
		'axis': function(self,val) {
			self.cleanupLeftMesh();
			self.initCartesian();

			self.intersectionPlane.flip(val);

			self.CalculateIntersection();
		},
		'axis_value': function(self,val){
			self.uniforms.axisValue.value = val;
			self.intersectionPlane.updatePosition(val);

			self.CalculateIntersection();
		},
		'render_shape': function(self,val){
			// Toggle opacity
			if(self.current_mode == null) return;

			updateRenderShape(self,val);

		},
		'render_slices': function(self,val){
			// Toggle opacity
			if(self.current_mode == null) return;

			updateRenderSlices(self,val);

		},
		'fill': function(self,val){

			self.CalculateIntersection();
		},
		'source': function(self,val){
			self.setMode();<commit_msg>Fixed bug where changing axis would always turn on cartesian<commit_after>var Mode3D = (function (scope) {
	//Constructor
	function Mode3D(document){
		this.document = document;

		this.animId = null;

		this.leftView = null;
		this.leftCamera = null;
		this.leftRenderer = null;
		this.leftControls = null;
		this.leftMesh = null;

		this.rightView = null;
		this.rightCamera = null;
		this.rightRenderer = null;
		this.rightControls = null;

		this.leftMesh = null;
		this.rightMesh = null;

		this.labels = [];
	}

	// Creates the scene and everything
	Mode3D.prototype.init = function(div,gui){
		// Create two child divs
		var leftCanvas = document.getElementById("left-view").getElementsByTagName("canvas")[0];
		var rightCanvas = document.getElementById("right-view").getElementsByTagName("canvas")[0];

		var viewWidth = (window.innerWidth-50)/2;

		// Init gui
		gui.init("3D",this.callbacks,this);
		this.gui = gui;

		this.leftView = new THREE.Scene();
		this.leftCamera = new THREE.PerspectiveCamera( 75, viewWidth / window.innerHeight, 0.1, 1000 );
		this.leftCamera.position.set(5,10,20);
		this.leftRenderer = new THREE.WebGLRenderer({ canvas: leftCanvas, antialias: true });
		this.leftRenderer.setClearColor(0xffffff);
		this.leftRenderer.setSize( viewWidth, window.innerHeight );

		this.leftControls = new THREE.OrbitControls( this.leftCamera, this.leftRenderer.domElement );
		this.leftControls.enableKeys  = false;

		var GridHelper = new Grid();
		var grid = GridHelper.CreateGrid("XZ");
		this.leftView.add(grid);

		var axis = GridHelper.CreateAxis("X");
		this.leftView.add(axis);
		axis = GridHelper.CreateAxis("Y");
		this.leftView.add(axis);
		axis = GridHelper.CreateAxis("Z");
		this.leftView.add(axis);

		var leftXLabel = GridHelper.CreateLabel("X",12,0,0); this.labels.push(leftXLabel);
		this.leftView.add(leftXLabel);
		var leftYLabel = GridHelper.CreateLabel("Y",0,12,0); this.labels.push(leftYLabel);
		this.leftView.add(leftYLabel);
		var leftZLabel = GridHelper.CreateLabel("Z",0,0,12); this.labels.push(leftZLabel);
		this.leftView.add(leftZLabel);

		this.rightView = new THREE.Scene();
		this.rightCamera = new THREE.PerspectiveCamera( 75, viewWidth / window.innerHeight, 0.1, 1000 );
		this.rightCamera.position.set(0,0,20);
		this.rightRenderer = new THREE.WebGLRenderer({ canvas: rightCanvas, antialias: true });
		this.rightRenderer.setClearColor(0xffffff);
		this.rightRenderer.setSize( viewWidth, window.innerHeight );

		this.rightControls = new THREE.OrbitControls( this.rightCamera, this.rightRenderer.domElement );
		this.rightControls.enableRotate = false;
		this.rightControls.enableKeys  = false;

		grid = GridHelper.CreateGrid("XY");
		this.rightView.add(grid);

		axis = GridHelper.CreateAxis("X");
		this.rightView.add(axis);
		axis = GridHelper.CreateAxis("Y");
		this.rightView.add(axis);

		var rightXLabel = GridHelper.CreateLabel("X",12,0,0);
		this.rightXLabel = rightXLabel;
		this.rightView.add(rightXLabel);
		var rightYLabel = GridHelper.CreateLabel("Z",0,12,0);
		this.rightYLabel = rightYLabel;
		this.rightView.add(rightYLabel);
		// Add lights to the scene
		var lightSky = new THREE.HemisphereLight( 0xffffbb, 0x080820, .7 );
		this.leftView.add( lightSky );
		var lightGround = new THREE.HemisphereLight( 0xffffbb, 0x080820, .4 );
		this.leftView.add( lightGround );
		lightGround.position.y = -5;
		lightGround.position.x = 2;

		this.util = new Util();
		this.projector = new Projecting();
		this.slicer = new Slicing();

		this.intersectionPlane = this.CreateIntersectionPlane();
		this.intersectionPlane.position.y = this.gui.params.axis_value;
		this.leftView.add(this.intersectionPlane);

		this.animate();

		this.setMode();

		}

	Mode3D.prototype.CreateIntersectionPlane = function(){
		var color =  this.gui.colors.slices;

		var v1 = new THREE.Vector3( 10, 0, 10 );
		var v2 = new THREE.Vector3( -10, 0, 10 );
		var v3 = new THREE.Vector3( -10, 0, -10 );
		var v4 = new THREE.Vector3( 10, 0, -10 );

		var geometry = new THREE.Geometry();
		geometry.vertices.push( v1 );
		geometry.vertices.push( v2 );
		geometry.vertices.push( v3 );
		geometry.vertices.push( v4 );
		geometry.faces.push(new THREE.Face3(0,1,2));
		geometry.faces.push(new THREE.Face3(2,3,0));

		var material = new THREE.MeshPhongMaterial( {color: color, flatShading:true, transparent:true, opacity:0.5, side:THREE.DoubleSide} );
		var mesh = new THREE.Mesh( geometry, material );

		mesh.updatePosition = function(val){
			if(this.axis == "Y")
				this.position.y = val;
			if(this.axis == "X")
				this.position.x = val;
			if(this.axis == "Z")
				this.position.z = val;
		}

		mesh.flip = function(newAxis){
			this.rotation.z = 0;
			this.rotation.x = 0;
			this.position.x = 0;
			this.position.y = 0;
			this.position.z = 0;

			if(newAxis == "Y"){
				let label = this.rightXLabel;
				label.ctx.clearRect(0,0,label.canvas.width,label.canvas.height);
				label.ctx.fillText( "X", label.canvas.width/2, label.canvas.height/2);

				label = this.rightYLabel;
				label.ctx.clearRect(0,0,label.canvas.width,label.canvas.height);
				label.ctx.fillText( "Z", label.canvas.width/2, label.canvas.height/2);
			}
			if(newAxis == "X"){
				this.rotation.z = Math.PI/2;

				let label = this.rightXLabel;
				label.ctx.clearRect(0,0,label.canvas.width,label.canvas.height);
				label.ctx.fillText( "Y", label.canvas.width/2, label.canvas.height/2);

				label = this.rightYLabel;
				label.ctx.clearRect(0,0,label.canvas.width,label.canvas.height);
				label.ctx.fillText( "Z", label.canvas.width/2, label.canvas.height/2);
			}
			if(newAxis == "Z"){
				this.rotation.x = Math.PI/2;

				let label = this.rightXLabel;
				label.ctx.clearRect(0,0,label.canvas.width,label.canvas.height);
				label.ctx.fillText( "X", label.canvas.width/2, label.canvas.height/2);

				label = this.rightYLabel;
				label.ctx.clearRect(0,0,label.canvas.width,label.canvas.height);
				label.ctx.fillText( "Y", label.canvas.width/2, label.canvas.height/2);
			}

			this.rightXLabel.material.map.needsUpdate = true;
			this.rightYLabel.material.map.needsUpdate = true;
			this.axis = newAxis;


		}

		mesh.axis = "Y";
		mesh.rightYLabel = this.rightYLabel;
		mesh.rightXLabel = this.rightXLabel;

		return mesh;
	}

	Mode3D.prototype.CalculateIntersection = function(){
		// TODO: Compute and render intersection
	}

	// define a function to be called when each param is updated
	function updateParametricCallback(self,val){
		self.cleanupLeftMesh();
		self.initParametric()
	}

	function updateRenderShape(self,val,opacity_val){
		if(opacity_val === undefined){
			opacity_val = val ? 1 : 0;
		}
		// TODO: Toggle projection visibility
	}

	function updateRenderSlices(self,val,opacity_val){
		if(opacity_val === undefined){
			opacity_val = val ? 1 : 0;
		}
		var params = self.gui.params;
		var source = params.source;

		// TODO: Toggle making the slices hidden
	}

	Mode3D.prototype.callbacks = {
		'axis': function(self,val) {

			if(self.current_mode == "cartesian"){
				self.cleanupLeftMesh();
				self.initCartesian();
			}
			

			self.intersectionPlane.flip(val);

			self.CalculateIntersection();
		},
		'axis_value': function(self,val){
			self.uniforms.axisValue.value = val;
			self.intersectionPlane.updatePosition(val);

			self.CalculateIntersection();
		},
		'render_shape': function(self,val){
			// Toggle opacity
			if(self.current_mode == null) return;

			updateRenderShape(self,val);

		},
		'render_slices': function(self,val){
			// Toggle opacity
			if(self.current_mode == null) return;

			updateRenderSlices(self,val);

		},
		'fill': function(self,val){

			self.CalculateIntersection();
		},
		'source': function(self,val){
			self.setMode();
{'fraction_non_alphanumeric': 0.14778807255644003, 'fraction_numerical': 0.020357562312410284, 'mean_word_length': 4.021952817824378, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3765448', 'n_tokens_mistral': 6104, 'n_tokens_neox': 5278, 'n_words': 944}