www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - how to implement vector structs with different number of components

reply Trass3r <un known.com> writes:
Is there maybe a way to implement commonly needed vector classes Vec2,  
Vec3, Vec4 without having to implement the same basic code over and over  
again?
Mar 12 2010
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
Trass3r:
 Is there maybe a way to implement commonly needed vector classes Vec2,  
 Vec3, Vec4 without having to implement the same basic code over and over  
 again?

I have implemented a generic nD vector struct for D1. When I have translated it to D2 I can show it and Andrei may add it to Phobos, because everyone and their uncle need vectors. There are several ways to implement a generic nD vector, the size is a template argument, and templates or CTFT + string mixin allow you to perform the operations with no loops in the final code. Bye, bearophile
Mar 12 2010
prev sibling next sibling parent Robert Clipsham <robert octarineparrot.com> writes:
On 12/03/10 23:20, Trass3r wrote:
 Is there maybe a way to implement commonly needed vector classes Vec2,
 Vec3, Vec4 without having to implement the same basic code over and over
 again?

The following are a few libraries that have already implemented vector classes/structs for Vec2 .. Vec4, they might give you some ideas should you decide to roll your own :) http://team0xf.com:8080/maths/file/tip/Vec.d http://dsource.org/projects/scrapple/browser/trunk/tools/tools/vector.d
Mar 12 2010
prev sibling parent Trass3r <un known.com> writes:
Am 13.03.2010, 01:29 Uhr, schrieb bearophile <bearophileHUGS lycos.com>:

 I have implemented a generic nD vector struct for D1. When I have  
 translated it to D2 I can show it and Andrei may add it to Phobos,  
 because everyone and their uncle need vectors.

Have you done so yet?
Apr 22 2010