News for hackers. Stuff that matters.
Re:Introduction to the Math of Computer Graphics by overgard on Wednesday December 30, 2015 @11:48AM (#10812881)
Small thing, but some of the examples have some pretty bad undefined behavior bugs. For instance:

    Matrix& operator*( const double scalar,
                       const Matrix& rhs)
    {
      Matrix result(rhs);
      result *= scalar;
 
      return result;
    }
(Returning a reference to a stack variable is undefined behavior, but realistically you're probably either looking at a hard crash or a really hard to track down bug)
Re:Introduction to the Math of Computer Graphics by santaclaus on Wednesday December 30, 2015 @01:24PM (#10813406)
I wonder why they didn't simply nuke the reference and get move semantics? Or better yet, use expression templates.
Re:Introduction to the Math of Computer Graphics by codeofthedamned on Wednesday December 30, 2015 @11:40PM (#10816162)
I have corrected the code by removing the reference.

The way the code is now structured will allow for the RVO (Return-value optimization) to occur, so the new instance will be constructed in the location of the receiving object.

Move semantics would not apply in this case, it would actually suffer from a similar problem as the version that returned a reference, except the program would not crash. Instead the return value would contain garbage.

(edit: added a link to details on how to use move semantics) http://codeofthedamned.com/index.php/c-r-value-references

I did not use expression templates, or try to optimize any of the implementation because my intent is to demonstrate "how" to get started with the math. I also wanted to make the code accessible to programmers that do not use C++. For example, someone trying to learn WebGL.

Re:Introduction to the Math of Computer Graphics by codeofthedamned on Wednesday December 30, 2015 @11:33PM (#10816131)
Thanks for pointing out my mistake, I have corrected the code to simply return from the stack.
Re:Introduction to the Math of Computer Graphics by jheriko on Thursday December 31, 2015 @02:59AM (#10816748)
that should be a compile error, surely? 'returning a reference or address of a temporary' or similar... i guess warnings as errors and having warnings to the max has spoiled me.