MCPcopy Create free account
hub / github.com/electronstudio/raylib-python-cffi / Vector2Ex

Class Vector2Ex

examples/extra/vector2_extended.py:5–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3from pyray import *
4
5class Vector2Ex(list):
6 def __init__(self, x, y):
7 super(Vector2Ex, self).__init__([x, y])
8
9 @property
10 def x(self):
11 return self[0]
12
13 @x.setter
14 def x(self, value):
15 self[0]= value
16
17 @property
18 def y(self):
19 return self[1]
20
21 @y.setter
22 def y(self, value):
23 self[1]= value
24
25 @staticmethod
26 def to_Vec2(v: Vector2):
27 """
28 Cast Vector2 to Vec2.
29 """
30 return Vector2Ex(v.x, v.y)
31
32 def __repr__(self) -> str:
33 return f"{self.x}, {self.y}"
34
35 def __eq__(self, other):
36 if isinstance(other, Vector2Ex):
37 return self.x == other.x and self.y == other.y
38 return False
39
40 def __add__(self, other):
41 if isinstance(other, Vector2Ex):
42 return Vector2Ex(self.x + other.x, self.y + other.y)
43 return Vector2Ex(self.x + other, self.y + other)
44
45 def __iadd__(self, other):
46 if isinstance(other, Vector2Ex):
47 self.x += other.x
48 self.y += other.y
49 else:
50 res = vector2_add_value(self, other)
51 self.x = res.x
52 self.y = res.y
53 return self
54
55 def __radd__(self, other):
56 return self + other
57
58 def __sub__(self, other):
59 if isinstance(other, Vector2Ex):
60 return Vector2Ex(self.x - other.x, self.y - other.y)
61 return Vector2Ex(self.x - other, self.y - other)
62

Callers 12

to_Vec2Method · 0.85
__add__Method · 0.85
__sub__Method · 0.85
__rsub__Method · 0.85
__mul__Method · 0.85
__truediv__Method · 0.85
__neg__Method · 0.85
__pos__Method · 0.85
__pow__Method · 0.85
oneMethod · 0.85
zeroMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected