Skip to content

Added tolerance for Color.lerp #3347

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
Feb 25, 2025
Merged
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
14 changes: 13 additions & 1 deletion src_c/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,19 @@ _color_lerp(pgColorObject *self, PyObject *args, PyObject *kw)
return NULL;
}

if (amt < 0 || amt > 1) {
// TOLERANCE to account for double precison floating point inaccuracy at
// the very limits, like if you're LERP'ing by 0.01. When you hit the end,
// something stupid like this might happen
/* >>> value = 0
>>> offset = 0.01
>>> while value < 1:
... value += offset
...
>>> print(value)
1.0000000000000007
*/
static const double TOLERANCE = 1e-6;
if ((amt < -TOLERANCE) || (amt > (1.0 + TOLERANCE))) {
return RAISE(PyExc_ValueError, "Argument 2 must be in range [0, 1]");
}

Expand Down
Loading