<commit_before>﻿using UnityEngine;
using System.Collections;

public class RTSCamera : MonoBehaviour {
	
	private readonly string[] INPUT_MOUSE_BUTTONS = {"Mouse Look", "Mouse Select"};
	
	private bool[] isDragging = new bool[2];
	private Vector3 selectStartPosition;
	private Texture2D pixel;

	void Start() {
		setPixel(Color.green);
	}
	
	void Update() {
		updateDragging();
		updateLook();
	}

	void OnGUI() {
		updateSelect();
	}

	private void updateDragging() {
		for (int index = 0; index <= 1; index ++) {
			if (isClicking(index) && !isDragging[index]) {
				isDragging[index] = true;
				if (index == 1) {
					selectStartPosition = Input.mousePosition;
				}
			} else if (!isClicking(index) && isDragging[index]) {
				isDragging[index] = false;
			}
		}
	}

	private void updateLook() {
		if (!isDragging[0]) { return; }
		var newPosition = transform.position;
		var mousePosition = getMouseMovement();
		newPosition.x = newPosition.x - mousePosition.x;
		newPosition.y = newPosition.y - mousePosition.y;
		transform.position = newPosition;
	}

	private void updateSelect() {
		if (!isDragging[1]) { return; }
		drawRectangle(selectStartPosition, Input.mousePosition);
	}

	private bool isClicking(int index) {
		return Input.GetAxis(INPUT_MOUSE_BUTTONS[index]) == 1;
	}

	private Vector2 getMouseMovement() {
		return new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
	}

	private void drawRectangle(Vector3 cornerA, Vector3 cornerB) {
		var x = cornerA.x;
		var y = cornerB.y;
		var width = cornerB.x - cornerA.x;
		var height = cornerB.y - cornerA.y;
		GUI.DrawTexture(new Rect(x, y, width, 1), pixel);
		GUI.DrawTexture(new Rect(x, y, 1, height), pixel);
		GUI.DrawTexture(new Rect(x, y + height, width, 1), pixel);
		GUI.DrawTexture(new Rect(x + width, y, 1, height), pixel);
	}

	private void setPixel(Color color) {
		pixel = new Texture2D(1, 1);
		pixel.SetPixel(0, 0, color);
		pixel.Apply();
	}

}<commit_msg>Fix bug where origin would move around<commit_after>﻿using UnityEngine;
using System.Collections;

public class RTSCamera : MonoBehaviour {
	
	private readonly string[] INPUT_MOUSE_BUTTONS = {"Mouse Look", "Mouse Select"};
	
	private bool[] isDragging = new bool[2];
	private Vector3 selectStartPosition;
	private Texture2D pixel;

	void Start() {
		setPixel(Color.green);
	}
	
	void Update() {
		updateDragging();
		updateLook();
	}

	void OnGUI() {
		updateSelect();
	}

	private void updateDragging() {
		for (int index = 0; index <= 1; index ++) {
			if (isClicking(index) && !isDragging[index]) {
				isDragging[index] = true;
				if (index == 1) {
					selectStartPosition = Input.mousePosition;
				}
			} else if (!isClicking(index) && isDragging[index]) {
				isDragging[index] = false;
			}
		}
	}

	private void updateLook() {
		if (!isDragging[0]) { return; }
		var newPosition = transform.position;
		var mousePosition = getMouseMovement();
		newPosition.x = newPosition.x - mousePosition.x;
		newPosition.y = newPosition.y - mousePosition.y;
		transform.position = newPosition;
	}

	private void updateSelect() {
		if (!isDragging[1]) { return; }
		drawRectangle(selectStartPosition, Input.mousePosition);
	}

	private bool isClicking(int index) {
		return Input.GetAxis(INPUT_MOUSE_BUTTONS[index]) == 1;
	}

	private Vector2 getMouseMovement() {
		return new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
	}

	private void drawRectangle(Vector3 cornerA, Vector3 cornerB) {
		var x = cornerA.x;
		var y = cornerA.y;
		var width = cornerB.x - cornerA.x;
		var height = cornerB.y - cornerA.y;
		GUI.DrawTexture(new Rect(x, y, width, 1), pixel);
		GUI.DrawTexture(new Rect(x, y, 1, height), pixel);
		GUI.DrawTexture(new Rect(x, y + height, width, 1), pixel);
		GUI.DrawTexture(new Rect(x + width, y, 1, height), pixel);
	}

	private void setPixel(Color color) {
		pixel = new Texture2D(1, 1);
		pixel.SetPixel(0, 0, color);
		pixel.Apply();
	}

}
{'fraction_non_alphanumeric': 0.13823004335628666, 'fraction_numerical': 0.011221627135934711, 'mean_word_length': 4.073738680465718, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2298405', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1353, 'n_words': 336}