samples/guiAndGfx: eC port of JFD's Mekano
[sdk] / samples / guiAndGfx / mekano / vector.ec
1 import IMPORT_STATIC "ecere"
2
3 struct Vector2D : Pointf
4 {
5    float dotProduct(Vector2D v)            { return x*v.x + y*v.y; }
6    void scale(Vector2D v, float s)         { this = { v.x*s, v.y*s }; }
7    void divide(Vector2D v, float s)        { this = { v.x/s, v.y/s }; }
8    void add(Vector2D a, Vector2D v)        { this = { a.x+v.x, a.y+v.y }; }
9    void subtract(Vector2D a, Vector2D v)   { this = { a.x-v.x, a.y-v.y }; }
10    void normalize()                        { float norm = length; this = norm ? { x / norm, y / norm } : { 0, 0 }; }
11
12    property float length                   { get { return (float)sqrt(x*x+y*y); } }
13    property Vector2D normal                { get { value = { -y, x }; value.normalize(); } }
14    property Vector2D unit                  { get { value = this; value.normalize(); } }
15 };