Note that there are some explanatory texts on larger screens.

plurals
  1. POVector, Matrix, Algebra class Design
    primarykey
    data
    text
    <p>I am in the process of designing a maths library. I want to start with a simple vector 4 and a matrix 4x4 and I'll extend it with the needs. I am trying to pro and cons of several design I have seen so that I can choose. I find it frustrating I searched a lot, I found a lot but almost no answer were talking about efficiency of the design which is critical for a maths library.</p> <p>What I am taking into consideration, compiler are amazing now a days I know I can't be smarter that the compiler, but I want to help him to the max. C++11 is bringing good stuff, like move semantics and other stuff like std::tuple....</p> <p>From what I know the data should be stored in continuous memory.</p> <p>Where I am a bit lost and need more info is:</p> <p>A) Should the data be: value_type[ Rows * Cols] (simple c array) or value_type* (allocated on the heap of size Rows * Cols) or use something like std::tuple</p> <p>B) Also Inheritance or composition/aggregation I could have a template base class for the data or I could do it with composition/aggregation</p> <p>C) I saw 3 layout of the data</p> <ul> <li>a struct and union (like in this article <a href="http://www.gamasutra.com/view/feature/4248/designing_fast_crossplatform_simd_.php" rel="nofollow">http://www.gamasutra.com/view/feature/4248/designing_fast_crossplatform_simd_.php</a>)</li> <li>a simple member variable</li> <li>another one used static pointer to member instead of a union. (<a href="http://www.gamedev.net/topic/261920-a-slick-trick-in-c/" rel="nofollow">http://www.gamedev.net/topic/261920-a-slick-trick-in-c/</a>)</li> </ul> <p>D) Also in the gamasutra article (which seem to be old and compiler are better now) He say that the class should not have operator overload and that global function should be used instead. For example the crossProduct function to make it non-member instead of a member function.</p> <p>I have all of those question, I know there is a lot. What are your take on those, especially on A and C.</p> <p>Edit:</p> <p>Thanks all for those answer for the point A, I must say that at the moment my biggest question is with point C, sorry I know it wasn't clear. Point c is really about the design of the classes. I saw 2 option (kind of three if you consider this static trick <a href="http://www.gamedev.net/topic/261920-a-slick-trick-in-c/" rel="nofollow">http://www.gamedev.net/topic/261920-a-slick-trick-in-c/</a>) I could have for a Vector4 in example I could have members of x, y, z and w publicly available or I could also make a union with those members and an array, or I could have only an array and have functions X(), Y(), Z(), W() for accessor. And finally there is the static trick that I provided the link just above but I would prefer if the x,y,z and w would be static and the array would be the data member.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload