<commit_before>/*
 * Paper.js
 *
 * This file is part of Paper.js, a JavaScript Vector Graphics Library,
 * based on Scriptographer.org and designed to be largely API compatible.
 * http://paperjs.org/
 * http://scriptographer.org/
 *
 * Distributed under the MIT license. See LICENSE file for details.
 *
 * Copyright (c) 2011, <NAME> & <NAME>
 * http://lehni.org/ & http://jonathanpuckey.com/
 *
 * All rights reserved.
 */

var Tool = this.Tool = Base.extend({
	/** @lends Tool# */

	beans: true,

	/**
	 * Initializes the tool's settings, so a new tool can be assigned to it
	 */
	initialize: function(handlers, scope) {
		this._scope = scope;
		this._firstMove = true;
		this._count = 0;
		this._downCount = 0;
		for (var i in handlers)
			this[i] = handlers[i];
	},

	/**
	 * The fixed time delay between each call to the {@link #onMouseDrag}
	 * event. Setting this to an interval means the {@link #onMouseDrag}
	 * event is called repeatedly after the initial {@link #onMouseDown}
	 * until the user releases the mouse.
	 * 
	 * @return the interval time in milliseconds
	 */
	eventInterval: null,

	/**
	 * The minimum distance the mouse has to drag before firing the onMouseDrag
	 * event, since the last onMouseDrag event.
	 */
	getMinDistance: function() {
		return this._minDistance;
	},

	setMinDistance: function(minDistance) {
		this._minDistance = minDistance;
		if (this._minDistance != null && this._maxDistance != null
				&& this._minDistance > this._maxDistance) {
			this._maxDistance = this._minDistance;
		}
	},

	getMaxDistance: function() {
		return this._maxDistance;
	},

	setMaxDistance: function(maxDistance) {
		this._maxDistance = maxDistance;
		if (this._minDistance != null && this._maxDistance != null
				&& this._maxDistance < this._minDistance) {
			this._minDistance = maxDistance;
		}
	},

	getFixedDistance: function() {
		return this._minDistance == this._maxDistance
			? this._minDistance : null;
	},

	setFixedDistance: function(distance) {
		this._minDistance = distance;
		this._maxDistance = distance;
	},

	updateEvent: function(type, pt, minDistance, maxDistance, start,
			needsChange, matchMaxDistance) {
		if (!start) {
			if (minDistance != null || maxDistance != null) {
				var minDist = minDistance != null ? minDistance : 0;
				var vector = pt.subtract(this._point);
				var distance = vector.getLength();
				if (distance < minDist)
					return false;
				// Produce a new point on the way to pt if pt is further away
				// than maxDistance
				var maxDist = maxDistance != null ? maxDistance : 0;
				if (maxDist != 0) {
					if (distance > maxDist) {
						pt = this._point.add(vector.normalize(maxDist));
					} else if (matchMaxDistance) {
						return false;
					}
				}<commit_msg>Add Tool documentation.<commit_after>/*
 * Paper.js
 *
 * This file is part of Paper.js, a JavaScript Vector Graphics Library,
 * based on Scriptographer.org and designed to be largely API compatible.
 * http://paperjs.org/
 * http://scriptographer.org/
 *
 * Distributed under the MIT license. See LICENSE file for details.
 *
 * Copyright (c) 2011, <NAME> & <NAME>
 * http://lehni.org/ & http://jonathanpuckey.com/
 *
 * All rights reserved.
 */

var Tool = this.Tool = Base.extend({
	/** @lends Tool# */

	beans: true,

	// DOCS: rewrite Tool constructor explanation
	/**
	 * Initializes the tool's settings, so a new tool can be assigned to it
	 * 
	 * @constructs Tool
	 *
	 * @class The Tool object refers to a script that the user can interact with
	 * by using the mouse and keyboard and can be accessed through the global
	 * {@code tool} variable. All its properties are also available in the paper
	 * scope.
	 * 
	 * The global {@code tool} variable only exists in scripts that contain mouse
	 * handler functions ({@link #onMouseMove}, {@link #onMouseDown},
	 * {@link #onMouseDrag}, {@link #onMouseUp}) or a keyboard handler
	 * function ({@link #onKeyDown}, {@link #onKeyUp}).
	 * 
	 * @example
	 * var path;
	 * 
	 * // Only execute onMouseDrag when the mouse
	 * // has moved at least 10 points:
	 * tool.distanceThreshold = 10;
	 * 
	 * function onMouseDown(event) {
	 * 	// Create a new path every time the mouse is clicked
	 * 	path = new Path();
	 * 	path.strokeColor = 'black';
	 * }
	 * 
	 * function onMouseDrag(event) {
	 * 	// Add a point to the path every time the mouse is dragged
	 * 	path.lineTo(event.point);
	 * }
	 */
	initialize: function(handlers, scope) {
		this._scope = scope;
		this._firstMove = true;
		this._count = 0;
		this._downCount = 0;
		for (var i in handlers)
			this[i] = handlers[i];
	},

	/**
	 * The fixed time delay in milliseconds between each call to the
	 * {@link #onMouseDrag} event. Setting this to an interval means the
	 * {@link #onMouseDrag} event is called repeatedly after the initial
	 * {@link #onMouseDown} until the user releases the mouse.
	 * 
	 * @type number
	 */
	eventInterval: null,

	/**
	 * The minimum distance the mouse has to drag before firing the onMouseDrag
	 * event, since the last onMouseDrag event.
	 * 
	 * @type number
	 * @bean
	 */
	getMinDistance: function() {
		return this._minDistance;
	},

	setMinDistance: function(minDistance) {
		this._minDistance = minDistance;
		if (this._minDistance != null && this._maxDistance != null
				&& this._minDistance > this._maxDistance) {
			this._maxDistance = this._minDistance;
		}
	},

	/**
	 * The maximum distance the mouse has to drag before firing the onMouseDrag
	 * event, since the last onMouseDrag event.
	 * 
	 * @type number
	 * @bean
	 */
	getMaxDistance: function() {
		return this._maxDistance;
	},

	setMaxDistance: function(maxDistance) {
		this._maxDistance = maxDistance;
		if (this._minDistance != null && this._maxDistance != null
				&& this._maxDistance < this._minDistance) {
			this._minDistance = maxDistance;
		}
	},

	// DOCS: document Tool#fixedDistance
	/**
	 * @type number
	 * @bean
	 */
	getFixedDistance: function() {
		return this._minDistance == this._maxDistance
			? this._minDistance : null;
	},

	setFixedDistance: function(distance) {
		this._minDistance = distance;
		this._maxDistance = distance;
	},

	/**
	 * {@grouptitle Mouse Event Handlers}
	 * 
	 * The function to be called when the mouse button is pushed down. The
	 * function receives a {@link ToolEvent} object which contains information
	 * about the mouse event.
	 * 
	 * @example
	 * function onMouseDown(event) {
	 * 	// the position of the mouse in project coordinates:
	 * 	console.log(event.point);
	 * }
	 * 
	 * @name Tool#onMouseDown
	 * @property
	 * @type function
	 */

	/**
	 * The function to be called when the mouse position changes while the mouse
	 * is being dragged. The function receives a {@link ToolEvent} object which
	 * contains information about the mouse event.
	 * 
	 * This function can also be called periodically while the mouse doesn't
	 * move by setting the {@link #eventInterval}
	 * 
	 * @example
	 * function onMouseDrag(event) {
	 * 	// the position of the mouse in project coordinates
	 * 	console.log(event.point);
	 * }
	 * 
	 * @name Tool#onMouseDrag
	 * @property
	 * @type function
	 */

	/**
	 * The function to be called when the tool is selected and the mouse moves
	 * within the document. The function receives a {@link ToolEvent} object
	 * which contains information about the mouse event.
	 * 
	 * @example
	 * function onMouseMove(event) {
	 * 	// the position of the mouse in project coordinates
	 * 	console.log(event.point);
	 * }
	 * @name Tool#onMouseMove
	 * @property
	 * @type function
	 */

	/**
	 * The function to be called when the mouse button is released. The function
	 * receives a {@link ToolEvent} object which contains information about the
	 * mouse event.
	 * 
	 * @example
	 * function onMouseUp(event) {
	 * 	// the position of the mouse in project coordinates
	 * 	console.log(event.point);
	 * }
	 * @name Tool#onMouseUp
	 * @property
	 * @type function
	 */

	// DOCS: document Tool#onKeyDown
	/**
	 * @name Tool#onKeyDown
	 * @property
	 * @type function
	 */

	// DOCS: document Tool#onKeyUp
	/**
	 * @name Tool#onKeyUp
	 * @property
	 * @type function
	 */

	updateEvent: function(type, pt, minDistance, maxDistance, start,
			needsChange, matchMaxDistance) {
		if (!start) {
			if (minDistance != null || maxDistance != null) {
				var minDist = minDistance != null ? minDistance : 0;
				var vector = pt.subtract(this._point);
				var distance = vector.getLength();
				if (distance < minDist)
					return false;
				// Produce a new point on the way to pt if pt is further away
				// than maxDistance
				var maxDist = maxDistance != null ? maxDistance : 0;
				if (maxDist != 0) {
					if (distance > maxDist) {
						pt = this._point.add(vector.normalize(maxDist));
					} else if (matchMaxDistance) {
						return false;
					}
				}
{'fraction_non_alphanumeric': 0.11288858633991378, 'fraction_numerical': 0.002496029044701611, 'mean_word_length': 3.159981123171307, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2592597', 'n_tokens_mistral': 2939, 'n_tokens_neox': 2545, 'n_words': 894}