better performances
changed self.x = x self.y = y self.z = z to self.x, self.y, self.z = x, y, z
This commit is contained in:
parent
70a6259d8b
commit
e93cae162b
1 changed files with 8 additions and 13 deletions
21
vec3.py
21
vec3.py
|
@ -1,6 +1,3 @@
|
||||||
from typing import Union
|
|
||||||
import math
|
|
||||||
import random
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,17 +7,13 @@ class Vec3:
|
||||||
__slots__ = ("x", "y", "z")
|
__slots__ = ("x", "y", "z")
|
||||||
|
|
||||||
def __init__(self, x: float, y: float, z: float):
|
def __init__(self, x: float, y: float, z: float):
|
||||||
self.x = x
|
self.x, self.y, self.z = x, y, z
|
||||||
self.y = y
|
|
||||||
self.z = z
|
|
||||||
|
|
||||||
def __add__(self, other :"Vec3"):
|
def __add__(self, other :"Vec3"):
|
||||||
return Vec3(self.x + other.x, self.y + other.y, self.z + other.z)
|
return Vec3(self.x + other.x, self.y + other.y, self.z + other.z)
|
||||||
|
|
||||||
def __iadd__(self, other : "Vec3"):
|
def __iadd__(self, other : "Vec3"):
|
||||||
self.x += other.x
|
self.x, self.y, self.z = self.x + other.x, self.y + other.y, self.z + other.z
|
||||||
self.y += other.y
|
|
||||||
self.z += other.z
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __neg__(self):
|
def __neg__(self):
|
||||||
|
@ -30,16 +23,14 @@ class Vec3:
|
||||||
return Vec3(self.x - other.x, self.y - other.y, self.z - other.z)
|
return Vec3(self.x - other.x, self.y - other.y, self.z - other.z)
|
||||||
|
|
||||||
def __isub__(self, other : "Vec3"):
|
def __isub__(self, other : "Vec3"):
|
||||||
self.x -= other.x
|
self.x, self.y, self.z = self.x - other.x, self.y - other.y, self.z - other.z
|
||||||
self.y -= other.y
|
|
||||||
self.z -= other.z
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __mul__(self, other : Num):
|
def __mul__(self, other : Num):
|
||||||
return Vec3(self.x * other, self.y * other, self.z * other)
|
return Vec3(self.x * other, self.y * other, self.z * other)
|
||||||
|
|
||||||
def __rmul__(self, other : Num):
|
def __rmul__(self, other : Num):
|
||||||
return self * other
|
return Vec3(self.x * other, self.y * other, self.z * other)
|
||||||
|
|
||||||
def __truediv__(self, other : Num):
|
def __truediv__(self, other : Num):
|
||||||
return Vec3(self.x / other, self.y / other, self.z / other)
|
return Vec3(self.x / other, self.y / other, self.z / other)
|
||||||
|
@ -53,6 +44,9 @@ class Vec3:
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter((self.x, self.y, self.z))
|
return iter((self.x, self.y, self.z))
|
||||||
|
|
||||||
|
def __copy__(self):
|
||||||
|
return Vec3(self.x, self.y, self.z)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"Vec3({self.x}, {self.y}, {self.z})"
|
return f"Vec3({self.x}, {self.y}, {self.z})"
|
||||||
|
|
||||||
|
@ -95,3 +89,4 @@ class Vec3:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue