Show HN: Smooth.js - Turn arrays into smooth functions
github.com
github.com
Smooth points,
method: 'cubic'
clip: 'periodic'
cubicTension: 'catmull-rom'But there is a good reason in the case of the cubicTension constants: those aren't enums, but actual values. You can put any cubicTension parameter you want between 0 and 1.
Although if I may, there is a potential benefit to using strings there in that it lets you get rid of the switch statement entirely:
unless config.clip of ClipHelpers
throw new Error "No clip mode '#{config.clip}'. Available modes are #{(k for k of ClipHelpers).join(', ')}"
clipHelper = ClipHelpers[config.clip]
This could also make it easy for a user to add helpers at runtime. Maybe overkill for this, just something to keep in mind.Chebyshev polynomials are more accurate than Fourier. In fact they are the most accurate interpolating polynomials in general. They're not as wildly known, but often used in numerical analysis. The problem with Fourier is that if your function is not periodic, the coefficients do not converge quickly, making the interpolant less accurate for a given number of nodes. Chebyshev gets around this problem, but instead of using equally spaced points, points are spaced out along the uneven "Chebyshev nodes". So to get an interpolated point, say 2.5, 2.5 no longer falls halfway between the 2nd and 3rd Cheb node, you would first have to figure out the value of 2.5 in the nonuniform Chebyshev distribution of points, and then compute the interpolating value in linear time at this point.[1]
Both Chebyshev and Fourier are "global" interpolants. As opposed to cubic splines and your other ones. If you change a single value in your vector, the entire interpolant is affected and needs to be recomputed.
But Nlog(N) only works for certain values of N, right (like powers of two)? I guess for other cases, we could use the clipping method to dictate behavior, but that doesn't feel great.
Ooo that's a good idea. Of course, you can use 3D vectors for rgb values to get much the same effect.
Why is it not named Smooth.coffee?
> The golden rule of CoffeeScript is: "It's just JavaScript".
And there is every possibility that it could get rewritten in JavaScript. Or it could be rewritten in something else that compiles to JS, if something comes along to which this task is well-suited. The implementation can change, and the name should remain appropriate. What will not certainly change, however, is the environment in which this is intended to be used.
Hope that makes sense.
It seems like saying something could be cross-compiled doesn't really mean it is in that other language, but again, people seem to think of CoffeeScript as different.
Also, sorry for forgetting, but thanks for making this! It looks pretty awesome.
Do you have any plans for extrapolation?
BTW. Yesterday I needed to mirror some sequence and I ended up using Math.sin()
In general, the mapping between CoffeeScript and JS is so trivial that it's hard to think of places where there could be a lack of control. Of course, if that were ever an issue, CoffeeScript lets you directly embed JS by surrounding it in backticks.
I also had a bad gut reaction to CoffeeScript initially, and I won't pretend it doesn't have drawbacks; the powerful, in-browser debugger that it desperately craves still hasn't yet been written, after all. But it really gets right what so many compile-to-javascript languages have gotten wrong in the past. At the very least, it is hands down the easiest way to sketch an idea for JavaScript. I just never end up feeling like I would gain anything significant by porting that sketch to native JS.