@@ -8,17 +8,13 @@ class Color:
8
8
A : float
9
9
10
10
def __init__ (self , r : float = 0.0 , g : float = 0.0 , b : float = 0.0 , a : float = 0.0 ):
11
+ if not all (isinstance (v , (int , float )) for v in (r , g , b , a )):
12
+ raise TypeError ("All components must be numeric." )
11
13
self .R = r
12
14
self .G = g
13
15
self .B = b
14
16
self .A = a
15
17
16
- def __eq__ (self , other ):
17
- if isinstance (other , Color ):
18
- return self .__dict__ == other .__dict__
19
- else :
20
- return False
21
-
22
18
def __add__ (self , other ):
23
19
return Color (
24
20
self .R + other .R , self .G + other .G , self .B + other .B , self .A + other .A
@@ -37,7 +33,7 @@ def __mul__(self, other):
37
33
else :
38
34
return Color (self .R * other , self .G * other , self .B * other , self .A * other )
39
35
40
- def __div__ (self , other ):
36
+ def __truediv__ (self , other ):
41
37
if isinstance (other , Color ):
42
38
return Color (
43
39
self .R / other .R , self .G / other .G , self .B / other .B , self .A / other .A
@@ -46,10 +42,13 @@ def __div__(self, other):
46
42
return Color (self .R / other , self .G / other , self .B / other , self .A / other )
47
43
48
44
def __eq__ (self , other ):
49
- return self .__dict__ == other .__dict__
45
+ if isinstance (other , Color ):
46
+ return self .__dict__ == other .__dict__
47
+ else :
48
+ return False
50
49
51
50
def __ne__ (self , other ):
52
- return self . __dict__ != other . __dict__
51
+ return not ( self == other )
53
52
54
53
def Vector4 (self ):
55
54
return Vector4 (self .R , self .G , self .B , self .A )
0 commit comments