forked from fponticelli/thx.unit
/
Turn.hx
79 lines (66 loc) · 2.59 KB
/
Turn.hx
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
package thx.unit.angle;
import thx.core.Floats;
// TODO parse string
abstract Turn(Float) {
@:from inline static public function floatToTurn(value : Float) : Turn
return new Turn(value);
function new(value : Float)
this = value;
inline public function cos()
return toRadian().cos();
inline public function sin()
return toRadian().sin();
@:op( -A ) inline public function negate() : Turn
return -this;
@:op( A+B) inline public function add(other : Turn) : Turn
return this + other.toFloat();
@:op( A-B) inline public function subtract(other : Turn) : Turn
return this - other.toFloat();
@:op( A*B) inline public function multiply(other : Float) : Turn
return this * other;
@:op( A/B) inline public function divide(other : Float) : Turn
return this / other;
@:op( A%B) inline public function modulo(other : Float) : Turn
return this % other;
@:op(A==B) inline public function equal(other : Turn) : Bool
return this == other;
public function nearEqual(other : Turn) : Bool
return Floats.nearEqual(this, other.toFloat());
@:op(A!=B) inline public function notEqual(other : Turn) : Bool
return this != other;
@:op( A<B) inline public function less(other : Turn) : Bool
return this < other.toFloat();
@:op(A<=B) inline public function lessEqual(other : Turn) : Bool
return this <= other.toFloat();
@:op( A>B) inline public function more(other : Turn) : Bool
return this > other.toFloat();
@:op(A>=B) inline public function moreEqual(other : Turn) : Bool
return this >= other.toFloat();
@:to inline public function toFloat() : Float
return this;
@:to inline public function toBinaryDegree() : BinaryDegree
return this * 256;
@:to inline public function toDegree() : Degree
return this * 360;
@:to inline public function toGrad() : Grad
return this * 400;
@:to inline public function toHourAngle() : HourAngle
return this * 24;
@:to inline public function toMinuteOfArc() : MinuteOfArc
return this * 21600;
@:to inline public function toPoint() : Point
return this * 32;
@:to inline public function toQuadrant() : Quadrant
return this * 4;
@:to inline public function toRadian() : Radian
return this * 6.28318530717959;
@:to inline public function toRevolution() : Revolution
return this * 1;
@:to inline public function toSecondOfArc() : SecondOfArc
return this * 1296000;
@:to inline public function toSextant() : Sextant
return this * 6;
@:to inline public function toString() : String
return this + symbol;
public static inline var symbol : String = "τ";
}