1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#pragma once
#include "../../compiler_setup.h"
#include "../../types/all.h"
#include "../../internal_functions/all.h"
static PyObject*
iround_(PyObject*, PyObject* arg) {
if (PyGLM_Number_Check(arg)) {
double d = PyGLM_Number_FromPyObject<double>(arg);
PyGLM_ASSERT((0.0 <= d), "x has to be greater than or equal to 0");
return pack(glm::iround(d));
}
PyGLM_PTI_Init0(arg, PyGLM_T_VEC | PyGLM_T_QUA | PyGLM_SHAPE_ALL | PyGLM_DT_FD);
if (PyGLM_Vec_PTI_Check0(1, float, arg)) {
glm::vec<1, float> o = PyGLM_Vec_PTI_Get0(1, float, arg);
PyGLM_ASSERT((glm::all(glm::lessThanEqual(glm::vec<1, float>(0), o))), "x has to be greater than or equal to 0");
return pack(glm::iround(o));
}
if (PyGLM_Vec_PTI_Check0(1, double, arg)) {
glm::vec<1, double> o = PyGLM_Vec_PTI_Get0(1, double, arg);
PyGLM_ASSERT((glm::all(glm::lessThanEqual(glm::vec<1, double>(0), o))), "x has to be greater than or equal to 0");
return pack(glm::iround(o));
}
if (PyGLM_Vec_PTI_Check0(2, float, arg)) {
glm::vec<2, float> o = PyGLM_Vec_PTI_Get0(2, float, arg);
PyGLM_ASSERT((glm::all(glm::lessThanEqual(glm::vec<2, float>(0), o))), "x has to be greater than or equal to 0");
return pack(glm::iround(o));
}
if (PyGLM_Vec_PTI_Check0(2, double, arg)) {
glm::vec<2, double> o = PyGLM_Vec_PTI_Get0(2, double, arg);
PyGLM_ASSERT((glm::all(glm::lessThanEqual(glm::vec<2, double>(0), o))), "x has to be greater than or equal to 0");
return pack(glm::iround(o));
}
if (PyGLM_Vec_PTI_Check0(3, float, arg)) {
glm::vec<3, float> o = PyGLM_Vec_PTI_Get0(3, float, arg);
PyGLM_ASSERT((glm::all(glm::lessThanEqual(glm::vec<3, float>(0), o))), "x has to be greater than or equal to 0");
return pack(glm::iround(o));
}
if (PyGLM_Vec_PTI_Check0(3, double, arg)) {
glm::vec<3, double> o = PyGLM_Vec_PTI_Get0(3, double, arg);
PyGLM_ASSERT((glm::all(glm::lessThanEqual(glm::vec<3, double>(0), o))), "x has to be greater than or equal to 0");
return pack(glm::iround(o));
}
if (PyGLM_Vec_PTI_Check0(4, float, arg)) {
glm::vec<4, float> o = PyGLM_Vec_PTI_Get0(4, float, arg);
PyGLM_ASSERT((glm::all(glm::lessThanEqual(glm::vec<4, float>(0), o))), "x has to be greater than or equal to 0");
return pack(glm::iround(o));
}
if (PyGLM_Vec_PTI_Check0(4, double, arg)) {
glm::vec<4, double> o = PyGLM_Vec_PTI_Get0(4, double, arg);
PyGLM_ASSERT((glm::all(glm::lessThanEqual(glm::vec<4, double>(0), o))), "x has to be greater than or equal to 0");
return pack(glm::iround(o));
}
PyGLM_TYPEERROR_O("invalid argument type for iround(): ", arg);
return NULL;
}
static PyObject*
uround_(PyObject*, PyObject* arg) {
if (PyGLM_Number_Check(arg)) {
double d = PyGLM_Number_FromPyObject<double>(arg);
PyGLM_ASSERT((0.0 <= d), "x has to be greater than or equal to 0");
return pack(glm::uround(d));
}
PyGLM_PTI_Init0(arg, PyGLM_T_VEC | PyGLM_SHAPE_ALL | PyGLM_DT_FD);
if (PyGLM_Vec_PTI_Check0(1, float, arg)) {
glm::vec<1, float> o = PyGLM_Vec_PTI_Get0(1, float, arg);
PyGLM_ASSERT((glm::all(glm::lessThanEqual(glm::vec<1, float>(0), o))), "x has to be greater than or equal to 0");
return pack(glm::uround(o));
}
if (PyGLM_Vec_PTI_Check0(1, double, arg)) {
glm::vec<1, double> o = PyGLM_Vec_PTI_Get0(1, double, arg);
PyGLM_ASSERT((glm::all(glm::lessThanEqual(glm::vec<1, double>(0), o))), "x has to be greater than or equal to 0");
return pack(glm::uround(o));
}
if (PyGLM_Vec_PTI_Check0(2, float, arg)) {
glm::vec<2, float> o = PyGLM_Vec_PTI_Get0(2, float, arg);
PyGLM_ASSERT((glm::all(glm::lessThanEqual(glm::vec<2, float>(0), o))), "x has to be greater than or equal to 0");
return pack(glm::uround(o));
}
if (PyGLM_Vec_PTI_Check0(2, double, arg)) {
glm::vec<2, double> o = PyGLM_Vec_PTI_Get0(2, double, arg);
PyGLM_ASSERT((glm::all(glm::lessThanEqual(glm::vec<2, double>(0), o))), "x has to be greater than or equal to 0");
return pack(glm::uround(o));
}
if (PyGLM_Vec_PTI_Check0(3, float, arg)) {
glm::vec<3, float> o = PyGLM_Vec_PTI_Get0(3, float, arg);
PyGLM_ASSERT((glm::all(glm::lessThanEqual(glm::vec<3, float>(0), o))), "x has to be greater than or equal to 0");
return pack(glm::uround(o));
}
if (PyGLM_Vec_PTI_Check0(3, double, arg)) {
glm::vec<3, double> o = PyGLM_Vec_PTI_Get0(3, double, arg);
PyGLM_ASSERT((glm::all(glm::lessThanEqual(glm::vec<3, double>(0), o))), "x has to be greater than or equal to 0");
return pack(glm::uround(o));
}
if (PyGLM_Vec_PTI_Check0(4, float, arg)) {
glm::vec<4, float> o = PyGLM_Vec_PTI_Get0(4, float, arg);
PyGLM_ASSERT((glm::all(glm::lessThanEqual(glm::vec<4, float>(0), o))), "x has to be greater than or equal to 0");
return pack(glm::uround(o));
}
if (PyGLM_Vec_PTI_Check0(4, double, arg)) {
glm::vec<4, double> o = PyGLM_Vec_PTI_Get0(4, double, arg);
PyGLM_ASSERT((glm::all(glm::lessThanEqual(glm::vec<4, double>(0), o))), "x has to be greater than or equal to 0");
return pack(glm::uround(o));
}
PyGLM_TYPEERROR_O("invalid argument type for uround(): ", arg);
return NULL;
}
PyDoc_STRVAR(iround_docstr,
"iround(x: number) -> int\n"
" Returns a value equal to the nearest integer to `x`. The fraction `0.5` will round in a\n"
" direction chosen by the implementation, presumably the direction that is fastest.\n"
"iround(x: vecN) -> ivecN\n"
" Returns a value equal to the nearest integer to `x`. The fraction `0.5` will round in a\n"
" direction chosen by the implementation, presumably the direction that is fastest."
);
PyDoc_STRVAR(uround_docstr,
"uround(x: number) -> int\n"
" Returns a value equal to the nearest integer to `x`. The fraction `0.5` will round in a\n"
" direction chosen by the implementation, presumably the direction that is fastest.\n"
"uround(x: vecN) -> uvecN\n"
" Returns a value equal to the nearest integer to `x`. The fraction `0.5` will round in a\n"
" direction chosen by the implementation, presumably the direction that is fastest."
);
#define INTEGER_METHODS \
{ "iround", (PyCFunction)iround_, METH_O, iround_docstr }, \
{ "uround", (PyCFunction)uround_, METH_O, uround_docstr }
|