Quick actions

cmd+k|ctrl+k

Navigation

Languages

Vector member function

Snippet info

Language

Cpp

Visibility

public

Author

evine

Created

2016-01-25T03:29:20Z

Updated

2016-01-25T03:29:20Z

#include <stdio.h>
#include <math.h>

float
v2Length(float x,float y)
{
    return sqrt(x*x+y*y);
}

struct v2 {
    union {
        struct {
            float x;
            float y;
        };
        float e[2];
    };
    float
    Length()
    {
        return v2Length(x,y);
    };
};

float
v2Length(v2 a)
{
    return v2Length(a.x,a.y);
}


int main() {
    
    printf("%f\n", v2Length(8,6)        );
    printf("%f\n", v2Length(v2{8,6})    );
    printf("%f\n", v2{8,6}.Length()     ); // Is this a gain???
    return 0;
}
INFO