Open the context
Choose the project folder and name the files or behavior involved.
Interpolate between strictly increasing knots and clamp queries outside the endpoints. Check exact knots and reject repeated coordinates, non-finite values or magnitudes above one trillion before computing a linear blend.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
from math import isfinite
def interpolate(points, query):
def valid(x):
return type(x) in (int, float) and abs(x) <= 10**12 and isfinite(x)
if type(points) is not list or len(points) < 2 or not valid(query):
raise ValueError("knots.input")
if any(type(p) not in (list, tuple) or len(p) != 2 or
not all(valid(v) for v in p) for p in points):
raise ValueError("knots.point")
if any(a[0] >= b[0] for a,b in zip(points, points[1:])):
raise ValueError("knots.order")
if query <= points[0][0]:
return points[0][1]
for (x0,y0),(x1,y1) in zip(points, points[1:]):
if query <= x1:
t = (query-x0)/(x1-x0)
return (1-t)*y0+t*y1
return points[-1][1]The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.