using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Base
{
public static class Misc
{
///
/// Call to signal that the player failed
///
public static Action closeGameWindow;
///
/// Convert a double to a float
///
/// Value to be converted
/// Converted value
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;
}
///
/// Convert a float to an int
///
/// Value to be converted
/// Converted value
public static int f2i(float input) => (int)Math.Round(input);
///
/// Convert a double to an int
///
/// Value to be converted
/// Converted value
public static int d2i(double input) => f2i(d2f(input));
///
/// Convert an int to a float
///
/// Value to be converted
/// Converted value
public static float i2f(int input) => input;
///
/// Convert an int to a double
///
/// Value to be converted
/// Converted value
public static double i2d(int input) => input;
///
/// Convert a float to a double
///
/// Value to be converted
/// Converted value
public static double f2d(float input) => input;
///
/// Convert a value in radians to a value in degrees
///
/// Value to be converted
/// Converted value
public static double rad2deg(double input) => (360 * input) / (2 * Math.PI);
///
/// Convert a value in degrees to a value in radians
///
/// Value to be converted
/// Converted value
public static double deg2rad(double input) => ((2 * Math.PI) * input) / 360;
///
/// Maps a number from one range of numbers to another
///
/// Start of the range the original number is in
/// End of the range the original number is in
/// Start of the range the new number is in
/// End of the range the new number is in
/// Value to be mapped
/// Mapped value
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);
}
}
}