68 lines
1.6 KiB
C#
68 lines
1.6 KiB
C#
/*
|
|
* Author: Andrey Pokidov
|
|
* License: Apache-2.0
|
|
* Date: 18 Nov 2024
|
|
*/
|
|
|
|
namespace BGC
|
|
{
|
|
public class DegreeFP64
|
|
{
|
|
public const double RADIANS_IN_DEGREE = 1.74532925199432958E-2;
|
|
public const double TURNS_IN_DEGREE = 2.77777777777777778E-3;
|
|
|
|
public static double ToRadians(double degrees)
|
|
{
|
|
return degrees * RADIANS_IN_DEGREE;
|
|
}
|
|
|
|
public static double ToTurns(double degrees)
|
|
{
|
|
return degrees * TURNS_IN_DEGREE;
|
|
}
|
|
|
|
public static double ToUnits(double degrees, AngleUnit toUnit)
|
|
{
|
|
if (toUnit == AngleUnit.RADIANS)
|
|
{
|
|
return degrees * RADIANS_IN_DEGREE;
|
|
}
|
|
|
|
if (toUnit == AngleUnit.TURNS)
|
|
{
|
|
return degrees * TURNS_IN_DEGREE;
|
|
}
|
|
|
|
return degrees;
|
|
}
|
|
|
|
public static double Normalize(double degrees, AngleRange range)
|
|
{
|
|
if (range == AngleRange.UNSIGNED_RANGE)
|
|
{
|
|
if (0.0 <= degrees && degrees < 360.0)
|
|
{
|
|
return degrees;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (-180.0 < degrees && degrees <= 180.0)
|
|
{
|
|
return degrees;
|
|
}
|
|
}
|
|
|
|
double turns = degrees * TURNS_IN_DEGREE;
|
|
|
|
turns -= Math.Floor(turns);
|
|
|
|
if (range == AngleRange.SIGNED_RANGE && turns > 0.5)
|
|
{
|
|
turns -= 1.0;
|
|
}
|
|
|
|
return turns * 360.0;
|
|
}
|
|
}
|
|
}
|