<commit_before>#include <iostream>
#include <GL/glut.h>

#include "map.h"
#include "data.h"
#include "time_code.c"

using namespace std;

Data Map::data;

Map::Map(unsigned int label, int pos_x, int pos_y, int width, int height, int low_res) : Viewport(label, pos_x, pos_y, width, height){
    while(!_window_index); // wait until window is initialised.
    _task_list.clear();
    _task_list_low_res.clear();
    _low_res = low_res;
    windows[_window_index].low_res = low_res;
    windows[_window_index]._p_data_points_low_res = &_data_points_low_res;
    windows[_window_index]._p_data_colour_low_res = &_data_colour_low_res;
    
    vessels.StartIcon();
    Icon icon;
    icon.scale = 0;
    icon.key = 1;
    while(icon.key != 0){
        icon = vessels.NextIcon(0,0,MAX_SIZE,MAX_SIZE);
        if(icon.scale){
            Icon_key key;
            key.type = ICON_TYPE_VESSEL;
            key.key = icon.key;
            AddIcon(key, icon);
        }
    }
};

void Map::Draw(void){
    while(!windows[_window_index].window);  // wait until window is initialised.
    cout << flush << "Map::Draw " << _window_index << " " << _width << "," << _height << "\n" << flush;
    timestamp_t t0 = get_timestamp();

    Clear();

    DrawSection(0.0f, 0.0f, 1.0f, 1.0f, 1);

    timestamp_t t1 = get_timestamp();
    cout << "Map::Draw took " << (double)(t1 - t0) / 1000000.0L << " seconds.\n";
}

int Map::DrawSection(Task* p_task, int resolution){
    float _zoom_holder = _zoom;
    float _view_x_holder = _view_x;
    float _view_y_holder = _view_y;
    _zoom = p_task->zoom;
    _view_x = p_task->view_x;
    _view_y = p_task->view_y;

    int retval = DrawSection(p_task->x0, p_task->y0, p_task->x1, p_task->y1, resolution, &(p_task->progress_x), &(p_task->progress_y));

    _zoom = _zoom_holder;
    _view_x = _view_x_holder;
    _view_y = _view_y_holder;

    return retval;
}

