26 ".. function:: clamp(value, min=0, max=1)\n"
28 " Clamps the float value between minimum and maximum. To avoid\n"
29 " confusion, any call must use either one or all three arguments.\n"
31 " :param value: The value to clamp.\n"
32 " :type value: float\n"
33 " :param min: The minimum value, defaults to 0.\n"
35 " :param max: The maximum value, defaults to 1.\n"
37 " :return: The clamped value.\n"
41 double x, minv = 0.0, maxv = 1.0;
43 if (PyTuple_Size(args) <= 1) {
44 if (!PyArg_ParseTuple(args,
53 if (!PyArg_ParseTuple(args,
68 return PyFloat_FromDouble(
x);
74 ".. function:: lerp(from_value, to_value, factor)\n"
76 " Linearly interpolate between two float values based on factor.\n"
78 " :param from_value: The value to return when factor is 0.\n"
79 " :type from_value: float\n"
80 " :param to_value: The value to return when factor is 1.\n"
81 " :type to_value: float\n"
82 " :param factor: The interpolation value, normally in [0.0, 1.0].\n"
83 " :type factor: float\n"
84 " :return: The interpolated value.\n"
89 if (!PyArg_ParseTuple(args,
101 return PyFloat_FromDouble(a * (1.0 -
x) +
b *
x);
106 py_bl_math_smoothstep_doc,
107 ".. function:: smoothstep(from_value, to_value, value)\n"
109 " Performs smooth interpolation between 0 and 1 as value changes between from and "
111 " Outside the range the function returns the same value as the nearest edge.\n"
113 " :param from_value: The edge value where the result is 0.\n"
114 " :type from_value: float\n"
115 " :param to_value: The edge value where the result is 1.\n"
116 " :type to_value: float\n"
117 " :param value: The interpolation value.\n"
118 " :type value: float\n"
119 " :return: The interpolated value in [0.0, 1.0].\n"
124 if (!PyArg_ParseTuple(args,
136 double t = (
x - a) / (
b - a);
140 return PyFloat_FromDouble(t * t * (3.0 - 2.0 * t));
150 {
"clamp",
static_cast<PyCFunction
>(
py_bl_math_clamp), METH_VARARGS, py_bl_math_clamp_doc},
151 {
"lerp",
static_cast<PyCFunction
>(
py_bl_math_lerp), METH_VARARGS, py_bl_math_lerp_doc},
155 py_bl_math_smoothstep_doc},
156 {
nullptr,
nullptr, 0,
nullptr},
162 "Miscellaneous math utilities module.");
static PyModuleDef M_bl_math_module_def
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
static PyObject * py_bl_math_smoothstep(PyObject *, PyObject *args)
PyMODINIT_FUNC BPyInit_bl_math()
static PyObject * py_bl_math_clamp(PyObject *, PyObject *args)
static PyMethodDef M_bl_math_methods[]
static PyObject * py_bl_math_lerp(PyObject *, PyObject *args)