Skip to content

Commit b6d281e

Browse files
committed
added floor division support to FVector2D
1 parent c1e930b commit b6d281e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Source/UnrealEnginePython/Private/Wrappers/UEPyFVector2D.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,23 @@ static PyObject *ue_py_fvector2d_div(ue_PyFVector2D *self, PyObject *value)
216216
return py_ue_new_fvector2d(vec);
217217
}
218218

219+
static PyObject *ue_py_fvector2d_floor_div(ue_PyFVector2D *self, PyObject *value)
220+
{
221+
FVector2D vec = self->vec;
222+
if (PyNumber_Check(value))
223+
{
224+
PyObject *f_value = PyNumber_Float(value);
225+
float f = PyFloat_AsDouble(f_value);
226+
if (f == 0)
227+
return PyErr_Format(PyExc_ZeroDivisionError, "division by zero");
228+
vec.X = floor(vec.X / f);
229+
vec.Y = floor(vec.Y / f);
230+
Py_DECREF(f_value);
231+
return py_ue_new_fvector2d(vec);
232+
}
233+
return PyErr_Format(PyExc_TypeError, "value is not numeric");
234+
}
235+
219236
PyNumberMethods ue_PyFVector2D_number_methods;
220237

221238
static Py_ssize_t ue_py_fvector2d_seq_length(ue_PyFVector2D *self)
@@ -297,6 +314,7 @@ void ue_python_init_fvector2d(PyObject *ue_module)
297314
ue_PyFVector2D_number_methods.nb_subtract = (binaryfunc)ue_py_fvector2d_sub;
298315
ue_PyFVector2D_number_methods.nb_multiply = (binaryfunc)ue_py_fvector2d_mul;
299316
ue_PyFVector2D_number_methods.nb_true_divide = (binaryfunc)ue_py_fvector2d_div;
317+
ue_PyFVector2D_number_methods.nb_floor_divide = (binaryfunc)ue_py_fvector2d_floor_div;
300318

301319
memset(&ue_PyFVector2D_sequence_methods, 0, sizeof(PySequenceMethods));
302320
ue_PyFVector2DType.tp_as_sequence = &ue_PyFVector2D_sequence_methods;

0 commit comments

Comments
 (0)