<commit_before>/*global THREE */ 
/*global assert */
/*global $ */
/*global jQuery */

var BEZIER = BEZIER || {};
BEZIER.widgets = BEZIER.widgets  || {};


///////////////////////
//3D Visualizer Class
//main interface to THREE.js
///////////////////////

BEZIER.widgets.visualizer_3d = function (curve_storage, width, height, stage_factory) {
	//FIXME: constructor is getting a little long.  Consider adding some setters and making some sensible defaults
	//it is also getting tougher to understand the constructor since a lot of the arguments are simple integers
	
	if (!curve_storage) {
		throw BEZIER.errors.illegal_argument_error("curve_storage cannot be null");
	}
	
	var num_points = 100;
	stage_factory = stage_factory || BEZIER.widgets.stage_basic;
	var curve_factory = BEZIER.widgets.render_solid_tube;
	
	
	var curves = {};
	var default_options = {points_visible:  true,
						   polygon_visible: true,
						   curve_visible:   true};
	
	
	
	var stage = stage_factory(width || 500, height || 500);	
	var scene = stage.make_scene();
	
	
	var render_trigger = false;
	function render() {
		stage.renderer.render(scene, stage.camera);
		render_trigger = true;
	}
		
	function set_visible(threeobj, value) {
		threeobj.traverse(function (o) {
			o.visible = value;
		});
	}
	
	var that = {
		/////////POINTS//////////
		get_num_points: function () {
			return num_points;
		},

		set_num_points: function (num) {
			num_points = num;
		},
	
		////////RENDERING////////////
		
		set_curve_factory: function (_curve_factory) {
			curve_factory  = _curve_factory || curve_factory;
		},
				
		update: function () {
			render_trigger = false;
			stage.camera_controls.update();
			
			if (!render_trigger) {
				render();
			}
		},
		
		////////RENDERING OPTIONS////////////
		get_view: function () {
			var target = stage.camera_controls.target;
			var position = stage.camera_controls.object.position;
			//copying the positions protects them from outside modification
			return {"target": BEZIER.core.dim3(target.x, target.y, target.z),
				    "position": BEZIER.core.dim3(position.x, position.y, position.z)};
		},
		
		set_view: function (target, position) {
			
			if (!target) {
				throw BEZIER.errors.illegal_argument_error("Target cannot be null.");
			}
			
			//copying the positions protects them from outside modification
			stage.camera_controls.target = new THREE.Vector3(target.x, target.y, target.z);
			if (position) {
				stage.camera_controls.object.position = new THREE.Vector3(position.x, position.y, position.z);
			}
			
			this.update();
		},
		

		
		set_points_visibility: function (curve_name, is_visible) {
			var curve_info = curves[curve_name];
			if (!curve_info) {
				return;
			}
			var options = curve_info.options;			

			if(is_visible !== null){
				options.points_visible = Boolean(is_visible);
				set_visible(curve_info.meshes.control_points, options.points_visible);				
			}
		},

		set_polygon_visibility: function (curve_name, is_visible) {
			var curve_info = curves[curve_name];
			if (!curve_info) {
				return;
			}
			var options = curve_info.options;			

			if(is_visible !== null){
				options.polygon_visible = Boolean(is_visible);
				set_visible(curve_info.meshes.control_polygon, options.polygon_visible);				
			}
		},
		set_curve_visibility: function (curve_name, is_visible) {
			var curve_info = curves[curve_name];
			if (!curve_info) {
				return;
			}
			var options = curve_info.options;			

			if(is_visible !== null){
				options.curve_visible = Boolean(is_visible);
				set_visible(curve_info.meshes.curve, options.curve_visible);
			}
		},		
		
		//////////DOM Manipulaion/////////////////////
		get_dom_element: function () {
			return stage.renderer.domElement;<commit_msg>visualizer visibility API re-worked to make more sense.<commit_after>/*global THREE */ 
/*global assert */
/*global $ */
/*global jQuery */

var BEZIER = BEZIER || {};
BEZIER.widgets = BEZIER.widgets  || {};


///////////////////////
//3D Visualizer Class
//main interface to THREE.js
///////////////////////

BEZIER.widgets.visualizer_3d = function (curve_storage, width, height, stage_factory) {
	//FIXME: constructor is getting a little long.  Consider adding some setters and making some sensible defaults
	//it is also getting tougher to understand the constructor since a lot of the arguments are simple integers
	
	if (!curve_storage) {
		throw BEZIER.errors.illegal_argument_error("curve_storage cannot be null");
	}
	
	var num_points = 100;
	stage_factory = stage_factory || BEZIER.widgets.stage_basic;
	var curve_factory = BEZIER.widgets.render_solid_tube;
	
	
	var curves = {};
	var default_options = {points_visible:  true,
						   polygon_visible: true,
						   curve_visible:   true};
	
	
	
	var stage = stage_factory(width || 500, height || 500);	
	var scene = stage.make_scene();
	
	
	var render_trigger = false;
	function render() {
		stage.renderer.render(scene, stage.camera);
		render_trigger = true;
	}
		
	function set_visible(threeobj, value) {
		threeobj.traverse(function (o) {
			o.visible = value;
		});
	}
	
	var that = {
		/////////POINTS//////////
		get_num_points: function () {
			return num_points;
		},

		set_num_points: function (num) {
			num_points = num;
		},
	
		////////RENDERING////////////
		
		set_curve_factory: function (_curve_factory) {
			curve_factory  = _curve_factory || curve_factory;
		},
				
		update: function () {
			render_trigger = false;
			stage.camera_controls.update();
			
			if (!render_trigger) {
				render();
			}
		},
		
		////////RENDERING OPTIONS////////////
		get_view: function () {
			var target = stage.camera_controls.target;
			var position = stage.camera_controls.object.position;
			//copying the positions protects them from outside modification
			return {"target": BEZIER.core.dim3(target.x, target.y, target.z),
				    "position": BEZIER.core.dim3(position.x, position.y, position.z)};
		},
		
		set_view: function (target, position) {
			
			if (!target) {
				throw BEZIER.errors.illegal_argument_error("Target cannot be null.");
			}
			
			//copying the positions protects them from outside modification
			stage.camera_controls.target = new THREE.Vector3(target.x, target.y, target.z);
			if (position) {
				stage.camera_controls.object.position = new THREE.Vector3(position.x, position.y, position.z);
			}
			
			this.update();
		},
		

		
		set_points_visibility: function (curve_name, is_visible) {
			var curve_info = curves[curve_name];
			if (!curve_info) {
				return;
			}
			var options = curve_info.options;			

			if (is_visible !== null) {
				options.points_visible = Boolean(is_visible);
				set_visible(curve_info.meshes.control_points, options.points_visible);				
			}
		},

		set_polygon_visibility: function (curve_name, is_visible) {
			var curve_info = curves[curve_name];
			if (!curve_info) {
				return;
			}
			var options = curve_info.options;			

			if (is_visible !== null) {
				options.polygon_visible = Boolean(is_visible);
				set_visible(curve_info.meshes.control_polygon, options.polygon_visible);				
			}
		},
		set_curve_visibility: function (curve_name, is_visible) {
			var curve_info = curves[curve_name];
			if (!curve_info) {
				return;
			}
			var options = curve_info.options;			

			if (is_visible !== null) {
				options.curve_visible = Boolean(is_visible);
				set_visible(curve_info.meshes.curve, options.curve_visible);
			}
		},		
		
		//////////DOM Manipulaion/////////////////////
		get_dom_element: function () {
			return stage.renderer.domElement;
{'fraction_non_alphanumeric': 0.14444738934534854, 'fraction_numerical': 0.003975616220514179, 'mean_word_length': 2.9721052631578946, 'pattern_counts': {'":': 4, '<': 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': '3275840', 'n_tokens_mistral': 2914, 'n_tokens_neox': 2338, 'n_words': 531}