<commit_before>package flixel.input;

import flixel.FlxCamera;
import flixel.group.FlxTypedGroup;
import flixel.math.FlxPoint;
import flixel.util.FlxStringUtil;

class FlxPointer
{
	public var x(default, null):Int = 0;
	public var y(default, null):Int = 0;
	
	public var screenX(default, null):Int = 0;
	public var screenY(default, null):Int = 0;
	
	private var _globalScreenX:Int = 0;
	private var _globalScreenY:Int = 0;
	
 	public function new() {}
	
	/**
	 * Fetch the world position of the input on any given camera.
	 * NOTE: x and y also store the world position of the point on the main camera.
	 * 
	 * @param 	Camera	If unspecified, first/main global camera is used instead.
	 * @param 	point	An existing point object to store the results (if you don't want a new one created). 
	 * @return 	The touch point's location in world space.
	 */
	public function getWorldPosition(?Camera:FlxCamera, ?point:FlxPoint):FlxPoint
	{
		if (Camera == null)
		{
			Camera = FlxG.camera;
		}
		if (point == null)
		{
			point = FlxPoint.get();
		}
		var screenPosition:FlxPoint = getScreenPosition(Camera);
		point.x = screenPosition.x + Camera.scroll.x;
		point.y = screenPosition.y + Camera.scroll.y;
		screenPosition.put();
		return point;
	}
	
	/**
	 * Fetch the screen position of the touch on any given camera.
	 * NOTE: Touch.screenX and Touch.screenY also store the screen position of the touch point on the main camera.
	 * 
	 * @param 	Camera	If unspecified, first/main global camera is used instead.
	 * @param 	point		An existing point object to store the results (if you don't want a new one created). 
	 * @return 	The touch point's location in screen space.
	 */
	public function getScreenPosition(?Camera:FlxCamera, ?point:FlxPoint):FlxPoint
	{
		if (Camera == null)
		{
			Camera = FlxG.camera;
		}
		if (point == null)
		{
			point = FlxPoint.get();
		}
		point.x = (_globalScreenX - Camera.x) / Camera.zoom;
		point.y = (_globalScreenY - Camera.y) / Camera.zoom;
		return point;
	}
	
	/**
	 * Returns a FlxPoint with this input's x and y.
	 */
	public inline function toPoint():FlxPoint
	{
		return FlxPoint.get(x, y);
	}
	
	/**
	 * Checks to see if some FlxObject overlaps this FlxObject or FlxGroup.
	 * If the group has a LOT of things in it, it might be faster to use FlxG.overlaps().
	 * WARNING: Currently tilemaps do NOT support screen space overlap checks!
	 * 
	 * @param 	ObjectOrGroup The object or group being tested.
	 * @param 	Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
	 * @return 	Whether or not the two objects overlap.
	*/
	public function overlaps(ObjectOrGroup:FlxBasic, ?Camera:FlxCamera):Bool
	{
		var result:Bool = false;
		
		var group = FlxTypedGroup.resolveGroup(ObjectOrGroup);
		if (group != null)
		{
			group.forEachExists(function(basic:FlxBasic) {
				if (overlaps(basic, Camera)) 
				{
					result = true;
					return;
				}
			});
		}
		else 
		{
			var point:FlxPoint = toPoint();
			var result:Bool = cast(ObjectOrGroup, FlxObject).overlapsPoint(point, true, Camera);
			point.put();
		}
		
		return result;
	}
	
	/**
	 * Directly set the underyling screen position variable. WARNING! You should never use
	 * this unless you are trying to manually dispatch low-level mouse / touch events to the stage.
	 */
	public inline function setGlobalScreenPositionUnsafe(X:Int, Y:Int):Void 
	{
		_globalScreenX = X;
		_globalScreenY = Y;
	}
	
	public function toString():String
	{
		return FlxStringUtil.getDebugString([ 
			LabelValuePair.weak("x", x),
			LabelValuePair.weak("y", y)]);
	}
	
	/**
	 * Helper function to update the cursor used by update() and playback().
	 * Updates the x, y, screenX, and screenY variables based on the default camera.
	 */
	private function updatePositions():Void
	{
		var screenPosition:FlxPoint = getScreenPosition();
		screenX = Std.int(screenPosition.x);
		screenY = Std.int(screenPosition.y);
		screenPosition.put();
		
		var worldPosition = getWorldPosition();
		x = Std.int(worldPosition.x);
		y = Std.int(worldPosition.y);
		worldPosition.put();
	}
}<commit_msg>FlxPointer: fix for overlaps()<commit_after>package flixel.input;

