1 import IMPORT_STATIC "ecere"
3 struct Vector2D : Pointf
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 }; }
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(); } }