Skip to content

Commit cdb24a7

Browse files
committed
Fix math.lerp docs, improve code
1 parent 7896a55 commit cdb24a7

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

docs/reST/ref/math.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Conversion can be combined with swizzling or slicing to create a new order
119119

120120
The formula is:
121121

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

124124
.. versionadded:: 2.4.0
125125

src_c/math.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4494,12 +4494,12 @@ math_lerp(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
44944494
PyObject *max = args[1];
44954495
PyObject *value = args[2];
44964496

4497-
if (PyNumber_Check(args[2]) != 1) {
4498-
return RAISE(PyExc_TypeError,
4499-
"lerp requires the interpolation amount to be number");
4500-
}
4501-
4497+
double a = PyFloat_AsDouble(min);
4498+
RAISE_ARG_TYPE_ERROR("min")
4499+
double b = PyFloat_AsDouble(max);
4500+
RAISE_ARG_TYPE_ERROR("max")
45024501
double t = PyFloat_AsDouble(value);
4502+
RAISE_ARG_TYPE_ERROR("value")
45034503

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

4516-
if (PyNumber_Check(min) && PyNumber_Check(max)) {
4517-
return PyFloat_FromDouble(PyFloat_AsDouble(min) * (1 - t) +
4518-
PyFloat_AsDouble(max) * t);
4519-
}
4520-
else {
4521-
return RAISE(
4522-
PyExc_TypeError,
4523-
"math.lerp requires all the arguments to be numbers. To lerp "
4524-
"between two vectors, please use the Vector class methods.");
4525-
}
4516+
return PyFloat_FromDouble(lerp(a, b, t));
45264517
}
45274518

45284519
static PyObject *

0 commit comments

Comments
 (0)