<commit_before>/*
  Made of one main arrow, and two lines perpendicular to the main arrow, at both its ends
  
  Two step interactive version : 
    - place center
    - place diameter
*/
DiameterHelper = function(options)
{
  BaseHelper.call( this );
  var options = options || {};

  this.distance = options.distance || 30;
  this.diameter = options.diameter || 10;
  this.endLength = options.endLength || 20;
  this.color = options.color || "#000000" ;
  
  this._position= options.position !== undefined ? options.position : new THREE.Vector3();
  this.orientation = 
  
  this.fontSize   = options.fontSize!== undefined ? options.fontSize : 10;
  this.textBgColor= options.textBgColor!== undefined ? options.textBgColor : "#fff";
  this.labelPos   = options.labelPos!== undefined ? options.labelPos : "center";
  this.labelType  = options.labelType!== undefined ? options.labelType : "flat";
  
  this.text   = options.text !== undefined ? options.text : this.diameter.toFixed(2);
  
  this.lineMaterial = new THREE.LineBasicMaterial( { color: 0x000000, depthTest:false, depthWrite:false,renderDepth : 1e20});
 
}

DiameterHelper.prototype = Object.create( BaseHelper.prototype );
DiameterHelper.prototype.constructor = DiameterHelper;

DiameterHelper.prototype.set = function(){
  this.setCenter();
  this.setDiameter();
}

DiameterHelper.prototype.unset = function(){
  this.remove( this.centerCross );
  this.remove( this.diaCircle );
  this.remove( this.leaderLine );
}

DiameterHelper.prototype.setCenter = function(centerPosition){
  if(centerPosition)  this.position.copy( centerPosition );
  if(this.centerCross) this.remove( this.centerCross );
   //center cross
  this.centerCross = new CrossHelper({size:this.centerCrossSize});
  this.add( this.centerCross );
}

DiameterHelper.prototype.setDiameter = function(diameter){
  if(!diameter && ! this.diameter){ 
    return
  }  
  this.diameter = diameter;
  this.text     = this.diameter.toFixed(2);
  
  this.drawCircle();
  this.drawLeaderLine();
}

DiameterHelper.prototype.setRadius = function(radius){
  if(!radius && ! this.diameter){ 
    return
  }  
  this.diameter = radius*2;
  this.text     = this.diameter.toFixed(2);
  
  this.drawCircle();
  this.drawLeaderLine();
}

DiameterHelper.prototype.setRadiusPoint = function(point){
  
  var radius = point.clone().sub( this.position ).length();
  //var plane = new THREE.Plane().setFromCoplanarPoints( this.end, this.mid, this.start );
  this.diameter = radius*2;
  this.text     = this.diameter.toFixed(2);
  
  this.drawCircle();
  this.drawLeaderLine();
}


DiameterHelper.prototype.drawCircle = function(){
  //draw main circle
  var circleRadius = this.diameter/2;
  var circleShape = new THREE.Shape();
	circleShape.moveTo( 0, 0 );
	circleShape.absarc( 0, 0, circleRadius, 0, Math.PI*2, false );
  var points  = circleShape.createSpacedPointsGeometry( 100 );
  this.diaCircle = new THREE.Line(points, this.lineMaterial );
  
  if(this.diaCircle) this.remove( this.diaCircle );
  this.add( this.diaCircle );
}

