Skip to content

Commit 5ed5321

Browse files
isHarryhK0lb3
authored andcommitted
refactor(math): Color
1 parent d9823c8 commit 5ed5321

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

UnityPy/math/Color.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,13 @@ class Color:
88
A: float
99

1010
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.")
1113
self.R = r
1214
self.G = g
1315
self.B = b
1416
self.A = a
1517

16-
def __eq__(self, other):
17-
if isinstance(other, Color):
18-
return self.__dict__ == other.__dict__
19-
else:
20-
return False
21-
2218
def __add__(self, other):
2319
return Color(
2420
self.R + other.R, self.G + other.G, self.B + other.B, self.A + other.A
@@ -37,7 +33,7 @@ def __mul__(self, other):
3733
else:
3834
return Color(self.R * other, self.G * other, self.B * other, self.A * other)
3935

40-
def __div__(self, other):
36+
def __truediv__(self, other):
4137
if isinstance(other, Color):
4238
return Color(
4339
self.R / other.R, self.G / other.G, self.B / other.B, self.A / other.A
@@ -46,10 +42,13 @@ def __div__(self, other):
4642
return Color(self.R / other, self.G / other, self.B / other, self.A / other)
4743

4844
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
5049

5150
def __ne__(self, other):
52-
return self.__dict__ != other.__dict__
51+
return not (self == other)
5352

5453
def Vector4(self):
5554
return Vector4(self.R, self.G, self.B, self.A)

0 commit comments

Comments
 (0)