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

/// <summary>
/// Represents an absolute facing. Can only be in 4 cardinal directions.
///
/// Defined in terms of euler angle (rotation about the z axis, right is 0 and up is 90).
/// </summary>
public struct Orientation
{
	public static readonly Orientation Right = new Orientation(0);
	public static readonly Orientation Up = new Orientation(90);
	public static readonly Orientation Left = new Orientation(180);
	public static readonly Orientation Down = new Orientation(270);

	private static readonly Orientation[] clockwiseOrientation = {Right, Down, Left, Up};

	/// <summary>
	/// Euler angle (rotation about the z axis, right is 0 and up is 90).
	/// </summary>
	public readonly int Degrees;

	private Orientation(int degree)
	{
		Degrees = degree;
	}

	/// <summary>
	/// Index of this rotation in the clockwiseOrientation array
	/// </summary>
	private int OrientationIndex
	{
		get
		{
			switch (Degrees)
			{
				case 0:
					return 0;
				case 90:
					return 3;
				case 180:
					return 2;
				default:
					return 1;
			}
		}
	}

	/// <summary>
	/// Vector pointing in the same direction as the orientation.
	/// </summary>
	public Vector3 Vector => (Quaternion.Euler(0,0, Degrees) * Vector3Int.right).RoundToInt();

	/// <summary>
	/// Return the orientation that would be reached by rotating clockwise 90 degrees the given number of turns
	/// </summary>
	/// <param name="steps">number of times to rotate 90 degrees, negative for counter-clockwise</param>
	/// <returns>the orientation that would be reached by rotating 90 degrees the given number of turns</returns>
	public Orientation Rotate(int turns)
	{
		var newIndex = ((OrientationIndex + turns) % clockwiseOrientation.Length + clockwiseOrientation.Length) % clockwiseOrientation.Length;
		return clockwiseOrientation[newIndex];
	}

	/// <summary>
	/// Return the rotation that would be reached by rotating according to the specified offset.
	///
	/// For example, if Orientation is Right and offset is Backwards, will return Orientation.Left
	/// </summary>
	/// <param name="offset">offset to rotate by</param>
	/// <returns>the rotation that would be reached by rotating according to the specified offset.</returns>
	public Orientation Rotate(RotationOffset offset)
	{
		return Rotate(offset.Degree / 90);
	}


	public override string ToString()
	{
		if (this == Left)
		{
			return "Left";
		}
		else if (this == Right)
		{
			return "Right";
		}
		else if (this == Up)
		{
			return "Up";
		}
		else
		{
			return "Down";
		}
	}

	/// <summary>
	/// Gets the Rotationoffset that would offset this orientation to reach toOrientation.
	///
	/// For example if this is Up and toOrientation is Down, returns RotationOffset.Backwards
	/// </summary>
	/// <param name="toOrientation">orientation to which the offset should be determined</param>
	/// <returns>the rotationoffset</returns>
	public RotationOffset OffsetTo(Orientation toOrientation)
	{
		if (this == toOrientation)
		{
			return RotationOffset.Same;
		}
		if (Rotate(1) == toOrientation)
		{
			return RotationOffset.Right;
		}
		else if (Rotate(2) == toOrientation)
		{
			return RotationOffset.Backwards;
		}
		else
		{
			return RotationOffset.Left;
		}
	}

	private static float AngleFromUp(Vector2 dir)
	{
		float angle = Vector2.Angle(Vector2.up, dir);

		if (dir.x < 0)
		{
			angle = 360 - angle;
		}

		return angle;
	}

	/// <summary>
	/// Orientation pointing the same direction as the specified vector.
	/// For example if vector is right (1,0), this will return Orientation.Right
	/// </summary>
	/// <param name="direction">direction</param>
	/// <returns>orientation pointing in same direction as vector</returns>
	public static Orientation From( Vector2 direction )
	{
		float degree = AngleFromUp(direction);
		var orientation = Down;
		if ( degree >= 315f && degree <= 360f || degree >= 0f && degree <= 45f ) {
			orientation = Up;
		}
		if ( degree > 45f && degree <= 135f ) {
			orientation = Right;
		}
		if ( degree > 135f && degree <= 225f ) {
			orientation = Down;
		}
		if ( degree > 225f && degree < 315f ) {
			orientation = Left;
		}
		return orientation;
	}

