higgsjs / Higgs

Higgs JavaScript Virtual Machine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lib/draw should accept FP coordinates/values

maximecb opened this issue · comments

I ran into an issue while using lib/draw, particularly the drawPoint function. I was supplying integer coordinates, but the values were internally stored as the f64 type (output of Math.floor). The calls to drawPoint simply didn't draw anything on the screen.

I remembered a previous discussion we had and use a trick to force an integer conversion. However, I think this issue needs to be fixed. Newbies will surely find it very confusing.

commented

ES6 has Math.fround, but on every call to drawPoint rounding and conversion may get expensive.
Maybe parseInt on xy if it contains "." ? May be the least complicated fix ?

Not sure the efficiency of parseInt, or match on every call either.

Oh, and I'm referring to only the drawPoint function

Both of these are unfortunately pretty slow. I particularly care about the performance of drawPoint, so I would have that one directly use $ir_is_int32(x) before making a call. The other functions could use $rt_toInt32(x).

commented

Hmm..im thinking those IR functions may beat other FP to int conversion methods, like Mozillas fround..possibly

They're more direct ways of telling Higgs what you want to do. The parseInt function is not optimized for performance, and there's some dynamic lookup overhead.