Skip to content

Commit 1ffed55

Browse files
alphaditocarson-katri
authored andcommitted
support more math dunder methods
1 parent f42e0ba commit 1ffed55

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

api/types.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,15 @@ def __init__(self, socket: bpy.types.NodeSocket = None, value = None):
5757
self.socket_type = type(socket).__name__
5858

5959
def _math(self, other, operation, reverse=False):
60+
if other is None:
61+
vector_or_value = self
62+
else:
63+
vector_or_value = (other, self) if reverse else (self, other)
64+
6065
if self._socket.type == 'VECTOR':
61-
return geometry_script.vector_math(operation=operation, vector=(other, self) if reverse else (self, other))
66+
return geometry_script.vector_math(operation=operation, vector=vector_or_value)
6267
else:
63-
return geometry_script.math(operation=operation, value=(other, self) if reverse else (self, other))
68+
return geometry_script.math(operation=operation, value=vector_or_value)
6469

6570
def __add__(self, other):
6671
return self._math(other, 'ADD')
@@ -92,6 +97,36 @@ def __mod__(self, other):
9297
def __rmod__(self, other):
9398
return self._math(other, 'MODULO', True)
9499

100+
def __floordiv__(self, other):
101+
return self._math(other, 'DIVIDE')._math(None,'FLOOR')
102+
103+
def __rfloordiv__(self, other):
104+
return self._math(other, 'DIVIDE',True)._math(None,'FLOOR')
105+
106+
def __pow__(self, other):
107+
return self._math(other, 'POWER')
108+
109+
def __rpow__(self, other):
110+
return self._math(other, 'POWER', True)
111+
112+
def __matmul__(self, other):
113+
return self._math(other, 'DOT_PRODUCT')
114+
115+
def __rmatmul__(self, other):
116+
return self._math(other, 'DOT_PRODUCT', True)
117+
118+
def __abs__(self):
119+
return self._math(None,'ABSOLUTE')
120+
121+
def __neg__(self):
122+
return self._math(-1, 'MULTIPLY')
123+
124+
def __pos__(self):
125+
return self
126+
127+
def __round__(self):
128+
return self._math(None,'ROUND')
129+
95130
def _compare(self, other, operation):
96131
return geometry_script.compare(operation=operation, a=self, b=other)
97132

0 commit comments

Comments
 (0)