Skip to content

Commit

Permalink
Added new tests and fixed some bugs (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuzu-Typ authored Nov 21, 2021
1 parent 41823ac commit 46b3c29
Show file tree
Hide file tree
Showing 14 changed files with 1,517 additions and 197 deletions.
83 changes: 81 additions & 2 deletions PyGLM/functions/detail/func_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,87 @@ PyDoc_STRVAR(sign_docstr,
" For every component `c` of `x`:\n"
" Returns `1.0` if `x > 0`, `0.0` if `x == 0`, or `-1.0` if `x < 0`."
);
PyGLM_MAKE_GLM_FUNC_N_V__tfF(sign)
static PyObject*
sign_(PyObject*, PyObject* arg) {
if (PyGLM_Number_Check(arg)) {
return pack(glm::sign(PyGLM_Number_FromPyObject<double>(arg)));
}
PyGLM_PTI_Init0(arg, PyGLM_T_ANY_VEC | PyGLM_SHAPE_ALL | PyGLM_DT_FD | PyGLM_DT_INT | PyGLM_DT_INT64 | PyGLM_DT_INT16 | PyGLM_DT_INT8);
if (PyGLM_Vec_PTI_Check0(1, float, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(1, float, arg)));
}
if (PyGLM_Vec_PTI_Check0(1, double, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(1, double, arg)));
}
if (PyGLM_Vec_PTI_Check0(1, int32, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(1, int32, arg)));
}
if (PyGLM_Vec_PTI_Check0(1, int64, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(1, int64, arg)));
}
if (PyGLM_Vec_PTI_Check0(1, int16, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(1, int16, arg)));
}
if (PyGLM_Vec_PTI_Check0(1, int8, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(1, int8, arg)));
}
if (PyGLM_Vec_PTI_Check0(2, float, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(2, float, arg)));
}
if (PyGLM_Vec_PTI_Check0(2, double, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(2, double, arg)));
}
if (PyGLM_Vec_PTI_Check0(2, int32, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(2, int32, arg)));
}
if (PyGLM_Vec_PTI_Check0(2, int64, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(2, int64, arg)));
}
if (PyGLM_Vec_PTI_Check0(2, int16, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(2, int16, arg)));
}
if (PyGLM_Vec_PTI_Check0(2, int8, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(2, int8, arg)));
}
if (PyGLM_Vec_PTI_Check0(3, float, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(3, float, arg)));
}
if (PyGLM_Vec_PTI_Check0(3, double, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(3, double, arg)));
}
if (PyGLM_Vec_PTI_Check0(3, int32, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(3, int32, arg)));
}
if (PyGLM_Vec_PTI_Check0(3, int64, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(3, int64, arg)));
}
if (PyGLM_Vec_PTI_Check0(3, int16, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(3, int16, arg)));
}
if (PyGLM_Vec_PTI_Check0(3, int8, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(3, int8, arg)));
}
if (PyGLM_Vec_PTI_Check0(4, float, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(4, float, arg)));
}
if (PyGLM_Vec_PTI_Check0(4, double, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(4, double, arg)));
}
if (PyGLM_Vec_PTI_Check0(4, int32, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(4, int32, arg)));
}
if (PyGLM_Vec_PTI_Check0(4, int64, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(4, int64, arg)));
}
if (PyGLM_Vec_PTI_Check0(4, int16, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(4, int16, arg)));
}
if (PyGLM_Vec_PTI_Check0(4, int8, arg)) {
return pack(glm::sign(PyGLM_Vec_PTI_Get0(4, int8, arg)));
}
PyGLM_TYPEERROR_O("invalid argument type for sign(): ", arg);
return NULL;
}

