How would I generate a function at runtime? NOT at comptime. I don't want for the user to need the zig compiler installed either.
Like how you can do this in JS
var nearestPointOnLine = function(ax, ay, bx, by) {
var dx = bx - ax; /* Vector from A to B (run) */
var dy = by - ay; /* ... (rise) */
var mag2 = dx*dx + dy*dy; /* Squared distance between A and B */
/* Find and return the nearest point on line AB to point P. */
var nearest = function(px, py) {
var a2pX = px - ax; /* Vector from A to P */
var a2pY = py - ay;
var a2pDota2b = a2pX*dx + a2pY*dy; /* AP ⦁ AB */
var t = a2pDota2b / mag2; /* Parametric distance from A to THE point */
return {
x: ax + dx*t,
y: ay + dy*t
};
};
return nearest;
};