News for hackers. Stuff that matters.
Re:Smallpt: Global Illumination in 99 lines of C++ by archgoon on Saturday February 04, 2017 @12:09AM (#13565731)
3325. I'm not quite sure why you're asking. This isn't about the size of the library, it's about the lines of code the programmer needs to write to express an idea.

If you are concerned about the size of the final binary, then as the author states, it's under 4k with a few optimizations.

Re:Smallpt: Global Illumination in 99 lines of C++ by echelon on Saturday February 04, 2017 @12:18AM (#13565758)
That's kind of ridiculous. Leveraging something someone else wrote does not mean you get to disclaim its role.

As an aside, this reminds me of XKCD's `import antigravity`.

Re:Smallpt: Global Illumination in 99 lines of C++ by Buge on Saturday February 04, 2017 @12:43AM (#13565823)
It's the standard library. It's not a library for graphics. Might as well credit your OS as well for providing a kernel that runs the program, and your CPU manufacturer for making a CPU that executes the instructions.

https://www.youtube.com/watch?v=5_vVGPy4-rc

Re:Smallpt: Global Illumination in 99 lines of C++ by santaclaus on Saturday February 04, 2017 @01:01AM (#13565866)
Sure, but where does the standard state that a #include of a standard header is a more proper atom than any other #include?
Re:Smallpt: Global Illumination in 99 lines of C++ by Buge on Saturday February 04, 2017 @01:32AM (#13565933)
Common sense states what a "proper atom" is.

If someone claimed "a string formatting tool in 2 lines of C++" and it was just fprintf, that's clearly the standard library doing the work, not the promoted file. In this case the standard library is not doing any global illumination or anything related. It's just doing IO.

Re:Smallpt: Global Illumination in 99 lines of C++ by Arelius on Saturday February 04, 2017 @03:00AM (#13566157)
For instance, in the C++ draft standard doc n3690. 17.6.1.3 you get

'The facilities of the C standard Library are provided in 26 additional headers, as shown in Table 15.'

'<cassert> <cinttypes> <csignal> <cstdio> <cwchar> <ccomplex> <ciso646> <cstdalign> <cstdlib> <cwctype> <cctype> <climits> <cstdarg> <cstring> <cerrno> <clocale> <cstdbool> <ctgmath> <cfenv> <cmath> <cstddef> <ctime> <cfloat> <csetjmp> <cstdint> <cuchar>'

and

'Except as noted in Clauses 18 through 30 and Annex D, the contents of each header c name shall be the same as that of the corresponding header name .h, as specified in the C standard library (1.2) or the C Unicode TR, as appropriate, as if by inclusion'

Among other bits. It's made very clear that the standard libraries are valid 'C++'.

Even that aside, here are the used symbols from those libs:

atoi fopen FILE fprintf M_PI fabs sqrt cos sin erand48

Which are all resonable functionality to expect in any programming environment. The first 4 are only used for I/O which are not exposed in the language otherwise. And can also be safely removed and "GI" still functions. It's just nice to be able to see the result.

The rest of the math functions are generally replaceable with varying amounts of code or by calling platform native instructions.

The only real stand out is erand48 which isn't actually part of the standard, but is easily replaceable by many other standard pseudo random implementations something like 'double erand48(){return (double)rand()/(double)MAX_RAND;}' or some such, or by implementing one of many pseudo random number generators.

In all, it's very fair to consider this 99 lines of C++ all the algorithmic components of a path tracer are shown in the code. External code is well within expectations. And there is no reason to consider the usage of stdio.h as something to be counted, while discounting all the code that goes into actually compiling and executing the code. Where the line is now is the most obvious place to draw it and where all sane C++ programmers would.

Re:Smallpt: Global Illumination in 99 lines of C++ by ben0x539 on Saturday February 04, 2017 @04:18AM (#13566350)
> atoi fopen FILE fprintf M_PI fabs sqrt cos sin erand48

They finally standardized M_PI? Sweet, that was always awkward.

Re:Smallpt: Global Illumination in 99 lines of C++ by khedoros1 on Saturday February 04, 2017 @01:12AM (#13565888)
Nowhere. The restrictions are arbitrary, but that's not the point. The point is that given the restrictions placed on it, it's a neat piece of code.
Re:Smallpt: Global Illumination in 99 lines of C++ by arjie on Saturday February 04, 2017 @12:41AM (#13565817)
The part where it references what someone else wrote is the 'of C++' part. The C++ language standard describes the standard library. The OpenMP enhancements aren't actually required (the code will compile as standard C++).

As such, it's pretty pure C++ really and anyone who writes the language commonly will understand what is meant.

Re:Smallpt: Global Illumination in 99 lines of C++ by johncolanduoni on Saturday February 04, 2017 @12:45AM (#13565827)
Or anyone who knows a language with a standard library for that matter :P
Re:Smallpt: Global Illumination in 99 lines of C++ by rootlocus on Saturday February 04, 2017 @02:36AM (#13566091)
Why stop at library code? How about the compiler? The operating system? The CPU? The tranzistor? The power source?

By that logic: "If you wish to make an apple pie from scratch, you must first invent the universe" (quote by Carl Sagan).

Re:Smallpt: Global Illumination in 99 lines of C++ by santaclaus on Saturday February 04, 2017 @12:11AM (#13565738)
Sure. With the right abstraction that will be 2 lines of code.
Re:Smallpt: Global Illumination in 99 lines of C++ by johncolanduoni on Saturday February 04, 2017 @12:25AM (#13565778)
So which part of the standard library is geared towards global illumination? I must have glossed over that one.
Re:Smallpt: Global Illumination in 99 lines of C++ by santaclaus on Saturday February 04, 2017 @12:38AM (#13565810)
Where here was the standard library laid out as the axiomatic atom of line counting?
Re:Smallpt: Global Illumination in 99 lines of C++ by johncolanduoni on Saturday February 04, 2017 @12:43AM (#13565825)
In the title, where they say "99 lines of C++".
Re:Smallpt: Global Illumination in 99 lines of C++ by Cyph0n on Saturday February 04, 2017 @12:15AM (#13565750)
If you limit it to the stdlib only, I highly doubt that's possible. I am a C++ noob, so I might be wrong.
Re:Smallpt: Global Illumination in 99 lines of C++ by kr7 on Saturday February 04, 2017 @12:53AM (#13565846)
Two lines, no more than 70 characters each.

(Okay, it isn't just limited to the stdlib: you'll need curl and gcc too.)

(Also: obviously, RUN THIS WITH CAUTION!)

    #include <stdlib.h>
    int main(){system("curl -o x -L bit.ly/2kbOUJr;g++ -xc++ -oy x;./y");}
Re:Smallpt: Global Illumination in 99 lines of C++ by Arelius on Saturday February 04, 2017 @03:05AM (#13566172)
Sure if your title is "Global Illumination in 2 lines of C++, with curl, and g++, and libraries hosted on bit.ly". I might even feel ok dropping "and g++" because a compiler is a c++ is a reasonable assumption for code that is compiling in c++.

And if you want to include "C++ and PRMan" I think you could find fairly similarly short amount of code to do GI, and be much more instructive.

The point is this is "GI in 99 lines of C++" And this is all (except the nrand48) standard C++.

Re:Smallpt: Global Illumination in 99 lines of C++ by Cyph0n on Saturday February 04, 2017 @01:15AM (#13565893)
Reminds me of the xkcd-inspired[1] stacksort: https://gkoberger.github.io/stacksort/. But yeah, that's cheating man :P

[1]: https://xkcd.com/1185/