PyDoc_STRVAR(floor_docstr,
"floor(x: float) -> float\n"
Expand Down Expand Up @@ -4260,7 +4340,6 @@ frexp_(PyObject*, PyObject* args) {
if (PyTuple_Check(args) && PyTuple_GET_SIZE(args) == 1) {
PyObject* arg = PyTuple_GET_ITEM(args, 0);
if (PyGLM_Number_Check(arg)) {
PyGLM_WARN(PyGLM_FREXP_WARNING, 1, "This function will return this pair: (m, e), which differs from glm behaviour.");
int e;
double m = glm::frexp(PyGLM_Number_FromPyObject<double>(arg), e);
return Py_BuildValue("(d, i)", m, e);
Expand Down
446 changes: 317 additions & 129 deletions PyGLM/functions/detail/func_integer.h

Large diffs are not rendered by default.

37 changes: 33 additions & 4 deletions PyGLM/functions/detail/func_vector_relational.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,20 @@ equal(PyObject*, PyObject* args) {

if (PyGLM_Number_Check(arg3)) {
if (PyGLM_Number_Check(arg1) && PyGLM_Number_Check(arg2)) {
pack(glm::equal(PyGLM_Number_FromPyObject<double>(arg1), PyGLM_Number_FromPyObject<double>(arg2), PyGLM_Number_FromPyObject<double>(arg3)));
return pack(glm::equal(PyGLM_Number_FromPyObject<double>(arg1), PyGLM_Number_FromPyObject<double>(arg2), PyGLM_Number_FromPyObject<double>(arg3)));
}
PyGLM_PTI_Init0(arg1, PyGLM_T_VEC | PyGLM_T_MAT | PyGLM_T_QUA | PyGLM_SHAPE_NxM | PyGLM_SHAPE_ALL | PyGLM_DT_FD);
PyGLM_PTI_Init1(arg2, PyGLM_T_VEC | PyGLM_T_MAT | PyGLM_T_QUA | PyGLM_SHAPE_NxM | PyGLM_SHAPE_ALL | PyGLM_DT_FD);
if (PyGLM_Vec_PTI_Check0(1, float, arg1) && PyGLM_Vec_PTI_Check1(1, float, arg2)) {
glm::vec<1, float> o = PyGLM_Vec_PTI_Get0(1, float, arg1);
glm::vec<1, float> o2 = PyGLM_Vec_PTI_Get1(1, float, arg2);
return pack(glm::equal(o, o2, PyGLM_Number_FromPyObject<float>(arg3)));
}
if (PyGLM_Vec_PTI_Check0(1, double, arg1) && PyGLM_Vec_PTI_Check1(1, double, arg2)) {
glm::vec<1, double> o = PyGLM_Vec_PTI_Get0(1, double, arg1);
glm::vec<1, double> o2 = PyGLM_Vec_PTI_Get1(1, double, arg2);
return pack(glm::equal(o, o2, PyGLM_Number_FromPyObject<double>(arg3)));
}
PyGLM_PTI_Init0(arg1, PyGLM_T_VEC | PyGLM_T_MAT | PyGLM_T_QUA | PyGLM_SHAPE_NxM | PyGLM_SHAPE_2 | PyGLM_SHAPE_3 | PyGLM_SHAPE_4 | PyGLM_DT_FD);
PyGLM_PTI_Init1(arg2, PyGLM_T_VEC | PyGLM_T_MAT | PyGLM_T_QUA | PyGLM_SHAPE_NxM | PyGLM_SHAPE_2 | PyGLM_SHAPE_3 | PyGLM_SHAPE_4 | PyGLM_DT_FD);
if (PyGLM_Vec_PTI_Check0(2, float, arg1) && PyGLM_Vec_PTI_Check1(2, float, arg2)) {
glm::vec<2, float> o = PyGLM_Vec_PTI_Get0(2, float, arg1);
glm::vec<2, float> o2 = PyGLM_Vec_PTI_Get1(2, float, arg2);
Expand Down Expand Up @@ -779,7 +789,26 @@ equal(PyObject*, PyObject* args) {
PyErr_SetString(PyExc_TypeError, "invalid argument type(s) for equal()");
return NULL;
}
PyGLM_PTI_Init2(arg3, PyGLM_T_VEC | PyGLM_SHAPE_2 | PyGLM_SHAPE_3 | PyGLM_SHAPE_4 | PyGLM_DT_INT | PyGLM_DT_FD)
PyGLM_PTI_Init2(arg3, PyGLM_T_VEC | PyGLM_SHAPE_ALL | PyGLM_DT_INT | PyGLM_DT_FD);

if (PyGLM_Vec_PTI_Check2(1, int, arg3)) {
glm::vec<1, int> o3 = PyGLM_Vec_PTI_Get2(1, int, arg3);
PyGLM_PTI_Init0(arg1, PyGLM_T_VEC | PyGLM_SHAPE_1 | PyGLM_DT_FD);
PyGLM_PTI_Init1(arg2, PyGLM_T_VEC | PyGLM_SHAPE_1 | PyGLM_DT_FD);
if (PyGLM_Vec_PTI_Check0(1, float, arg1) && PyGLM_Vec_PTI_Check1(1, float, arg2)) {
glm::vec<1, float> o = PyGLM_Vec_PTI_Get0(1, float, arg1);
glm::vec<1, float> o2 = PyGLM_Vec_PTI_Get1(1, float, arg2);
return pack(glm::equal(o, o2, o3));
}
if (PyGLM_Vec_PTI_Check0(1, double, arg1) && PyGLM_Vec_PTI_Check1(1, double, arg2)) {
glm::vec<1, double> o = PyGLM_Vec_PTI_Get0(1, double, arg1);
glm::vec<1, double> o2 = PyGLM_Vec_PTI_Get1(1, double, arg2);
return pack(glm::equal(o, o2, o3));
}
PyErr_SetString(PyExc_TypeError, "invalid argument type(s) for equal()");
return NULL;
}

if (PyGLM_Vec_PTI_Check2(2, int, arg3)) {
glm::vec<2, int> o3 = PyGLM_Vec_PTI_Get2(2, int, arg3);
PyGLM_PTI_Init0(arg1, PyGLM_T_VEC | PyGLM_T_MAT | PyGLM_SHAPE_2 | PyGLM_SHAPE_2xM | PyGLM_DT_FD);
Expand Down
22 changes: 11 additions & 11 deletions PyGLM/functions/other/binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ binary_add(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "add", arg1, arg2);

PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, 4, PyExc_DeprecationWarning, "glm.add is deprecated. Use operator.add instead");
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.add is deprecated. Use operator.add instead");

return PyNumber_Add(arg1, arg2);
}
Expand All @@ -26,7 +26,7 @@ binary_sub(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "sub", arg1, arg2);

PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, 4, PyExc_DeprecationWarning, "glm.sub is deprecated. Use operator.sub instead");
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.sub is deprecated. Use operator.sub instead");

return PyNumber_Subtract(arg1, arg2);
}
Expand All @@ -40,7 +40,7 @@ binary_mul(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "mul", arg1, arg2);

PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, 4, PyExc_DeprecationWarning, "glm.mul is deprecated. Use operator.mul instead");
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.mul is deprecated. Use operator.mul instead");

return PyNumber_Multiply(arg1, arg2);
}
Expand All @@ -54,7 +54,7 @@ binary_div(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "div", arg1, arg2);

PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, 4, PyExc_DeprecationWarning, "glm.div is deprecated. Use operator.truediv instead");
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.div is deprecated. Use operator.truediv instead");

return PyNumber_TrueDivide(arg1, arg2);
}
Expand All @@ -68,7 +68,7 @@ binary_floordiv(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "floordiv", arg1, arg2);

PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, 4, PyExc_DeprecationWarning, "glm.floordiv is deprecated. Use operator.floordiv instead");
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.floordiv is deprecated. Use operator.floordiv instead");

return PyNumber_FloorDivide(arg1, arg2);
}
Expand All @@ -82,7 +82,7 @@ binary_mod(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "mod", arg1, arg2);

PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, 4, PyExc_DeprecationWarning, "glm.mod is deprecated. Use operator.mod instead");
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.mod is deprecated. Use operator.mod instead");

return PyNumber_Remainder(arg1, arg2);
}
Expand All @@ -96,7 +96,7 @@ binary_lshift(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "lshift", arg1, arg2);

PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, 4, PyExc_DeprecationWarning, "glm.lshift is deprecated. Use operator.lshift instead");
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.lshift is deprecated. Use operator.lshift instead");

return PyNumber_Lshift(arg1, arg2);
}
Expand All @@ -110,7 +110,7 @@ binary_rshift(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "rshift", arg1, arg2);

PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, 4, PyExc_DeprecationWarning, "glm.rshift is deprecated. Use operator.rshift instead");
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.rshift is deprecated. Use operator.rshift instead");

return PyNumber_Rshift(arg1, arg2);
}
Expand All @@ -124,7 +124,7 @@ binary_and(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "band", arg1, arg2);

PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, 4, PyExc_DeprecationWarning, "glm.band is deprecated. Use operator.and_ instead");
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.band is deprecated. Use operator.and_ instead");

return PyNumber_And(arg1, arg2);
}
Expand All @@ -138,7 +138,7 @@ binary_xor(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "bxor", arg1, arg2);

PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, 4, PyExc_DeprecationWarning, "glm.bxor is deprecated. Use operator.xor instead");
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.bxor is deprecated. Use operator.xor instead");

return PyNumber_Xor(arg1, arg2);
}
Expand All @@ -152,7 +152,7 @@ binary_or(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "bor", arg1, arg2);

PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, 4, PyExc_DeprecationWarning, "glm.bor is deprecated. Use operator.or_ instead");
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.bor is deprecated. Use operator.or_ instead");

return PyNumber_Or(arg1, arg2);
}
Expand Down
6 changes: 3 additions & 3 deletions PyGLM/functions/other/unary.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PyDoc_STRVAR(unary_pos_docstr,
);
static PyObject*
unary_pos(PyObject*, PyObject* arg) {
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, 4, PyExc_DeprecationWarning, "glm.pos is deprecated. Use operator.pos instead");
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.pos is deprecated. Use operator.pos instead");
return PyNumber_Positive(arg);
}

