On Monday, 16 January 2012 at 17:57:38 UTC, suicide wrote:
Here is mine:
http://suicide.zoadian.de/ext/math/geometry/vector.d
i haven't tested (not even compiled) it yet. It needs
polishing, but i have not much time to work on it atm. But you
may use it as you wish ;)
Any suggestions/improvement is welcome.
Greetings,
Felix
Am 16.01.2012, 04:00 Uhr, schrieb Walter Bright
<[email protected]>:
On 1/15/2012 6:54 PM, JoeCoder wrote:
On 1/15/2012 1:42 PM, Walter Bright wrote:
A nice vector math library for D that puts us competitive
will be a nice
addition to Phobos.
The gl3n library might be something good to build on:
https://bitbucket.org/dav1d/gl3n
It looks to be a continuation of the OMG library used by
Deadlock, and is
similar to the glm (http://glm.g-truc.net) c++ library which
emulates glsl
vector ops in software.
We'd need to ask if it can be re-licensed from MIT to Boost.
I have never used libraries like that, and so it isn't obvious
to me what a good one would look like.
Nice start, though it have quite a few issues.
1. for (i; 0 .. D) needs to be: foreach (i; 0 .. D)
2. asserts(r != 0) should be done in a contract
3. 'Vector(D, T)' can be internally used as just 'Vector'
4. instead of making opAdd, opSub, opMul, etc.. use opBinary and
mixins
5. don't pass vectors as 'ref' unless they are going to be
modified
6. for performance, don't pass all values through 'real'
auto opBinary(string op, U)(U r)
if (U.sizeof <= T.sizeof && isImplicitlyConvertible(T, U))
in {
assert(r != 0);
}
body {
Vector nvec(this);
foreach (i; 0 .. D)
mixin("nvec.vec[i]" ~ op ~ "= r;");
return nvec;
}
auto opBinary(string op, U)(U r)
if (U.sizeof > T.sizeof && isImplicitlyConvertible(U, T))
in {
assert(r != 0);
}
body {
Vector nvec(this);
foreach (i; 0 .. D)
mixin("nvec.vec[i]" ~ op ~ "= cast(T) r;");
return nvec;
}
. . . . .
auto opBinary(string op, V, U)(Vector!(V, U) vec)
if (U.sizeof <= T.sizeof && isImplicitlyConvertible(U, T))
in {
foreach (i; 0 .. V)
assert(vec.vec[i] != 0);
}
body {
Vector nvec(this);
static if (D <= V) {
foreach (i; 0 .. D)
mixin("nvec.vec[i]" ~ op ~ "= vec.vec[i];");
}
else {
foreach (i; 0 .. V)
mixin("nvec.vec[i]" ~ op ~ "= vec.vec[i];");
}
return nvec;
}
// etc...
Something along those lines. Also, make sure you can't create a
vector of zero or one length (struct Vector(D, T) if (D >= 2) {
... }). Plus, none of your Vector(D,T) instances will compile
because you for the '!' mark: Vector!(D, T)