Low dimensional matrices, vectors, quaternions and a cubic equation solver

Eric Poggel dnewsgroup at yage3d.net
Mon Apr 19 13:15:20 PDT 2010


On 4/19/2010 6:43 AM, Lars T. Kyllingstad wrote:
> IMO, general vectors/matrices should be structs wrapping a pointer to
> the data:
>
>    struct Vector(T)
>    {
>       T* ptr;
>       size_t length;
>       size_t stride;
>    }
>
> Low-dimensional fixed-size vectors should probably be value types.

I think it would be confusing to have some vectors as value and others 
as reference types, unless they were different types in the library itself.

I've always used two template parameters, one for type and another for 
size, but almost all my vectors are only 2-4 components.

struct Vector(T, S)
{
     T[S] values;
}

You can union things out from there so you can still have your .x/y/z 
properties without the overhead of a function call.



More information about the Digitalmars-d mailing list