2019-07-27 20:57:23 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-09-15 16:21:56 +02:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Drawing2D;
|
2019-07-27 20:57:23 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Base
|
|
|
|
|
{
|
|
|
|
|
public static class Misc
|
|
|
|
|
{
|
2019-09-19 18:51:31 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Call to signal that the player failed
|
|
|
|
|
/// </summary>
|
2019-09-14 14:00:28 +02:00
|
|
|
|
public static Action closeGameWindow;
|
2019-09-19 18:51:31 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert a double to a float
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">Value to be converted</param>
|
|
|
|
|
/// <returns>Converted value</returns>
|
2019-07-27 20:57:23 +02:00
|
|
|
|
public static float d2f(double input)
|
|
|
|
|
{
|
|
|
|
|
float result = Convert.ToSingle(input);
|
|
|
|
|
if (float.IsPositiveInfinity(result))
|
|
|
|
|
result = float.MaxValue;
|
|
|
|
|
else if (float.IsNegativeInfinity(result))
|
|
|
|
|
result = float.MinValue;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 18:51:31 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert a float to an int
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">Value to be converted</param>
|
|
|
|
|
/// <returns>Converted value</returns>
|
2019-07-27 20:57:23 +02:00
|
|
|
|
public static int f2i(float input) => (int)Math.Round(input);
|
2019-09-19 18:51:31 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert a double to an int
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">Value to be converted</param>
|
|
|
|
|
/// <returns>Converted value</returns>
|
2019-07-27 20:57:23 +02:00
|
|
|
|
public static int d2i(double input) => f2i(d2f(input));
|
2019-09-19 18:51:31 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert an int to a float
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">Value to be converted</param>
|
|
|
|
|
/// <returns>Converted value</returns>
|
2019-07-27 20:57:23 +02:00
|
|
|
|
public static float i2f(int input) => input;
|
2019-09-19 18:51:31 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert an int to a double
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">Value to be converted</param>
|
|
|
|
|
/// <returns>Converted value</returns>
|
2019-07-27 20:57:23 +02:00
|
|
|
|
public static double i2d(int input) => input;
|
2019-09-19 18:51:31 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert a float to a double
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">Value to be converted</param>
|
|
|
|
|
/// <returns>Converted value</returns>
|
2019-07-27 20:57:23 +02:00
|
|
|
|
public static double f2d(float input) => input;
|
2019-09-19 18:51:31 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert a value in radians to a value in degrees
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">Value to be converted</param>
|
|
|
|
|
/// <returns>Converted value</returns>
|
2019-08-01 22:42:35 +02:00
|
|
|
|
public static double rad2deg(double input) => (360 * input) / (2 * Math.PI);
|
2019-09-19 18:51:31 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert a value in degrees to a value in radians
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">Value to be converted</param>
|
|
|
|
|
/// <returns>Converted value</returns>
|
2019-08-01 22:42:35 +02:00
|
|
|
|
public static double deg2rad(double input) => ((2 * Math.PI) * input) / 360;
|
2019-09-19 18:51:31 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Maps a number from one range of numbers to another
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="originalStart">Start of the range the original number is in</param>
|
|
|
|
|
/// <param name="originalEnd">End of the range the original number is in</param>
|
|
|
|
|
/// <param name="newStart">Start of the range the new number is in</param>
|
|
|
|
|
/// <param name="newEnd">End of the range the new number is in</param>
|
|
|
|
|
/// <param name="value">Value to be mapped</param>
|
|
|
|
|
/// <returns>Mapped value</returns>
|
2019-09-14 14:00:28 +02:00
|
|
|
|
public static double map(double originalStart, double originalEnd, double newStart, double newEnd, double value)
|
|
|
|
|
{
|
|
|
|
|
double scale = (newEnd - newStart) / (originalEnd - originalStart);
|
|
|
|
|
return newStart + ((value - originalStart) * scale);
|
|
|
|
|
}
|
2019-07-27 20:57:23 +02:00
|
|
|
|
}
|
|
|
|
|
}
|