@@ -7,6 +7,10 @@ class (or others) to determine the size of each Axes. The unit
77Note that this class is nothing more than a simple tuple of two
88floats. Take a look at the Divider class to see how these two
99values 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.
1014"""
1115
1216from numbers import Real
@@ -17,14 +21,33 @@ class (or others) to determine the size of each Axes. The unit
1721
1822class _Base :
1923 def __rmul__ (self , other ):
24+ return self * other
25+
26+ def __mul__ (self , other ):
27+ if not isinstance (other , Real ):
28+ return NotImplemented
2029 return Fraction (other , self )
2130
31+ def __div__ (self , other ):
32+ return (1 / other ) * self
33+
2234 def __add__ (self , other ):
2335 if isinstance (other , _Base ):
2436 return Add (self , other )
2537 else :
2638 return Add (self , Fixed (other ))
2739
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+
2851 def get_size (self , renderer ):
2952 """
3053 Return two-float tuple with relative and absolute sizes.
0 commit comments