fparse icon indicating copy to clipboard operation
fparse copied to clipboard

Using objects as values

Open structinfo opened this issue 5 months ago • 0 comments

It would be useful to allow passing object values into formula to process inside custom functions.

Example:

const fObj = new Formula()
fObj.distance = (point1, point2) => Math.sqrt(Math.pow(point1.x - point2.x, 2) + Math.pow(point1.y - point2.y, 2))

fObj.setFormula('distance(x,y)')
console.log(fObj.evaluate({ x: { 1, 3 }, y: { 4, 5 } }))

The example is simplified. Points can be N-dimentional etc.

structinfo avatar Sep 08 '24 06:09 structinfo