Skip to content

Fix math.lerp docs, improve code #3523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reST/ref/math.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Conversion can be combined with swizzling or slicing to create a new order

The formula is:

``a * value + (1 - value) * b``.
``a + (b - a) * value``.

.. versionadded:: 2.4.0

Expand Down
21 changes: 6 additions & 15 deletions src_c/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -4494,12 +4494,12 @@ math_lerp(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *max = args[1];
PyObject *value = args[2];

if (PyNumber_Check(args[2]) != 1) {
return RAISE(PyExc_TypeError,
"lerp requires the interpolation amount to be number");
}

double a = PyFloat_AsDouble(min);
RAISE_ARG_TYPE_ERROR("min")
double b = PyFloat_AsDouble(max);
RAISE_ARG_TYPE_ERROR("max")
double t = PyFloat_AsDouble(value);
RAISE_ARG_TYPE_ERROR("value")

if (nargs == 4 && !PyObject_IsTrue(args[3])) {
; // pass if do_clamp is false
Expand All @@ -4513,16 +4513,7 @@ math_lerp(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
}
}

if (PyNumber_Check(min) && PyNumber_Check(max)) {
return PyFloat_FromDouble(PyFloat_AsDouble(min) * (1 - t) +
PyFloat_AsDouble(max) * t);
}
else {
return RAISE(
PyExc_TypeError,
"math.lerp requires all the arguments to be numbers. To lerp "
"between two vectors, please use the Vector class methods.");
}
return PyFloat_FromDouble(lerp(a, b, t));
}

static PyObject *
Expand Down
Loading