	/// <summary>
	/// Gets an int representing how many 90 degree rotations would be needed to get from<commit_msg>[CHANGE] Playerdirection degrees to have right/left be more inclusive<commit_after>using System;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// Represents an absolute facing. Can only be in 4 cardinal directions.
///
/// Defined in terms of euler angle (rotation about the z axis, right is 0 and up is 90).
/// </summary>
public struct Orientation
{
	public static readonly Orientation Right = new Orientation(0);
	public static readonly Orientation Up = new Orientation(90);
	public static readonly Orientation Left = new Orientation(180);
	public static readonly Orientation Down = new Orientation(270);

	private static readonly Orientation[] clockwiseOrientation = {Right, Down, Left, Up};

	/// <summary>
	/// Euler angle (rotation about the z axis, right is 0 and up is 90).
	/// </summary>
	public readonly int Degrees;

	private Orientation(int degree)
	{
		Degrees = degree;
	}

	/// <summary>
	/// Index of this rotation in the clockwiseOrientation array
	/// </summary>
	private int OrientationIndex
	{
		get
		{
			switch (Degrees)
			{
				case 0:
					return 0;
				case 90:
					return 3;
				case 180:
					return 2;
				default:
					return 1;
			}
		}
	}

	/// <summary>
	/// Vector pointing in the same direction as the orientation.
	/// </summary>
	public Vector3 Vector => (Quaternion.Euler(0,0, Degrees) * Vector3Int.right).RoundToInt();

	/// <summary>
	/// Return the orientation that would be reached by rotating clockwise 90 degrees the given number of turns
	/// </summary>
	/// <param name="steps">number of times to rotate 90 degrees, negative for counter-clockwise</param>
	/// <returns>the orientation that would be reached by rotating 90 degrees the given number of turns</returns>
	public Orientation Rotate(int turns)
	{
		var newIndex = ((OrientationIndex + turns) % clockwiseOrientation.Length + clockwiseOrientation.Length) % clockwiseOrientation.Length;
		return clockwiseOrientation[newIndex];
	}

	/// <summary>
	/// Return the rotation that would be reached by rotating according to the specified offset.
	///
	/// For example, if Orientation is Right and offset is Backwards, will return Orientation.Left
	/// </summary>
	/// <param name="offset">offset to rotate by</param>
	/// <returns>the rotation that would be reached by rotating according to the specified offset.</returns>
	public Orientation Rotate(RotationOffset offset)
	{
		return Rotate(offset.Degree / 90);
	}


	public override string ToString()
	{
		if (this == Left)
		{
			return "Left";
		}
		else if (this == Right)
		{
			return "Right";
		}
		else if (this == Up)
		{
			return "Up";
		}
		else
		{
			return "Down";
		}
	}

	/// <summary>
	/// Gets the Rotationoffset that would offset this orientation to reach toOrientation.
	///
	/// For example if this is Up and toOrientation is Down, returns RotationOffset.Backwards
	/// </summary>
	/// <param name="toOrientation">orientation to which the offset should be determined</param>
	/// <returns>the rotationoffset</returns>
	public RotationOffset OffsetTo(Orientation toOrientation)
	{
		if (this == toOrientation)
		{
			return RotationOffset.Same;
		}
		if (Rotate(1) == toOrientation)
		{
			return RotationOffset.Right;
		}
		else if (Rotate(2) == toOrientation)
		{
			return RotationOffset.Backwards;
		}
		else
		{
			return RotationOffset.Left;
		}
	}

	private static float AngleFromUp(Vector2 dir)
	{
		float angle = Vector2.Angle(Vector2.up, dir);

		if (dir.x < 0)
		{
			angle = 360 - angle;
		}

		return angle;
	}

	/// <summary>
	/// Orientation pointing the same direction as the specified vector.
	/// For example if vector is right (1,0), this will return Orientation.Right
	/// </summary>
	/// <param name="direction">direction</param>
	/// <returns>orientation pointing in same direction as vector</returns>
	public static Orientation From( Vector2 direction )
	{
		float degree = AngleFromUp(direction);
		var orientation = Down;
		if ( degree > 315f && degree <= 360f || degree >= 0f && degree < 45f ) {
			orientation = Up;
		}
		if ( degree >= 45f && degree <= 135f ) {
			orientation = Right;
		}
		if ( degree > 135f && degree < 225f ) {
			orientation = Down;
		}
		if ( degree >= 225f && degree <= 315f ) {
			orientation = Left;
		}
		return orientation;
	}

	/// <summary>
	/// Gets an int representing how many 90 degree rotations would be needed to get from
{'fraction_non_alphanumeric': 0.11541111621497474, 'fraction_numerical': 0.017914561322921452, 'mean_word_length': 3.2153920619554697, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 81, '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': '3221391', 'n_tokens_mistral': 3014, 'n_tokens_neox': 2541, 'n_words': 917}