<commit_before>



/*
	========================================================================
	The /r/place Atlas
	
	An Atlas of Reddit's /r/place, with information to each
	artwork	of the canvas provided by the community.
	
	Copyright (C) 2017 <NAME> <<EMAIL>>
	Licensed under the GNU Affero General Public License Version 3
	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU Affero General Public License as
	published by the Free Software Foundation, either version 3 of the
	License, or (at your option) any later version.
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	For more information, see:
	https://draemm.li/various/place-atlas/license.txt
	
	========================================================================
*/


function initDraw(){

	var finishButton = document.getElementById("finishButton");
	var resetButton = document.getElementById("resetButton");
	var undoButton = document.getElementById("undoButton");
	var redoButton = document.getElementById("redoButton");
	
	var objectInfoBox = document.getElementById("objectInfo");
	var hintText = document.getElementById("hint");
	
	var exportButton = document.getElementById("exportButton");
	var cancelButton = document.getElementById("cancelButton");

	var exportOverlay = document.getElementById("exportOverlay");
	var exportCloseButton = document.getElementById("exportCloseButton");

	container.style.cursor = "crosshair";
	
	var path = [];
	var drawing = true;

	var undoHistory = [];

	var lastPos = [0, 0];

	render(path);

	container.addEventListener("mousedown", function(e){
		lastPos = [
			 e.clientX
			,e.clientY
		];
	});

	container.addEventListener("mouseup", function(e){
		if(Math.abs(lastPos[0] - e.clientX) + Math.abs(lastPos[1] - e.clientY) <= 4 && drawing){
			path.push([
				 ~~((e.clientX - (container.clientWidth/2 - innerContainer.clientWidth/2 + zoomOrigin[0]))/zoom)+0.5
				,~~((e.clientY - (container.clientHeight/2 - innerContainer.clientHeight/2 + zoomOrigin[1]))/zoom)+0.5
			]);
			render(path);
			
			undoHistory = [];
			redoButton.disabled = true;
			undoButton.disabled = false;
			
			if(path.length >= 3){
				finishButton.disabled = false;
			}
		}
	});

	window.addEventListener("mousemove", function(e){
		if(!dragging && drawing){
			var last = [
				 ~~((e.clientX - (container.clientWidth/2 - innerContainer.clientWidth/2 + zoomOrigin[0]))/zoom)+0.5
				,~~((e.clientY - (container.clientHeight/2 - innerContainer.clientHeight/2 + zoomOrigin[1]))/zoom)+0.5
			];
			render(path.concat([last]));
		}
	});

	window.addEventListener("keyup", function(e){
		if(e.key == "Enter"){
			finish();
		} else if(e.key == "z" && e.ctrlKey){
			undo();
		} else if(e.key == "y" && e.ctrlKey){
			redo();
		} else if(e.key == "Escape"){
			exportOverlay.style.display = "none";
		}
	});<commit_msg>using shift key to lock lines at vertical / horizontal<commit_after>



/*
	========================================================================
	The /r/place Atlas
	
	An Atlas of Reddit's /r/place, with information to each
	artwork	of the canvas provided by the community.
	
	Copyright (C) 2017 <NAME> <<EMAIL>>
	Licensed under the GNU Affero General Public License Version 3
	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU Affero General Public License as
	published by the Free Software Foundation, either version 3 of the
	License, or (at your option) any later version.
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	For more information, see:
	https://draemm.li/various/place-atlas/license.txt
	
	========================================================================
*/


function initDraw(){

	var finishButton = document.getElementById("finishButton");
	var resetButton = document.getElementById("resetButton");
	var undoButton = document.getElementById("undoButton");
	var redoButton = document.getElementById("redoButton");
	
	var objectInfoBox = document.getElementById("objectInfo");
	var hintText = document.getElementById("hint");
	
	var exportButton = document.getElementById("exportButton");
	var cancelButton = document.getElementById("cancelButton");

	var exportOverlay = document.getElementById("exportOverlay");
	var exportCloseButton = document.getElementById("exportCloseButton");

	container.style.cursor = "crosshair";
	
	var path = [];
	var drawing = true;

	var undoHistory = [];
  var _global_key_status = {"L_SHIFT":0, "R_SHIFT":0, buff:{}};

	var lastPos = [0, 0];

	render(path);

	container.addEventListener("mousedown", function(e){
    var e_clientX = e.clientX;
    var e_clientY = e.clientY;
    if(_global_key_status.R_SHIFT || _global_key_status.L_SHIFT === 1){
      var r = lockHorV(e);
      e_clientX=r[0];
      e_clientY=r[1];
    }
		lastPos = [
			 e_clientX
			,e_clientY
		];
	});

	container.addEventListener("mouseup", function(e){
    var e_clientX = e.clientX;
    var e_clientY = e.clientY;

      if(_global_key_status.R_SHIFT || _global_key_status.L_SHIFT === 1){
        e_clientX = lastPos[0];
        e_clientY = lastPos[1];
      }

		if(Math.abs(lastPos[0] - e_clientX) + Math.abs(lastPos[1] - e_clientY) <= 4 && drawing){
			path.push([
				 ~~((e_clientX - (container.clientWidth/2 - innerContainer.clientWidth/2 + zoomOrigin[0]))/zoom)+0.5
				,~~((e_clientY - (container.clientHeight/2 - innerContainer.clientHeight/2 + zoomOrigin[1]))/zoom)+0.5
			]);
			render(path);
			
			undoHistory = [];
			redoButton.disabled = true;
			undoButton.disabled = false;
			
			if(path.length >= 3){
				finishButton.disabled = false;
			}
		}
	});

  function lockHorV(e){
    var e_clientX = e.clientX;
    var e_clientY = e.clientY;
    var x_offset = Math.abs(e.clientX -lastPos[0]);
    var y_offset = Math.abs(e.clientY-lastPos[1]);
    var offset = y_offset - x_offset ;
    if(y_offset > x_offset ) //keep x 
      e_clientX = lastPos[0];
    else if (x_offset > y_offset) //keep y
      e_clientY =lastPos[1];
    return [e_clientX,e_clientY];
  }

	window.addEventListener("mousemove", function(e){
    var e_clientX = e.clientX;
    var e_clientY = e.clientY;
		if(!dragging && drawing){
      if(_global_key_status.R_SHIFT || _global_key_status.L_SHIFT === 1){
        var r = lockHorV(e);
        e_clientX=r[0];
        e_clientY=r[1];
      }
			var last = [
				 ~~((e_clientX - (container.clientWidth/2 - innerContainer.clientWidth/2 + zoomOrigin[0]))/zoom)+0.5
				,~~((e_clientY - (container.clientHeight/2 - innerContainer.clientHeight/2 + zoomOrigin[1]))/zoom)+0.5
			];
			render(path.concat([last]));
		}
	});

	window.addEventListener("keyup", function(e){
		if(e.key == "Enter"){
			finish();
		} else if(e.key == "z" && e.ctrlKey){
			undo();
		} else if(e.key == "y" && e.ctrlKey){
			redo();
		} else if(e.key == "Escape"){
			exportOverlay.style.display = "none";
		} else if (e.key === "Shift" ){
      if(e.code === "ShiftRight")
        _global_key_status.R_SHIFT = 0;
      else if(e.code === "ShiftLeft")
        _global_key_status.L_SHIFT = 0;
    }
	});

	window.addEventListener("keydown", function(e){
   if (e.key === "Shift" ){
      if(e.code === "ShiftRight")
        _global_key_status.R_SHIFT = 1;
      else if(e.code === "ShiftLeft")
        _global_key_status.L_SHIFT = 1;
    }
 
  });
{'fraction_non_alphanumeric': 0.17386138613861385, 'fraction_numerical': 0.010957095709570958, 'mean_word_length': 3.8908973531310522, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '7256731', 'n_tokens_mistral': 2591, 'n_tokens_neox': 2344, 'n_words': 566}