63 lines
1.3 KiB
C#
63 lines
1.3 KiB
C#
/*
|
|
* Author: Andrey Pokidov
|
|
* License: Apache-2.0
|
|
* Date: 18 Nov 2024
|
|
*/
|
|
|
|
namespace BGC
|
|
{
|
|
public class TurnFP64
|
|
{
|
|
public static double ToRadians(double turns)
|
|
{
|
|
return turns * RadianFP64.TWO_PI;
|
|
}
|
|
|
|
public static double ToDegrees(double turns)
|
|
{
|
|
return turns * 360.0;
|
|
}
|
|
|
|
public static double ToUnits(double turns, AngleUnit toUnit)
|
|
{
|
|
if (toUnit == AngleUnit.RADIANS)
|
|
{
|
|
return turns * RadianFP64.TWO_PI;
|
|
}
|
|
|
|
if (toUnit == AngleUnit.DEGREES)
|
|
{
|
|
return turns * 360.0;
|
|
}
|
|
|
|
return turns;
|
|
}
|
|
|
|
public static double Normalize(double turns, AngleRange range)
|
|
{
|
|
if (range == AngleRange.UNSIGNED_RANGE)
|
|
{
|
|
if (0.0 <= turns && turns < 1.0)
|
|
{
|
|
return turns;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (-0.5 < turns && turns <= 0.5)
|
|
{
|
|
return turns;
|
|
}
|
|
}
|
|
|
|
double rest = turns - Math.Floor(turns);
|
|
|
|
if (range == AngleRange.SIGNED_RANGE && rest > 0.5)
|
|
{
|
|
rest -= 1.0;
|
|
}
|
|
|
|
return rest;
|
|
}
|
|
}
|
|
}
|