|
Boost : |
From: Walter Landry (wlandry_at_[hidden])
Date: 2006-09-20 12:46:38
"Olivier Grant" <olivier.grant_at_[hidden]> wrote:
> Hi,
>
> I have written a bit of code to handle geometric vectors in a generic way,
> abstracting their dimension. The idea behind this code is to be able to
> apply one operation between two vectors, or a vector and a scalar, whatever
> their dimension, and writing it in an expandable way without having to
> modify any manipulation functions if a new geometric vector class is
> created. The other advantage is that the resulting assembly code is just as
> fast as if the functions had all been explicitly written.
Does this hold true if the equations get complicated (e.g. products of
products)?
> Right now I have three simple vector classes - ranging from vector2d to
> vector4d - that are not templetized since I like the idea of being able to
> access coordinates directly by their name
>
> vector3d vec;
> vec.x += 10.0f;
>
> to give you an example of the syntax, here is how you would add two vectors
> of different dimensions :
>
> vector2d v1(1.0f, 2.0f);
> vector3d v2(-1.0f, 3.0f, 2.0f);
> vector4d res;
>
> vector_add(v1, v2, res);
> /* res now contains (0.0f, 5.0f, 2.0f, 1.0f) */
This is a bit clunky. What about using the operator+() and operator=()?
> the result is determined by the dimension of the third vector passed to
> vector_add.
> v1 is auto-promoted to act like a vector3d.
This seems wrong. If I want to add a vector2d to a vector3d, then I
should have to do it manually. Otherwise, it should be a type error.
> v2 does not change.
> res gets (v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, default_w_value).
>
> I didn't seem to find any information on a lib currently under development
> that provides geometric vector manipulation in that way - maybe apart from
> uBLAS - so I thought I would share this if anyone seems to be interested.
What are the advantages of this library over tvmet[1]?
Cheers,
Walter Landry
wlandry_at_[hidden]
[1] http://tvmet.sourceforge.net/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk