Skip to content

Commit 36907ac

Browse files
isHarryhK0lb3
authored andcommitted
refactor(math): Quaternion
1 parent c801730 commit 36907ac

File tree

1 file changed

+22
-44
lines changed

1 file changed

+22
-44
lines changed

UnityPy/math/Quaternion.py

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,26 @@ class Quaternion:
33
Y: float
44
Z: float
55
W: float
6-
7-
def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0, w: float = 0.0):
8-
self._data = [0.0] * 4
9-
self.X = x
10-
self.Y = y
11-
self.Z = z
12-
self.W = w
13-
14-
@property
15-
def X(self) -> float:
16-
return self._data[0]
17-
18-
@X.setter
19-
def X(self, value: float):
20-
self._data[0] = value
21-
22-
@property
23-
def Y(self) -> float:
24-
return self._data[1]
25-
26-
@Y.setter
27-
def Y(self, value: float):
28-
self._data[1] = value
29-
30-
@property
31-
def Z(self) -> float:
32-
return self._data[2]
33-
34-
@Z.setter
35-
def Z(self, value: float):
36-
self._data[2] = value
37-
38-
@property
39-
def W(self) -> float:
40-
return self._data[3]
41-
42-
@W.setter
43-
def W(self, value: float):
44-
self._data[3] = value
45-
46-
def __getitem__(self, value):
47-
return self._data[value]
48-
6+
7+
def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0, w: float = 1.0):
8+
if not all(isinstance(v, (int, float)) for v in (x, y, z, w)):
9+
raise TypeError("All components must be numeric.")
10+
self.X = float(x)
11+
self.Y = float(y)
12+
self.Z = float(z)
13+
self.W = float(w)
14+
15+
def __getitem__(self, index):
16+
return (self.X, self.Y, self.Z, self.W)[index]
17+
4918
def __setitem__(self, index, value):
50-
self._data[index] = value
19+
if index == 0:
20+
self.X = value
21+
elif index == 1:
22+
self.Y = value
23+
elif index == 2:
24+
self.Z = value
25+
elif index == 3:
26+
self.W = value
27+
else:
28+
raise IndexError("Index out of range")

0 commit comments

Comments
 (0)