118 lines
5.3 KiB
C#
118 lines
5.3 KiB
C#
namespace QWERTYkez.Mensura.Units;
|
|
|
|
/// <summary>
|
|
/// Base value is Seconds
|
|
/// </summary>
|
|
[UnitGenerator, DebuggerDisplay("Radians = {Radians.ToString(\"0.###\")}, Degrees = {Degrees.ToString(\"0.###\")}")]
|
|
public readonly partial record struct Angle
|
|
{
|
|
public static Angle _Second { get; } = new() { _Seconds = 1 };
|
|
[NotMapped, JsonIgnore] public double _Seconds { get => _Value; init => _Value = value; }
|
|
|
|
|
|
public static Angle Minute { get; } = new() { Minutes = 1 };
|
|
[NotMapped, JsonIgnore] public double Minutes
|
|
{
|
|
get => AngleConv.Minutes.From(_Value);
|
|
init
|
|
{
|
|
_Value = AngleConv.Minutes.To(value);
|
|
}
|
|
}
|
|
|
|
public static Angle Degree { get; } = new() { Degrees = 1 };
|
|
[NotMapped, JsonIgnore] public double Degrees
|
|
{
|
|
get => AngleConv.Degrees.From(_Value);
|
|
init
|
|
{
|
|
_Value = AngleConv.Degrees.To(value);
|
|
}
|
|
}
|
|
|
|
public static Angle Radian { get; } = new() { Radians = 1 };
|
|
[NotMapped, JsonIgnore] public double Radians
|
|
{
|
|
get => AngleConv.Radians.From(_Value);
|
|
init
|
|
{
|
|
_Value = AngleConv.Radians.To(value);
|
|
}
|
|
}
|
|
|
|
|
|
public Angle AddSeconds(double value) => new(_Value + value);
|
|
public Angle AddMinutes(double value) => new(_Value + AngleConv.Minutes.To(value));
|
|
public Angle AddGrads(double value) => new(_Value + AngleConv.Grads.To(value));
|
|
public Angle AddDegrees(double value) => new(_Value + AngleConv.Degrees.To(value));
|
|
public Angle AddRadians(double value) => new(_Value + AngleConv.Radians.To(value));
|
|
|
|
|
|
public static Angle Degs___0 { get; } = new() { Degrees = 0 };
|
|
public static Angle Degs__15 { get; } = new() { Degrees = 15 };
|
|
public static Angle Degs__30 { get; } = new() { Degrees = 30 };
|
|
public static Angle Degs__45 { get; } = new() { Degrees = 45 };
|
|
public static Angle Degs__60 { get; } = new() { Degrees = 60 };
|
|
public static Angle Degs__75 { get; } = new() { Degrees = 75 };
|
|
public static Angle Degs__90 { get; } = new() { Degrees = 90 };
|
|
public static Angle Degs_105 { get; } = new() { Degrees = 105 };
|
|
public static Angle Degs_120 { get; } = new() { Degrees = 120 };
|
|
public static Angle Degs_135 { get; } = new() { Degrees = 135 };
|
|
public static Angle Degs_150 { get; } = new() { Degrees = 150 };
|
|
public static Angle Degs_165 { get; } = new() { Degrees = 165 };
|
|
public static Angle Degs_180 { get; } = new() { Degrees = 180 };
|
|
public static Angle Degs_195 { get; } = new() { Degrees = 195 };
|
|
public static Angle Degs_210 { get; } = new() { Degrees = 210 };
|
|
public static Angle Degs_225 { get; } = new() { Degrees = 225 };
|
|
public static Angle Degs_240 { get; } = new() { Degrees = 240 };
|
|
public static Angle Degs_255 { get; } = new() { Degrees = 255 };
|
|
public static Angle Degs_270 { get; } = new() { Degrees = 270 };
|
|
public static Angle Degs_285 { get; } = new() { Degrees = 285 };
|
|
public static Angle Degs_300 { get; } = new() { Degrees = 300 };
|
|
public static Angle Degs_315 { get; } = new() { Degrees = 315 };
|
|
public static Angle Degs_330 { get; } = new() { Degrees = 330 };
|
|
public static Angle Degs_345 { get; } = new() { Degrees = 345 };
|
|
public static Angle Degs_360 { get; } = new() { Degrees = 360 };
|
|
|
|
public static Angle Pi { get; } = new(Constants.Pi);
|
|
|
|
public static double Cos__0 { get; } = 1;
|
|
public static double Cos_45 { get; } = Math.Cos(45 * Math.PI / 180);
|
|
public static double Cos_90 { get; } = 0;
|
|
public static double Sin__0 { get; } = 0;
|
|
public static double Sin_45 { get; } = Math.Sin(45 * Math.PI / 180);
|
|
public static double Sin_90 { get; } = 1;
|
|
|
|
|
|
public static Angle Acos(double d) => new() { Radians = Math.Acos(d) };
|
|
public static Angle Acosh(double d) => new() { Radians = Math.Acosh(d) };
|
|
public static Angle Asin(double d) => new() { Radians = Math.Asin(d) };
|
|
public static Angle Asinh(double d) => new() { Radians = Math.Asinh(d) };
|
|
public static Angle Atan(double d) => new() { Radians = Math.Atan(d) };
|
|
public static Angle Atanh(double d) => new() { Radians = Math.Atanh(d) };
|
|
|
|
public double Cos() => Math.Cos(AngleConv.Radians.From(_Value));
|
|
public double Cosh() => Math.Cosh(AngleConv.Radians.From(_Value));
|
|
public double Sin() => Math.Sin(AngleConv.Radians.From(_Value));
|
|
public (double Sin, double Cos) SinCos() => Math.SinCos(AngleConv.Radians.From(_Value));
|
|
public double Sinh() => Math.Sinh(AngleConv.Radians.From(_Value));
|
|
public double Tan() => Math.Tan(AngleConv.Radians.From(_Value));
|
|
public double Tanh() => Math.Tanh(AngleConv.Radians.From(_Value));
|
|
|
|
|
|
internal const double PiDiv2 = Math.PI / 2;
|
|
public double Ctg() => Math.Tan(PiDiv2 - AngleConv.Radians.From(_Value));
|
|
}
|
|
|
|
internal readonly struct AngleConv
|
|
{
|
|
private AngleConv(double multiplicator) => this.Multiplicator = multiplicator;
|
|
public double To(double value) => value * Multiplicator;
|
|
public double From(double value) => value / Multiplicator;
|
|
public double Multiplicator { get; init; }
|
|
public static AngleConv Seconds { get; } = new(1);
|
|
public static AngleConv Minutes { get; } = new(60);
|
|
public static AngleConv Grads { get; } = new(3240);
|
|
public static AngleConv Degrees { get; } = new(3600);
|
|
public static AngleConv Radians { get; } = new((180 * 60 * 60) / Math.PI);
|
|
} |