-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDegree.cs
More file actions
120 lines (93 loc) · 3.26 KB
/
Degree.cs
File metadata and controls
120 lines (93 loc) · 3.26 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System;
using System.ComponentModel;
namespace dotnetCampus.OpenXMLUnitConverter
{
[EditorBrowsable(EditorBrowsableState.Never), Obsolete("请使用 dotnetCampus.OpenXmlUnitConverter 命名空间下的同名类型。")]
public class Degree
{
public static readonly Degree Degree270 = Degree.FromDouble(270.0);
public static readonly Degree Degree90 = Degree.FromDouble(90);
public static readonly Degree Degree180 = Degree.FromDouble(180);
private int _intValue;
private const int MaxDegreeValue = 21600000;
private const double Precision = 60000.0;
public Degree(int value)
{
IntValue = value;
}
public int IntValue
{
get => _intValue;
private set
{
var d = value % MaxDegreeValue;
if (d < 0)
{
d += MaxDegreeValue;
}
_intValue = d;
}
}
public double DoubleValue => IntValue / Precision;
public double ToRadiansValue() => DoubleValue / 180 * Math.PI;
public override bool Equals(object obj)
{
if ((obj == null) || this.GetType() != obj.GetType())
{
return false;
}
else
{
Degree p = (Degree)obj;
return IntValue == p.IntValue;
}
}
public override int GetHashCode()
{
return this.IntValue.GetHashCode();
}
public static Degree operator +(Degree a) => a;
public static Degree operator -(Degree a) => new Degree(-a.IntValue);
public static Degree operator +(Degree a, Degree b)
=> new Degree(a.IntValue + b.IntValue);
public static Degree operator -(Degree a, Degree b)
=> a + (-b);
public static Degree operator *(Degree a, double b)
=> new Degree(((int)(a.IntValue * b)));
public static Degree operator *(double a, Degree b)
=> new Degree(((int)(a * b.IntValue)));
public static Degree operator /(Degree a, double b)
{
if (b == 0)
{
throw new DivideByZeroException();
}
return new Degree((int)(a.IntValue / b));
}
public static bool operator >(Degree a, Degree b)
=> a.IntValue > b.IntValue;
public static bool operator <(Degree a, Degree b)
=> b > a;
public static bool operator ==(Degree a, Degree b)
{
return a.IntValue == b.IntValue;
}
public static bool operator !=(Degree a, Degree b)
{
return !(a == b);
}
public static Degree FromDouble(double value)
{
int v = (int)(value * Precision);
return new Degree(v);
}
public static implicit operator dotnetCampus.OpenXmlUnitConverter.Degree(Degree legacyUnit)
{
return new dotnetCampus.OpenXmlUnitConverter.Degree(legacyUnit.IntValue);
}
public static implicit operator Degree(dotnetCampus.OpenXmlUnitConverter.Degree newUnit)
{
return new Degree(newUnit.IntValue);
}
}
}