Skip to content

Commit

Permalink
Fixed Vec type checking
Browse files Browse the repository at this point in the history
Should fix #43
  • Loading branch information
Zuzu-Typ committed Nov 6, 2019
1 parent 952d2e4 commit ea756b0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
31 changes: 19 additions & 12 deletions PyGLM.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define PyGLM_VERSION "1.1.0"
#define PyGLM_VERSION "1.1.1"

#define PyGLM_NO_FUNCTIONS 1
#define PyGLM_NO_ITER_TYPECHECKING 2
Expand Down Expand Up @@ -15276,7 +15276,9 @@ static bool PyGLM_Vecb_Check(int L, PyObject* o) {
return true;
}

#define PyGLM_Vec_Check(L, T, o) (PyObject_TypeCheck(o, UNBRACKET (PyGLM_VEC_TYPE<L, T>())) || Py_TYPE(o) == PyGLM_MVEC_TYPE<L, T>() || ((PyGLM_GET_TYPE(o) == PyGLM_TYPE_UNKNOWN || (PyGLM_GET_TYPE(o) == PyGLM_TYPE_VEC && PyGLM_VEC_SHAPE_CHECK(o, L))) && ((PyGLM_Vecb_Check<T>(L, (PyObject*)o)) || (PyGLM_Veci_Check(L, o)))))
#define PyGLM_Vec_Check(L, T, o) (PyObject_TypeCheck(o, UNBRACKET (PyGLM_VEC_TYPE<L, T>())) || Py_TYPE(o) == PyGLM_MVEC_TYPE<L, T>() || ((PyGLM_GET_TYPE(o) == PyGLM_TYPE_UNKNOWN) && (PyGLM_Vecb_Check<T>(L, (PyObject*)o))))

#define PyGLM_Vec_Check_IgnoreType(L, T, o) (PyObject_TypeCheck(o, UNBRACKET (PyGLM_VEC_TYPE<L, T>())) || Py_TYPE(o) == PyGLM_MVEC_TYPE<L, T>() || ((PyGLM_GET_TYPE(o) == PyGLM_TYPE_UNKNOWN || (PyGLM_GET_TYPE(o) == PyGLM_TYPE_VEC && PyGLM_VEC_SHAPE_CHECK(o, L))) && ((PyGLM_Vecb_Check<T>(L, (PyObject*)o)) || (PyGLM_Veci_Check(L, o)))))

#define PyGLM_Qua_Check(T, o) (PyObject_TypeCheck(o, UNBRACKET (PyGLM_QUA_TYPE<T>())) || ((PyGLM_GET_TYPE(o) == PyGLM_TYPE_UNKNOWN || (PyGLM_GET_TYPE(o) == PyGLM_TYPE_QUA)) && PyGLM_Vecb_Check<T>(4, (PyObject*)o)))

