-
Notifications
You must be signed in to change notification settings - Fork 0
/
Angle.cs
48 lines (41 loc) · 1.05 KB
/
Angle.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
namespace Thinf
{
public struct Angle
{
public float Value;
public Angle(float angle)
{
Value = angle;
float remainder = Value % (2f * (float)Math.PI);
float rotations = Value - remainder;
Value -= rotations;
if (Value < 0f)
{
Value += 2f * (float)Math.PI;
}
}
public static Angle operator +(Angle a1, Angle a2)
=> new Angle(a1.Value + a2.Value);
public static Angle operator -(Angle a1, Angle a2)
=> new Angle(a1.Value - a2.Value);
public Angle Opposite()
=> new Angle(Value + (float)Math.PI);
public bool ClockwiseFrom(Angle other)
{
if (other.Value >= (float)Math.PI)
{
return Value < other.Value && Value >= other.Opposite().Value;
}
return Value < other.Value || Value >= other.Opposite().Value;
}
public bool Between(Angle cLimit, Angle ccLimit)
{
if (cLimit.Value < ccLimit.Value)
{
return Value >= cLimit.Value && Value <= ccLimit.Value;
}
return Value >= cLimit.Value || Value <= ccLimit.Value;
}
}
}