@@ -7,6 +7,10 @@ class (or others) to determine the size of each Axes. The unit
7
7
Note that this class is nothing more than a simple tuple of two
8
8
floats. Take a look at the Divider class to see how these two
9
9
values are used.
10
+
11
+ Once created, the unit classes can be modified by simple arithmetic
12
+ operations: addition /subtraction with another unit type or a real number and scaling
13
+ (multiplication or division) by a real number.
10
14
"""
11
15
12
16
from numbers import Real
@@ -17,14 +21,33 @@ class (or others) to determine the size of each Axes. The unit
17
21
18
22
class _Base :
19
23
def __rmul__ (self , other ):
24
+ return self * other
25
+
26
+ def __mul__ (self , other ):
27
+ if not isinstance (other , Real ):
28
+ return NotImplemented
20
29
return Fraction (other , self )
21
30
31
+ def __div__ (self , other ):
32
+ return (1 / other ) * self
33
+
22
34
def __add__ (self , other ):
23
35
if isinstance (other , _Base ):
24
36
return Add (self , other )
25
37
else :
26
38
return Add (self , Fixed (other ))
27
39
40
+ def __neg__ (self ):
41
+ return - 1 * self
42
+
43
+ def __radd__ (self , other ):
44
+ # other cannot be a _Base instance, because A + B would trigger
45
+ # A.__add__(B) first.
46
+ return Add (self , Fixed (other ))
47
+
48
+ def __sub__ (self , other ):
49
+ return self + (- other )
50
+
28
51
def get_size (self , renderer ):
29
52
"""
30
53
Return two-float tuple with relative and absolute sizes.
0 commit comments