forked from fponticelli/thx.unit
/
Candlepower.hx
50 lines (42 loc) · 1.84 KB
/
Candlepower.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
package thx.unit.luminousintensity;
import thx.core.Floats;
// TODO parse string
abstract Candlepower(Float) {
@:from inline static public function floatToCandlepower(value : Float) : Candlepower
return new Candlepower(value);
function new(value : Float)
this = value;
@:op( -A ) inline public function negate() : Candlepower
return -this;
@:op( A+B) inline public function add(other : Candlepower) : Candlepower
return this + other.toFloat();
@:op( A-B) inline public function subtract(other : Candlepower) : Candlepower
return this - other.toFloat();
@:op( A*B) inline public function multiply(other : Float) : Candlepower
return this * other;
@:op( A/B) inline public function divide(other : Float) : Candlepower
return this / other;
@:op( A%B) inline public function modulo(other : Float) : Candlepower
return this % other;
@:op(A==B) inline public function equal(other : Candlepower) : Bool
return this == other;
public function nearEqual(other : Candlepower) : Bool
return Floats.nearEqual(this, other.toFloat());
@:op(A!=B) inline public function notEqual(other : Candlepower) : Bool
return this != other;
@:op( A<B) inline public function less(other : Candlepower) : Bool
return this < other.toFloat();
@:op(A<=B) inline public function lessEqual(other : Candlepower) : Bool
return this <= other.toFloat();
@:op( A>B) inline public function more(other : Candlepower) : Bool
return this > other.toFloat();
@:op(A>=B) inline public function moreEqual(other : Candlepower) : Bool
return this >= other.toFloat();
@:to inline public function toFloat() : Float
return this;
@:to inline public function toCandela() : Candela
return this * 0.981;
@:to inline public function toString() : String
return this + symbol;
public static inline var symbol : String = "cp";
}