>>110449448
lmao ok, so you want me to tell you whether a point lies under a linear piecewise function. A linked list is a dumb representation for something you know is monotonic in some value considering the opportunity for binary search, but fine.
struct Point {
int x;
int y;
};
struct Node {
struct Point point;
struct Node *next;
};
float
lerp(float y0, float y1, float x0, float x1, float x)
{
return y0 + (y1 - y0) * (x - x0) / (x1 - x0);
}
bool
under_the_line(const struct Node *line, struct Point target)
{
const struct Node *n0 = line;
for (; n0; n0 = n0->next) {
if (target.x < n0->point.x) {
break;
}
}
const struct Node *n1 = n0;
for (; n1; n1 = n1->next) {
if (target.x > n1->point.x) {
break;
}
}
return target.y < (n0 == n1 ? n0->point.y : lerp(n0->point.y, n1->point.y, n0->point.x, n1->point.x, target.x));
}
NEET dropout btw. hire me