<commit_before>var TerrainGen = function(){

    var self = this;
    
    this.origin = new THREE.Vector2( 0, 0 );
    
    this.material = new THREE.MeshBasicMaterial({
            color : 0xffffff,
            opacity : 0.75,
            transparent : true,
            wireframe : true,
            side: THREE.BackSide,
            shading: THREE.FlatShading
        });
    
    this.generate = function(  bbox, x_step, z_step,  callback, scene ){
             
         var min,
            max,
            geometry;
            
        // Get the origin XY coordinates
        self.origin = self.lonLatToScene(bbox[0], bbox[1]);
            
        // Get the bounds XY coordinates    
        min = self.lonLatToScene(bbox[0], bbox[1]);
        max = self.lonLatToScene(bbox[2], bbox[3]);

        geometry = new THREE.PlaneGeometry(max.x, max.y, x_step, z_step);
        
        // Add plane
        plane = new THREE.Mesh( geometry,  this.material );
        plane.visible = true;
        plane.position.x = -max.y/2;
        plane.position.z = -max.x /2;
        plane.rotation.x = -Math.PI / 2;
        plane.rotation.z= -Math.PI / 2;
        
        self.set_Elevations( plane, scene, callback );
    }
    
    //  ******************** Helpers ********************
    
    // Calls the elevation API to get heights of terrain vertices, sets them and adds the object to the scene
    this.set_Elevations = function( plane, scene, callback ){

        var vertex_latLons = [];  

        // Convert all geometry vertices to longitude and latitude
        for (var i = 0; i < plane.geometry.vertices.length; i++) { 
            var lonLat = self.sceneToLonLat(plane.geometry.vertices[i]);
            vertex_latLons.push(lonLat[1],lonLat[0]);
        }
         
         // Call elevation API via sinatra app, modify mesh when heights are returned
         // FIXME: There are currently limits to the # of elevation points returned.
         // Figure out why/develop a workaround.

         $.when(  $.ajax('/elevation',{
            'data': JSON.stringify({latLngCollection: vertex_latLons.join(",")}), //{action:'x',params:['a','b','c']}
            'type': 'POST',
            'processData': false,
            'contentType': 'application/json' 
            }) )
        .then(function( data, textStatus, jqXHR ) {
            elevationJSON = JSON.parse(data);
            console.log(elevationJSON);
            
            for (var i = 0; i < plane.geometry.vertices.length; i++) { 
                var elevation = elevationJSON[i];
                plane.geometry.vertices[i].setZ(elevation);
            }
            
            scene.add(plane);
            
            // Cleanup
            self.origin = new THREE.Vector2( 0, 0 );
            callback.call();
        });
        
    }
    
     // Vector2 is transformed by origin and passed to worldToLonLat
    this.sceneToLonLat = function( vector ) {
        var world_vector = new THREE.Vector2( vector.x + self.origin.x,  vector.y + self.origin.y );
        var lonLat = self.worldToLonLat( world_vector )
        return lonLat<commit_msg>tweaked terraingen<commit_after>var TerrainGen = function(){

    var self = this;
    
    this.origin = new THREE.Vector2( 0, 0 );
    
    this.material = new THREE.MeshBasicMaterial({
            color : 0xffffff,
            opacity : 0.75,
            transparent : true,
            wireframe : true,
            side: THREE.BackSide,
            shading: THREE.FlatShading
        });
    
    this.generate = function(  bbox, x_step, z_step,  callback, scene ){
             
         var min,
            max,
            geometry;
            
        // Get the origin XY coordinates
        self.origin = self.lonLatToScene(bbox[0], bbox[1]);
            
        // Get the bounds XY coordinates    
        min = self.lonLatToScene(bbox[0], bbox[1]);
        max = self.lonLatToScene(bbox[2], bbox[3]);

        geometry = new THREE.PlaneGeometry(max.x, max.y, x_step, z_step);
        
        // Add plane
        plane = new THREE.Mesh( geometry,  this.material );
        plane.visible = true;
        plane.position.x = -max.y/2;
        plane.position.z = -max.x /2;
        plane.rotation.x = -Math.PI / 2;
        plane.rotation.z= -Math.PI / 2;
        
        self.set_Elevations( plane, scene, callback );
    }
    
    //  ******************** Helpers ********************
    
    // Calls the elevation API to get heights of terrain vertices, sets them and adds the object to the scene
    this.set_Elevations = function( plane, scene, callback ){

        var vertex_latLons = [];  

        // Convert all geometry vertices to longitude and latitude
        for (var i = 0; i < plane.geometry.vertices.length; i++) { 
            var lonLat = self.sceneToLonLat(plane.geometry.vertices[i]);
            vertex_latLons.push(lonLat[1],lonLat[0]);
        }
         
         // Call elevation API via sinatra app, modify mesh when heights are returned
         $.when(  $.ajax('/elevation',{
            'data': JSON.stringify({latLngCollection: vertex_latLons.join(",")}), //{action:'x',params:['a','b','c']}
            'type': 'POST',
            'processData': false,
            'contentType': 'application/json' 
            }) )
        .then(function( data, textStatus, jqXHR ) {
            elevationJSON = JSON.parse(data);
            
            for (var i = 0; i < plane.geometry.vertices.length; i++) { 
                var elevation = elevationJSON[i];
                plane.geometry.vertices[i].setZ(elevation);
            }
            
            scene.add(plane);
            
            // Cleanup
            self.origin = new THREE.Vector2( 0, 0 );
            callback.call();
        });
        
    }
    
     // Vector2 is transformed by origin and passed to worldToLonLat
    this.sceneToLonLat = function( vector ) {
        var world_vector = new THREE.Vector2( vector.x + self.origin.x,  vector.y + self.origin.y );
        var lonLat = self.worldToLonLat( world_vector )
        return lonLat
{'fraction_non_alphanumeric': 0.12754432042022323, 'fraction_numerical': 0.008535784635587657, 'mean_word_length': 1.709204090706981, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2456723', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1744, 'n_words': 431}