Expand All @@ -15285,6 +15287,8 @@ static bool PyGLM_Vecb_Check(int L, PyObject* o) {
#else
#define PyGLM_Vec_Check(L, T, o) (PyObject_TypeCheck(o, UNBRACKET (PyGLM_VEC_TYPE<L, T>())) || Py_TYPE(o) == PyGLM_MVEC_TYPE<L, T>())

#define PyGLM_Vec_Check_IgnoreType PyGLM_Vec_Check

#define PyGLM_Qua_Check(T, o) (PyObject_TypeCheck(o, UNBRACKET (PyGLM_QUA_TYPE<T>())))

#define PyGLM_Mat_Check(C, R, T, o) PyObject_TypeCheck(o, UNBRACKET (PyGLM_MAT_TYPE<C, R, T>()))
Expand Down Expand Up @@ -15709,19 +15713,19 @@ vec1_init(vec<1, T> *self, PyObject *args, PyObject *kwds)
self->super_type = glm::vec<1, T>(PyGLM_Number_FromPyObject<T>(arg));
return 0;
}
if (PyGLM_Vec_Check(1, T, arg)) {
if (PyGLM_Vec_Check_IgnoreType(1, T, arg)) {
self->super_type = unpack_vec<1, T>(arg);
return 0;
}
if (PyGLM_Vec_Check(2, T, arg)) {
if (PyGLM_Vec_Check_IgnoreType(2, T, arg)) {
self->super_type = unpack_vec<2, T>(arg);
return 0;
}
if (PyGLM_Vec_Check(3, T, arg)) {
if (PyGLM_Vec_Check_IgnoreType(3, T, arg)) {
self->super_type = unpack_vec<3, T>(arg);
return 0;
}
if (PyGLM_Vec_Check(4, T, arg)) {
if (PyGLM_Vec_Check_IgnoreType(4, T, arg)) {
self->super_type = unpack_vec<4, T>(arg);
return 0;
}
Expand Down Expand Up @@ -15752,15 +15756,15 @@ vec2_init(vec<2, T> *self, PyObject *args, PyObject *kwds)
return 0;
}

if (PyGLM_Vec_Check(2, T, arg1)) {
if (PyGLM_Vec_Check_IgnoreType(2, T, arg1)) {
self->super_type = unpack_vec<2, T>(arg1);
return 0;
}
if (PyGLM_Vec_Check(3, T, arg1)) {
if (PyGLM_Vec_Check_IgnoreType(3, T, arg1)) {
self->super_type = unpack_vec<3, T>(arg1);
return 0;
}
if (PyGLM_Vec_Check(4, T, arg1)) {
if (PyGLM_Vec_Check_IgnoreType(4, T, arg1)) {
self->super_type = unpack_vec<4, T>(arg1);
return 0;
}
Expand Down Expand Up @@ -15797,11 +15801,11 @@ vec3_init(vec<3, T> *self, PyObject *args, PyObject *kwds)
return 0;
}

if (PyGLM_Vec_Check(3, T, arg1)) {
if (PyGLM_Vec_Check_IgnoreType(3, T, arg1)) {
self->super_type = unpack_vec<3, T>(arg1);
return 0;
}
if (PyGLM_Vec_Check(4, T, arg1)) {
if (PyGLM_Vec_Check_IgnoreType(4, T, arg1)) {
self->super_type = unpack_vec<4, T>(arg1);
return 0;
}
Expand Down Expand Up @@ -35678,7 +35682,10 @@ silence(PyObject*, PyObject* arg) {

//static PyObject*
//test(PyObject* self, PyObject* arg) {
// return PyLong_FromLong((long)((shape_helper*)arg)->shape);
// if (PyGLM_Vec_Check(3, double, arg)) {
// Py_RETURN_TRUE;
// }
// Py_RETURN_FALSE;
//}
//#define HAS_TEST
//#define TEST_FUNC_TYPE METH_O
Expand Down
File renamed without changes.
8 changes: 6 additions & 2 deletions PyGLM_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,10 @@ def fassert(func, args):

# random #
for args in gen_args("NN_VV__fFiqsuIQSU"):
comp = args[0] > args[1]
if type(comp) != bool: comp = any(comp)
if len(args) == 2 and comp:
args = (args[1], args[0])
fassert(glm.linearRand, args)
fassert(glm.gaussRand, args)

Expand Down Expand Up @@ -997,7 +1001,7 @@ def fassert(func, args):
#/type_ptr #

# ulp #
for args in gen_args("#uN_V_NNi_VNi_VVi_fF"):
for args in gen_args("#uN_V_NNi_VNi_VVi__fF"):
fassert(glm.next_float, args)
fassert(glm.prev_float, args)

Expand All @@ -1006,4 +1010,4 @@ def fassert(func, args):
#/ulp #
##/EXTENSIONS ##

print("Finished tests in {:.3g}s".format(time.time()-start_time))
print("Finished tests in {:.3g}s".format(time.time()-start_time))
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='1.1.0',
version='1.1.1',

description='OpenGL Mathematics library for Python',
long_description=long_description,
Expand Down

0 comments on commit ea756b0

Please sign in to comment.