Expand All @@ -24,7 +24,7 @@ PyDoc_STRVAR(unary_neg_docstr,
);
static PyObject*
unary_neg(PyObject*, PyObject* arg) {
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, 4, PyExc_DeprecationWarning, "glm.neg is deprecated. Use operator.neg instead");
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.neg is deprecated. Use operator.neg instead");
return PyNumber_Negative(arg);
}

Expand All @@ -34,7 +34,7 @@ PyDoc_STRVAR(unary_inv_docstr,
);
static PyObject*
unary_inv(PyObject*, PyObject* arg) {
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, 4, PyExc_DeprecationWarning, "glm.inv is deprecated. Use operator.invert instead");
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.inv is deprecated. Use operator.invert instead");
return PyNumber_Invert(arg);
}

Expand Down
2 changes: 1 addition & 1 deletion PyGLM/internal_functions/error_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#define PyGLM_ZERO_DIVISION_ERROR PyErr_SetString(PyExc_ZeroDivisionError, "Whoopsie. Integers can't divide by zero (:")

#define PyGLM_ZERO_DIVISION_ERROR_T(T) if (std::numeric_limits<T>::is_iec559) { PyGLM_WARN(PyGLM_FLOAT_ZERO_DIVISION_WARNING, 2, "Uh oh.. There is a float division by zero here. I hope that's intended!"); } else { PyGLM_ZERO_DIVISION_ERROR; return NULL; }
#define PyGLM_ZERO_DIVISION_ERROR_T(T) if (std::numeric_limits<T>::is_iec559) { PyGLM_WARN(PyGLM_FLOAT_ZERO_DIVISION_WARNING, "Uh oh.. There is a float division by zero here. I hope that's intended!"); } else { PyGLM_ZERO_DIVISION_ERROR; return NULL; }

#define PyGLM_Arg_Unpack_1O(args, name, arg1) if(!PyArg_UnpackTuple(args, name, 1, 1, &arg1)) return NULL
#define PyGLM_Arg_Unpack_2O(args, name, arg1, arg2) if(!PyArg_UnpackTuple(args, name, 2, 2, &arg1, &arg2)) return NULL
Expand Down
8 changes: 6 additions & 2 deletions PyGLM/internal_functions/helper_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

#define PyGLM_TypeCheck(op, tp) (Py_TYPE(op) == tp)

#define PyGLM_Ctypes_TypeCheck(op, tp) PyGLM_TypeCheck(op, PyGLM_CTYPES_TYPE<tp>())

#define PyGLM_Ctypes_Get(op, tp) (*reinterpret_cast<tp*>(reinterpret_cast<ctypes_helper*>(op)->b_ptr))

#define PyGLM_FITS_IN_FLOAT(value) ((FLT_MAX >= value && value >= FLT_MIN) || (-FLT_MIN >= value && value >= -FLT_MAX))

#define PyGLM_TupleOrList_Check(op) PyType_FastSubclass(Py_TYPE(op), (Py_TPFLAGS_TUPLE_SUBCLASS | Py_TPFLAGS_LIST_SUBCLASS))
Expand All @@ -27,9 +31,9 @@
#define PyGLM_PREPROCESSOR_TOSTRING_ID(x) #x
#define PyGLM_PREPROCESSOR_TOSTRING(x) PyGLM_PREPROCESSOR_TOSTRING_ID(x)

#define PyGLM_WARN(flag, id, msg) PyGLM_WARN_TYPE(flag, id, PyExc_UserWarning, msg)
#define PyGLM_WARN(id, msg) PyGLM_WARN_TYPE(id, PyExc_UserWarning, msg)

#define PyGLM_WARN_TYPE(flag, id, type, msg) if (PyGLM_SHOW_WARNINGS & flag) PyErr_WarnEx(type, msg "\nYou can silence this warning by calling glm.silence(" PyGLM_PREPROCESSOR_TOSTRING(id) ")", 1)
#define PyGLM_WARN_TYPE(id, type, msg) if (PyGLM_SHOW_WARNINGS & (1ull << id)) PyErr_WarnEx(type, msg "\nYou can silence this warning by calling glm.silence(" PyGLM_PREPROCESSOR_TOSTRING(id) ")", 1)

#define PyGLM_free(ptr) PyMem_Free(ptr); ptr = NULL;

Expand Down
Loading

0 comments on commit 46b3c29

Please sign in to comment.