import flixel.FlxCamera;
import flixel.group.FlxTypedGroup;
import flixel.math.FlxPoint;
import flixel.util.FlxStringUtil;

class FlxPointer
{
	public var x(default, null):Int = 0;
	public var y(default, null):Int = 0;
	
	public var screenX(default, null):Int = 0;
	public var screenY(default, null):Int = 0;
	
	private var _globalScreenX:Int = 0;
	private var _globalScreenY:Int = 0;
	
 	public function new() {}
	
	/**
	 * Fetch the world position of the input on any given camera.
	 * NOTE: x and y also store the world position of the point on the main camera.
	 * 
	 * @param 	Camera	If unspecified, first/main global camera is used instead.
	 * @param 	point	An existing point object to store the results (if you don't want a new one created). 
	 * @return 	The touch point's location in world space.
	 */
	public function getWorldPosition(?Camera:FlxCamera, ?point:FlxPoint):FlxPoint
	{
		if (Camera == null)
		{
			Camera = FlxG.camera;
		}
		if (point == null)
		{
			point = FlxPoint.get();
		}
		var screenPosition:FlxPoint = getScreenPosition(Camera);
		point.x = screenPosition.x + Camera.scroll.x;
		point.y = screenPosition.y + Camera.scroll.y;
		screenPosition.put();
		return point;
	}
	
	/**
	 * Fetch the screen position of the touch on any given camera.
	 * NOTE: Touch.screenX and Touch.screenY also store the screen position of the touch point on the main camera.
	 * 
	 * @param 	Camera	If unspecified, first/main global camera is used instead.
	 * @param 	point		An existing point object to store the results (if you don't want a new one created). 
	 * @return 	The touch point's location in screen space.
	 */
	public function getScreenPosition(?Camera:FlxCamera, ?point:FlxPoint):FlxPoint
	{
		if (Camera == null)
		{
			Camera = FlxG.camera;
		}
		if (point == null)
		{
			point = FlxPoint.get();
		}
		point.x = (_globalScreenX - Camera.x) / Camera.zoom;
		point.y = (_globalScreenY - Camera.y) / Camera.zoom;
		return point;
	}
	
	/**
	 * Returns a FlxPoint with this input's x and y.
	 */
	public inline function toPoint():FlxPoint
	{
		return FlxPoint.get(x, y);
	}
	
	/**
	 * Checks to see if some FlxObject overlaps this FlxObject or FlxGroup.
	 * If the group has a LOT of things in it, it might be faster to use FlxG.overlaps().
	 * WARNING: Currently tilemaps do NOT support screen space overlap checks!
	 * 
	 * @param 	ObjectOrGroup The object or group being tested.
	 * @param 	Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
	 * @return 	Whether or not the two objects overlap.
	*/
	public function overlaps(ObjectOrGroup:FlxBasic, ?Camera:FlxCamera):Bool
	{
		var result:Bool = false;
		
		var group = FlxTypedGroup.resolveGroup(ObjectOrGroup);
		if (group != null)
		{
			group.forEachExists(function(basic:FlxBasic) {
				if (overlaps(basic, Camera)) 
				{
					result = true;
					return;
				}
			});
		}
		else 
		{
			var point:FlxPoint = toPoint();
			result = cast(ObjectOrGroup, FlxObject).overlapsPoint(point, true, Camera);
			point.put();
		}
		
		return result;
	}
	
	/**
	 * Directly set the underyling screen position variable. WARNING! You should never use
	 * this unless you are trying to manually dispatch low-level mouse / touch events to the stage.
	 */
	public inline function setGlobalScreenPositionUnsafe(X:Int, Y:Int):Void 
	{
		_globalScreenX = X;
		_globalScreenY = Y;
	}
	
	public function toString():String
	{
		return FlxStringUtil.getDebugString([ 
			LabelValuePair.weak("x", x),
			LabelValuePair.weak("y", y)]);
	}
	
	/**
	 * Helper function to update the cursor used by update() and playback().
	 * Updates the x, y, screenX, and screenY variables based on the default camera.
	 */
	private function updatePositions():Void
	{
		var screenPosition:FlxPoint = getScreenPosition();
		screenX = Std.int(screenPosition.x);
		screenY = Std.int(screenPosition.y);
		screenPosition.put();
		
		var worldPosition = getWorldPosition();
		x = Std.int(worldPosition.x);
		y = Std.int(worldPosition.y);
		worldPosition.put();
	}
}
{'fraction_non_alphanumeric': 0.10498177399756986, 'fraction_numerical': 0.0014580801944106927, 'mean_word_length': 3.529994496422675, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6313475', 'n_tokens_mistral': 2934, 'n_tokens_neox': 2599, 'n_words': 860}