int Map::DrawSection(float x0, float y0, float x1, float y1, int resolution, unsigned int* p_progress_x, unsigned int* p_progress_y){
    std::vector<GLfloat>* _p_data_points;
    std::vector<GLubyte>* _p_data_colour;
    if(resolution == _low_res){
        _p_data_points = &_data_points_low_res;
        _p_data_colour = &_data_colour_low_res;
    } else {
        _p_data_points = &_data_points;
        _p_data_colour = &_data_colour;
    }

    /* step size will always be a power of 2.
     * This is important to ensure the display pixels coincide with the data structure recursion levels
     * which means un-necesary recursion through the datastructure need not occur. */
    int step_x = MAX_SIZE / (int)pow(2, (int)log2(_width * _zoom));
    int step_y = MAX_SIZE / (int)pow(2, (int)log2(_height * _zoom));
    step_x *= resolution;
    step_y *= resolution;

    /* The (min_y % step_y) part ensures the display is alligned with the datastructure, preventing un-necesary recursion. */
    int min_x = ((0.5f - _view_x) * MAX_SIZE) - (((0.5f - x0) / _zoom) * MAX_SIZE);
    int min_y = ((0.5f - _view_y) * MAX_SIZE) - (((0.5f - y0) / _zoom) * MAX_SIZE);
    min_x = min_x - (min_x % step_x);
    min_y = min_y - (min_y % step_y);
    if( min_x < 0)
         min_x = 0;
    if( min_y < 0)
        min_y = 0;
    unsigned int max_x = ((0.5f - _view_x) * MAX_SIZE) - (((0.5f - x1) / _zoom) * MAX_SIZE);
    unsigned int max_y = ((0.5f - _view_y) * MAX_SIZE) - (((0.5f - y1) / _zoom) * MAX_SIZE);

    /* special case to guard against a bug that occurs when x0==0 and x1==0 */
    if(min_x == 0 and max_x > (unsigned int)MAX_SIZE and _zoom != 1.0f)
        return 0;
    if(min_y == 0 and max_y > (unsigned int)MAX_SIZE and _zoom != 1.0f)
        return 0;

    if (max_x > (unsigned int)MAX_SIZE)
        max_x = MAX_SIZE;
    if (max_y > (unsigned int)MAX_SIZE)
        max_y = MAX_SIZE;

    float z_multiplier_dry = 255.0f / (data.Height_z_max() - data.Waterlevel());

    MapPoint tl, tr, bl, br;

    cout << "min_x: " << min_x << "\tmax_x: " << max_x << "\tmin_y: " << min_y << "\tmax_y: " << max_y << "\n";
    cout << "step_x: " << step_x << "\tstep_y: " << step_y << "\n";
    cout << "y0: " << y0 << "\ty1: " << y1 << "\n";
    for(unsigned int row = min_y; row < max_y; row+=step_y){
        if(p_progress_y and *p_progress_y > row){
            continue;
        }
        //if(TestInterupt(SIG_DEST_MAP)){
        //    cout << "INTERUPT!!\n";
        //        if(p_progress_y)
        //            *p_progress_y = row;
        //        return 1;
        //}
        for(unsigned int col = min_x; col < max_x; col+=step_x){
            if(p_progress_x and p_progress_y and *p_progress_x > col and *p_progress_y > row){
                continue;
            }
            int retval = TestInterupt(SIG_DEST_MAP);
            if(retval){
                cout << "INTERUPT!! " << retval << "\n";
                if(p_progress_x)
                    *p_progress_x = col;
                if(p_progress_y)
                    *p_progress_y = row;
                return retval;
            }

            //cout << col << "," << row << "\n" << flush;
            tl.x = col;<commit_msg>Update map.cpp<commit_after>#include <iostream>
#include <GL/glut.h>

#include "map.h"
#include "data.h"
#include "time_code.c"

using namespace std;

Data Map::data;

Map::Map(unsigned int label, int pos_x, int pos_y, int width, int height, int low_res) : Viewport(label, pos_x, pos_y, width, height){
    while(!_window_index); // wait until window is initialised.
    _task_list.clear();
    _task_list_low_res.clear();
    _low_res = low_res;
    windows[_window_index].low_res = low_res;
    windows[_window_index]._p_data_points_low_res = &_data_points_low_res;
    windows[_window_index]._p_data_colour_low_res = &_data_colour_low_res;
    
    vessels.StartIcon();
    Icon icon;
    icon.scale = 0;
    icon.key = 1;
    while(icon.key != 0){
        icon = vessels.NextIcon(0,0,MAX_SIZE,MAX_SIZE);
        if(icon.scale){
            Icon_key key;
            key.type = ICON_TYPE_VESSEL;
            key.key = icon.key;
            AddIcon(key, icon);
        }
    }
};

void Map::Draw(void){
    while(!windows[_window_index].window);  // wait until window is initialised.
    cout << flush << "Map::Draw " << _window_index << " " << _width << "," << _height << "\n" << flush;
    timestamp_t t0 = get_timestamp();

    Clear();

    DrawSection(0.0f, 0.0f, 1.0f, 1.0f, 1);

    timestamp_t t1 = get_timestamp();
    cout << "Map::Draw took " << (double)(t1 - t0) / 1000000.0L << " seconds.\n";
}

int Map::DrawSection(Task* p_task, int resolution){
    float _zoom_holder = _zoom;
    float _view_x_holder = _view_x;
    float _view_y_holder = _view_y;
    _zoom = p_task->zoom;
    _view_x = p_task->view_x;
    _view_y = p_task->view_y;

    int retval = DrawSection(p_task->x0, p_task->y0, p_task->x1, p_task->y1, resolution, &(p_task->progress_x), &(p_task->progress_y));

    _zoom = _zoom_holder;
    _view_x = _view_x_holder;
    _view_y = _view_y_holder;

    return retval;
}

int Map::DrawSection(float x0, float y0, float x1, float y1, int resolution, unsigned int* p_progress_x, unsigned int* p_progress_y){
    std::vector<GLfloat>* _p_data_points;
    std::vector<GLubyte>* _p_data_colour;
    if(resolution == _low_res){
        _p_data_points = &_data_points_low_res;
        _p_data_colour = &_data_colour_low_res;
    } else {
        _p_data_points = &_data_points;
        _p_data_colour = &_data_colour;
    }

    /* step size will always be a power of 2.
     * This is important to ensure the display pixels coincide with the data structure recursion levels
     * which means un-necesary recursion through the datastructure need not occur. */
    int step_x = MAX_SIZE / (int)pow(2, (int)log2(_width * _zoom));
    int step_y = MAX_SIZE / (int)pow(2, (int)log2(_height * _zoom));
    step_x *= resolution;
    step_y *= resolution;

    /* The (min_y % step_y) part ensures the display is alligned with the datastructure, preventing un-necesary recursion. */
    int min_x = ((0.5f - _view_x) * MAX_SIZE) - (((0.5f - x0) / _zoom) * MAX_SIZE);
    int min_y = ((0.5f - _view_y) * MAX_SIZE) - (((0.5f - y0) / _zoom) * MAX_SIZE);
    min_x = min_x - (min_x % step_x);
    min_y = min_y - (min_y % step_y);
    if( min_x < 0)
         min_x = 0;
    if( min_y < 0)
        min_y = 0;
    unsigned int max_x = ((0.5f - _view_x) * MAX_SIZE) - (((0.5f - x1) / _zoom) * MAX_SIZE);
    unsigned int max_y = ((0.5f - _view_y) * MAX_SIZE) - (((0.5f - y1) / _zoom) * MAX_SIZE);

    /* special case to guard against a bug that occurs when x0==0 and x1==0 */
    if(min_x == 0 and max_x > (unsigned int)MAX_SIZE and _zoom != 1.0f)
        return 0;
    if(min_y == 0 and max_y > (unsigned int)MAX_SIZE and _zoom != 1.0f)
        return 0;
    if(min_x > max_x or min_y > max_y)
        return 0;
        
    if (max_x > (unsigned int)MAX_SIZE)
        max_x = MAX_SIZE;
    if (max_y > (unsigned int)MAX_SIZE)
        max_y = MAX_SIZE;

    float z_multiplier_dry = 255.0f / (data.Height_z_max() - data.Waterlevel());

    MapPoint tl, tr, bl, br;

    cout << "min_x: " << min_x << "\tmax_x: " << max_x << "\tmin_y: " << min_y << "\tmax_y: " << max_y << "\n";
    cout << "step_x: " << step_x << "\tstep_y: " << step_y << "\n";
    cout << "y0: " << y0 << "\ty1: " << y1 << "\n";
    for(unsigned int row = min_y; row < max_y; row+=step_y){
        if(p_progress_y and *p_progress_y > row){
            continue;
        }
        if(_p_data_points->size() > 4000000){
          cout << "RUNAWAY!\n";
          return 0;
        }
        //if(TestInterupt(SIG_DEST_MAP)){
        //    cout << "INTERUPT!!\n";
        //        if(p_progress_y)
        //            *p_progress_y = row;
        //        return 1;
        //}
        for(unsigned int col = min_x; col < max_x; col+=step_x){
            if(p_progress_x and p_progress_y and *p_progress_x > col and *p_progress_y > row){
                continue;
            }
            int retval = TestInterupt(SIG_DEST_MAP);
            if(retval){
                cout << "INTERUPT!! " << retval << "\n";
                if(p_progress_x)
                    *p_progress_x = col;
                if(p_progress_y)
                    *p_progress_y = row;
                return retval;
            }

            //cout << col << "," << row << "\n" << flush;
            tl.x = col;
{'fraction_non_alphanumeric': 0.14394670785865998, 'fraction_numerical': 0.01708824097316084, 'mean_word_length': 2.4019704433497537, 'pattern_counts': {'":': 0, '<': 181, '<?xml version=': 0, '>': 47, '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': '5534797', 'n_tokens_mistral': 3945, 'n_tokens_neox': 3827, 'n_words': 879}