DiameterHelper.prototype.drawLeaderLine = function(){
  //leader line
  this.leaderLine = new LeaderLineHelper({text:"∅"+this.text,radius:this.diameter/2,
  fontSize:this.fontSize,textBgColor:this.textBgColor});<commit_msg>- added orientation support / setter<commit_after>/*
  Made of one main arrow, and two lines perpendicular to the main arrow, at both its ends
  
  Two step interactive version : 
    - place center
    - place diameter
*/
DiameterHelper = function(options)
{
  BaseHelper.call( this );
  var options = options || {};

  this.distance = options.distance || 30;
  this.diameter = options.diameter || 10;
  this.endLength = options.endLength || 20;
  this.color = options.color || "#000000" ;
  
  this._position   = options.position !== undefined ? options.position : new THREE.Vector3();
  this.orientation = options.orientation !== undefined ? options.orientation : new THREE.Vector3();
  
  this.fontSize   = options.fontSize!== undefined ? options.fontSize : 10;
  this.textBgColor= options.textBgColor!== undefined ? options.textBgColor : "#fff";
  this.labelPos   = options.labelPos!== undefined ? options.labelPos : "center";
  this.labelType  = options.labelType!== undefined ? options.labelType : "flat";
  
  this.text   = options.text !== undefined ? options.text : this.diameter.toFixed(2);
  
  this.lineMaterial = new THREE.LineBasicMaterial( { color: 0x000000, depthTest:false, depthWrite:false,renderDepth : 1e20});
 
}

DiameterHelper.prototype = Object.create( BaseHelper.prototype );
DiameterHelper.prototype.constructor = DiameterHelper;

DiameterHelper.prototype.set = function(){
  this.setCenter();
  this.setDiameter();
}

DiameterHelper.prototype.unset = function(){
  this.remove( this.centerCross );
  this.remove( this.diaCircle );
  this.remove( this.leaderLine );
}

DiameterHelper.prototype.setCenter = function(centerPosition){
  if(centerPosition)  this.position.copy( centerPosition );
  if(this.centerCross) this.remove( this.centerCross );
   //center cross
  this.centerCross = new CrossHelper({size:this.centerCrossSize});
  this.add( this.centerCross );
}

DiameterHelper.prototype.setDiameter = function(diameter){
  if(!diameter && ! this.diameter){ 
    return
  }  
  this.diameter = diameter;
  this.text     = this.diameter.toFixed(2);
  
  this.drawCircle();
  this.drawLeaderLine();
}

DiameterHelper.prototype.setRadius = function(radius){
  if(!radius && ! this.diameter){ 
    return
  }  
  this.diameter = radius*2;
  this.text     = this.diameter.toFixed(2);
  
  this.drawCircle();
  this.drawLeaderLine();
}

DiameterHelper.prototype.setOrientation = function(orientation){
  this.orientation = orientation;
  console.log("this.orientation",this.orientation);
  
  var defaultOrientation = new THREE.Vector3(0,0,1); 
  var quaternion = new THREE.Quaternion();
  quaternion.setFromUnitVectors ( defaultOrientation, this.orientation.clone() );
  this.rotation.setFromQuaternion( quaternion );
}

/*Allows setting the radius/diameter from a 3d point

*/
DiameterHelper.prototype.setRadiusPoint = function(point, normal){
  
  var radius = point.clone().sub( this.position ).length();
  //var plane = new THREE.Plane().setFromCoplanarPoints( this.end, this.mid, this.start );
  this.diameter = radius*2;
  this.text     = this.diameter.toFixed(2);
  
  this.drawCircle();
  this.drawLeaderLine();
}


DiameterHelper.prototype.drawCircle = function(){
  //draw main circle
  var circleRadius = this.diameter/2;
  var circleShape = new THREE.Shape();
	circleShape.moveTo( 0, 0 );
	circleShape.absarc( 0, 0, circleRadius, 0, Math.PI*2, false );
  var points  = circleShape.createSpacedPointsGeometry( 100 );
  this.diaCircle = new THREE.Line(points, this.lineMaterial );
  
  if(this.diaCircle) this.remove( this.diaCircle );
  this.add( this.diaCircle );
}

DiameterHelper.prototype.drawLeaderLine = function(){
  //leader line
  this.leaderLine = new LeaderLineHelper({text:"∅"+this.text,radius:this.diameter/2,
  fontSize:this.fontSize,textBgColor:this.textBgColor});
{'fraction_non_alphanumeric': 0.1344632768361582, 'fraction_numerical': 0.012711864406779662, 'mean_word_length': 4.272524199553239, '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': '3716694', 'n_tokens_mistral': 2416, 'n_tokens_neox': 2224, 'n_words': 439}