Re:Writing a small ray tracer in Rust and Zig
by tjelen on Tuesday July 02, 2019 @05:19AM
(#20333448)
So why not just write the original formula into the comment above the code? Maybe it's not the purest approach, but it sure would help parsing the code in this case.
[ Parent
| on HN ]
Re:Writing a small ray tracer in Rust and Zig
by minxomat on Tuesday July 02, 2019 @05:36AM
(#20333544)
Yep. If the code doesn't clearly show the original intent, document your intent in a comment next to the code so future you or others can double check. Esp in gfx engines where some blocks are just math translated one to one to code.
Re:Writing a small ray tracer in Rust and Zig
by pjc50 on Tuesday July 02, 2019 @09:52AM
(#20334957)
Why not one step further, and let the original formula be the code? Directly compilable Latex:
\vec r = \frac {n_{1}}{n_{2}} \cdot (\vec v - dot(\vec v, \vec n) \cdot \vec N) - \sqrt{1 - \frac {n_{1}^2}{n_{2}^2} \cdot (1 - dot(\vec v, \vec n))} \cdot \vec N
(This is partly a joke and partly a serious suggestion, there are definitely people out there who would find that easier to write, especially if the IDE rendered it properly. I stole it by searching for ni_over_nt and finding http://viclw17.github.io/2018/08/05/raytracing-dielectric-ma... )
Re:Writing a small ray tracer in Rust and Zig
by ddragon on Tuesday July 02, 2019 @11:47AM
(#20336231)
Julia (a language focused on science/math) does it partially. For example in the editor or REPL you can just type \sqrt [tab] \alpha [tab] and it will generate √α which is valid code. Most math symbols in unicode are supported and overloadable. And you can also write matrix like a table, such as
[1 2 3
4 5 6
7 8 9].
And you can transform Julia expressions to LaTeX:
https://github.com/korsbo/Latexify.jl
But even they didn't go as far as being able to parse full LaTeX expressions (though you technically could with reader macros plus editor support).