schveiguy / raylib-d

Resurrected copy of onroundit's raylib-d
zlib License
55 stars 14 forks source link

Using arrays in vectors #36

Closed al1-ce closed 1 year ago

al1-ce commented 1 year ago

Have vectors in this format:

struct Vector2 {
    float data[2] = [0.0f, 0.0f];
    alias data this;
    void x(float _x) { x = _x;} 
    float x() { return x;} 
    // same for y
    mixin Linear;
}

To allow usage of other libraries/custom vector implementations

schveiguy commented 1 year ago

Unfortunately this would be a breaking change, as &v.x would become a delegate.

al1-ce commented 1 year ago

I assume aliases would do something similar then Well, making my own wrapper anyway

Still, toArray and fromArray would be appreciated if not a burden to do

schveiguy commented 1 year ago

Such an implementation is trivial, if you want to include it for your external projects.

ref float[2] asArray(ref Vector2 v)
{
   return *cast(float[2]*)&v;
}

v.asArray[0] = 5;
assert(v.x == 5);