Dart Documentationvector_mathvec2

vec2 class

class vec2 {
 double x;
 double y;
 /// Constructs a new [vec2]. Follows GLSL constructor syntax so many combinations are possible
 vec2([dynamic x_, dynamic y_]) {
   x = y = 0.0;
   if (x_ is vec2) {
     xy = x_.xy;
     return;
   }
   if (x_ is num && y_ is num) {
     x = x_.toDouble();
     y = y_.toDouble();
     return;
   }
   if (x_ is num) {
     x = y = x_.toDouble();
     return;
   }
 }
 /// Constructs a new [vec2] zero vector.
 vec2.zero() { makeZero(); }
 /// Make [this] the zero vector.
 vec2 makeZero() {
   x = 0.0;
   y = 0.0;
   return this;
 }
 /// Constructs a copy of [other].
 vec2.copy(vec2 other) {
   makeCopy(other);
 }
 /// Make [this] a copy of [other] [other].
 vec2 makeCopy(vec2 other) {
   x = other.x;
   y = other.y;
   return this;
 }
 /// Constructs a new [vec2] that is initialized with passed in values.
 vec2.raw(num x_, num y_) {
   makeRaw(x_, y_);
 }
 /// Components of [this] are set to the passed in values.
 vec2 makeRaw(num x_, num y_) {
   x = x_.toDouble();
   y = y_.toDouble();
   return this;
 }
 /// Constructs a new [vec2] that is initialized with values from [array] starting at [offset].
 vec2.array(List<num> array, [int offset=0]) {
   int i = offset;
   x = array[i].toDouble();
   i++;
   y = array[i].toDouble();
   i++;
 }
 /// Splats a scalar into all lanes of the vector.
 vec2 splat(num arg) {
   double a = arg.toDouble();
   x = a;
   y = a;
   return this;
 }
 /// Returns a printable string
 String toString() => '$x,$y';
 /// Returns a new vec2 from -this
 vec2 operator-() => new vec2.raw(-x, -y);
 /// Returns a new vec2 from this - [other]
 vec2 operator-(vec2 other) => new vec2.raw(x - other.x, y - other.y);
 /// Returns a new vec2 from this + [other]
 vec2 operator+(vec2 other) => new vec2.raw(x + other.x, y + other.y);
 /// Returns a new vec2 divided by [other]
 vec2 operator/(dynamic other) {
   if (other is num) {
     var o = 1.0 / other.toDouble();
     return new vec2.raw(x * o, y * o);
   }
   if (other is vec2) {
     return new vec2.raw(x / other.x, y / other.y);
   }
 }
 /// Returns a new vec2 scaled by [other]
 vec2 operator*(dynamic other) {
   if (other is num) {
     var o = other.toDouble();
     return new vec2.raw(x * o, y * o);
   }
   if (other is vec2) {
     return new vec2.raw(x * other.x, y * other.y);
   }
 }
 /// Returns a component from vec2. This is indexed as an array with [i]
 double operator[](int i) {
   assert(i >= 0 && i < 2);
   switch (i) {
     case 0: return x;
     case 1: return y;
   };
   return 0.0;
 }
 /// Assigns a component in vec2 the value in [v]. This is indexed as an array with [i]
 void operator[]=(int i, double v) {
   assert(i >= 0 && i < 2);
   switch (i) {
     case 0: x = v; break;
     case 1: y = v; break;
   };
 }
 /// Returns length of this
 double get length {
   double sum = 0.0;
   sum += (x * x);
   sum += (y * y);
   return Math.sqrt(sum);
 }
 /// Returns squared length of this
 double get length2 {
   double sum = 0.0;
   sum += (x * x);
   sum += (y * y);
   return sum;
 }
 /// Normalizes [this]. Returns [this].
 vec2 normalize() {
   double l = length;
   if (l == 0.0) {
     return this;
   }
   x /= l;
   y /= l;
   return this;
 }
 /// Normalizes [this]. Returns length.
 double normalizeLength() {
   double l = length;
   if (l == 0.0) {
     return 0.0;
   }
   x /= l;
   y /= l;
   return l;
 }
 /// Normalizes [this] returns new vector or optional [out]
 vec2 normalized([vec2 out = null]) {
   if (out == null) {
     out = new vec2.raw(x, y);
   }
   double l = out.length;
   if (l == 0.0) {
     return out;
   }
   out.x /= l;
   out.y /= l;
   return out;
 }
 /// Returns the dot product of [this] and [other]
 double dot(vec2 other) {
   double sum = 0.0;
   sum += (x * other.x);
   sum += (y * other.y);
   return sum;
 }
 /// Returns the cross product of [this] and [other], optionally pass in output storage [out]
 double cross(vec2 other) {
   return x * other.y - y * other.x;
 }
 /// Returns the relative error between [this] and [correct]
 double relativeError(vec2 correct) {
   double correct_norm = correct.length;
   double diff_norm = (this - correct).length;
   return diff_norm/correct_norm;
 }
 /// Returns the absolute error between [this] and [correct]
 double absoluteError(vec2 correct) {
   return (this - correct).length;
 }
 set xy(vec2 arg) {
   x = arg.x;
   y = arg.y;
 }
 set yx(vec2 arg) {
   y = arg.x;
   x = arg.y;
 }
 /// Returns true if any component is infinite.
 bool get isInfinite {
   bool is_infinite = false;
   is_infinite = is_infinite || x.isInfinite;
   is_infinite = is_infinite || y.isInfinite;
   return is_infinite;
 }
 /// Returns true if any component is NaN.
 bool get isNaN {
   bool is_nan = false;
   is_nan = is_nan || x.isNaN;
   is_nan = is_nan || y.isNaN;
   return is_nan;
 }
 set r(double arg) => x = arg;
 set g(double arg) => y = arg;
 set s(double arg) => x = arg;
 set t(double arg) => y = arg;
 set rg(vec2 arg) {
   r = arg.r;
   g = arg.g;
 }
 set gr(vec2 arg) {
   g = arg.r;
   r = arg.g;
 }
 set st(vec2 arg) {
   s = arg.s;
   t = arg.t;
 }
 set ts(vec2 arg) {
   t = arg.s;
   s = arg.t;
 }
 vec2 get xx => new vec2(x, x);
 vec2 get xy => new vec2(x, y);
 vec2 get yx => new vec2(y, x);
 vec2 get yy => new vec2(y, y);
 vec3 get xxx => new vec3(x, x, x);
 vec3 get xxy => new vec3(x, x, y);
 vec3 get xyx => new vec3(x, y, x);
 vec3 get xyy => new vec3(x, y, y);
 vec3 get yxx => new vec3(y, x, x);
 vec3 get yxy => new vec3(y, x, y);
 vec3 get yyx => new vec3(y, y, x);
 vec3 get yyy => new vec3(y, y, y);
 vec4 get xxxx => new vec4(x, x, x, x);
 vec4 get xxxy => new vec4(x, x, x, y);
 vec4 get xxyx => new vec4(x, x, y, x);
 vec4 get xxyy => new vec4(x, x, y, y);
 vec4 get xyxx => new vec4(x, y, x, x);
 vec4 get xyxy => new vec4(x, y, x, y);
 vec4 get xyyx => new vec4(x, y, y, x);
 vec4 get xyyy => new vec4(x, y, y, y);
 vec4 get yxxx => new vec4(y, x, x, x);
 vec4 get yxxy => new vec4(y, x, x, y);
 vec4 get yxyx => new vec4(y, x, y, x);
 vec4 get yxyy => new vec4(y, x, y, y);
 vec4 get yyxx => new vec4(y, y, x, x);
 vec4 get yyxy => new vec4(y, y, x, y);
 vec4 get yyyx => new vec4(y, y, y, x);
 vec4 get yyyy => new vec4(y, y, y, y);
 double get r => x;
 double get g => y;
 double get s => x;
 double get t => y;
 vec2 get rr => new vec2(r, r);
 vec2 get rg => new vec2(r, g);
 vec2 get gr => new vec2(g, r);
 vec2 get gg => new vec2(g, g);
 vec3 get rrr => new vec3(r, r, r);
 vec3 get rrg => new vec3(r, r, g);
 vec3 get rgr => new vec3(r, g, r);
 vec3 get rgg => new vec3(r, g, g);
 vec3 get grr => new vec3(g, r, r);
 vec3 get grg => new vec3(g, r, g);
 vec3 get ggr => new vec3(g, g, r);
 vec3 get ggg => new vec3(g, g, g);
 vec4 get rrrr => new vec4(r, r, r, r);
 vec4 get rrrg => new vec4(r, r, r, g);
 vec4 get rrgr => new vec4(r, r, g, r);
 vec4 get rrgg => new vec4(r, r, g, g);
 vec4 get rgrr => new vec4(r, g, r, r);
 vec4 get rgrg => new vec4(r, g, r, g);
 vec4 get rggr => new vec4(r, g, g, r);
 vec4 get rggg => new vec4(r, g, g, g);
 vec4 get grrr => new vec4(g, r, r, r);
 vec4 get grrg => new vec4(g, r, r, g);
 vec4 get grgr => new vec4(g, r, g, r);
 vec4 get grgg => new vec4(g, r, g, g);
 vec4 get ggrr => new vec4(g, g, r, r);
 vec4 get ggrg => new vec4(g, g, r, g);
 vec4 get gggr => new vec4(g, g, g, r);
 vec4 get gggg => new vec4(g, g, g, g);
 vec2 get ss => new vec2(s, s);
 vec2 get st => new vec2(s, t);
 vec2 get ts => new vec2(t, s);
 vec2 get tt => new vec2(t, t);
 vec3 get sss => new vec3(s, s, s);
 vec3 get sst => new vec3(s, s, t);
 vec3 get sts => new vec3(s, t, s);
 vec3 get stt => new vec3(s, t, t);
 vec3 get tss => new vec3(t, s, s);
 vec3 get tst => new vec3(t, s, t);
 vec3 get tts => new vec3(t, t, s);
 vec3 get ttt => new vec3(t, t, t);
 vec4 get ssss => new vec4(s, s, s, s);
 vec4 get ssst => new vec4(s, s, s, t);
 vec4 get ssts => new vec4(s, s, t, s);
 vec4 get sstt => new vec4(s, s, t, t);
 vec4 get stss => new vec4(s, t, s, s);
 vec4 get stst => new vec4(s, t, s, t);
 vec4 get stts => new vec4(s, t, t, s);
 vec4 get sttt => new vec4(s, t, t, t);
 vec4 get tsss => new vec4(t, s, s, s);
 vec4 get tsst => new vec4(t, s, s, t);
 vec4 get tsts => new vec4(t, s, t, s);
 vec4 get tstt => new vec4(t, s, t, t);
 vec4 get ttss => new vec4(t, t, s, s);
 vec4 get ttst => new vec4(t, t, s, t);
 vec4 get ttts => new vec4(t, t, t, s);
 vec4 get tttt => new vec4(t, t, t, t);
 vec2 add(vec2 arg) {
   x = x + arg.x;
   y = y + arg.y;
   return this;
 }
 vec2 sub(vec2 arg) {
   x = x - arg.x;
   y = y - arg.y;
   return this;
 }
 vec2 multiply(vec2 arg) {
   x = x * arg.x;
   y = y * arg.y;
   return this;
 }
 vec2 div(vec2 arg) {
   x = x / arg.x;
   y = y / arg.y;
   return this;
 }
 vec2 scale(num arg) {
   double a = arg.toDouble();
   x = x * a;
   y = y * a;
   return this;
 }
 vec2 scaled(num arg) {
   return clone().scale(arg);
 }
 vec2 negate() {
   x = -x;
   y = -y;
   return this;
 }
 vec2 absolute() {
   x = x.abs();
   y = y.abs();
   return this;
 }
 vec2 clone() {
   return new vec2.copy(this);
 }
 vec2 copyInto(vec2 arg) {
   arg.x = x;
   arg.y = y;
   return arg;
 }
 vec2 copyFrom(vec2 arg) {
   x = arg.x;
   y = arg.y;
   return this;
 }
 vec2 set(vec2 arg) {
   x = arg.x;
   y = arg.y;
   return this;
 }
 vec2 setComponents(num x_, num y_) {
   x = x_.toDouble();
   y = y_.toDouble();
   return this;
 }
 /// Copies [this] into [array] starting at [offset].
 void copyIntoArray(List<num> array, [int offset=0]) {
   int i = offset;
   array[i] = x;
   i++;
   array[i] = y;
   i++;
 }
 /// Copies elements from [array] into [this] starting at [offset].
 void copyFromArray(List<num> array, [int offset=0]) {
   int i = offset;
   x = array[i].toDouble();
   i++;
   y = array[i].toDouble();
   i++;
 }
}

Constructors

new vec2([x_, y_]) #

Constructs a new vec2. Follows GLSL constructor syntax so many combinations are possible

vec2([dynamic x_, dynamic y_]) {
 x = y = 0.0;
 if (x_ is vec2) {
   xy = x_.xy;
   return;
 }
 if (x_ is num && y_ is num) {
   x = x_.toDouble();
   y = y_.toDouble();
   return;
 }
 if (x_ is num) {
   x = y = x_.toDouble();
   return;
 }
}

new vec2.array(List<num> array, [int offset = 0]) #

Constructs a new vec2 that is initialized with values from array starting at offset.

vec2.array(List<num> array, [int offset=0]) {
 int i = offset;
 x = array[i].toDouble();
 i++;
 y = array[i].toDouble();
 i++;
}

new vec2.copy(vec2 other) #

Constructs a copy of other.

vec2.copy(vec2 other) {
 makeCopy(other);
}

new vec2.raw(num x_, num y_) #

Constructs a new vec2 that is initialized with passed in values.

vec2.raw(num x_, num y_) {
 makeRaw(x_, y_);
}

new vec2.zero() #

Constructs a new vec2 zero vector.

vec2.zero() { makeZero(); }

Properties

double g #

double get g => y;
set g(double arg) => y = arg;

final vec2 gg #

vec2 get gg => new vec2(g, g);

final vec3 ggg #

vec3 get ggg => new vec3(g, g, g);

final vec4 gggg #

vec4 get gggg => new vec4(g, g, g, g);

final vec4 gggr #

vec4 get gggr => new vec4(g, g, g, r);

final vec3 ggr #

vec3 get ggr => new vec3(g, g, r);

final vec4 ggrg #

vec4 get ggrg => new vec4(g, g, r, g);

final vec4 ggrr #

vec4 get ggrr => new vec4(g, g, r, r);

vec2 gr #

vec2 get gr => new vec2(g, r);
set gr(vec2 arg) {
 g = arg.r;
 r = arg.g;
}

final vec3 grg #

vec3 get grg => new vec3(g, r, g);

final vec4 grgg #

vec4 get grgg => new vec4(g, r, g, g);

final vec4 grgr #

vec4 get grgr => new vec4(g, r, g, r);

final vec3 grr #

vec3 get grr => new vec3(g, r, r);

final vec4 grrg #

vec4 get grrg => new vec4(g, r, r, g);

final vec4 grrr #

vec4 get grrr => new vec4(g, r, r, r);

final bool isInfinite #

Returns true if any component is infinite.

bool get isInfinite {
 bool is_infinite = false;
 is_infinite = is_infinite || x.isInfinite;
 is_infinite = is_infinite || y.isInfinite;
 return is_infinite;
}

final bool isNaN #

Returns true if any component is NaN.

bool get isNaN {
 bool is_nan = false;
 is_nan = is_nan || x.isNaN;
 is_nan = is_nan || y.isNaN;
 return is_nan;
}

final double length #

Returns length of this

double get length {
 double sum = 0.0;
 sum += (x * x);
 sum += (y * y);
 return Math.sqrt(sum);
}

final double length2 #

Returns squared length of this

double get length2 {
 double sum = 0.0;
 sum += (x * x);
 sum += (y * y);
 return sum;
}

double r #

double get r => x;
set r(double arg) => x = arg;

vec2 rg #

vec2 get rg => new vec2(r, g);
set rg(vec2 arg) {
 r = arg.r;
 g = arg.g;
}

final vec3 rgg #

vec3 get rgg => new vec3(r, g, g);

final vec4 rggg #

vec4 get rggg => new vec4(r, g, g, g);

final vec4 rggr #

vec4 get rggr => new vec4(r, g, g, r);

final vec3 rgr #

vec3 get rgr => new vec3(r, g, r);

final vec4 rgrg #

vec4 get rgrg => new vec4(r, g, r, g);

final vec4 rgrr #

vec4 get rgrr => new vec4(r, g, r, r);

final vec2 rr #

vec2 get rr => new vec2(r, r);

final vec3 rrg #

vec3 get rrg => new vec3(r, r, g);

final vec4 rrgg #

vec4 get rrgg => new vec4(r, r, g, g);

final vec4 rrgr #

vec4 get rrgr => new vec4(r, r, g, r);

final vec3 rrr #

vec3 get rrr => new vec3(r, r, r);

final vec4 rrrg #

vec4 get rrrg => new vec4(r, r, r, g);

final vec4 rrrr #

vec4 get rrrr => new vec4(r, r, r, r);

double s #

double get s => x;
set s(double arg) => x = arg;

final vec2 ss #

vec2 get ss => new vec2(s, s);

final vec3 sss #

vec3 get sss => new vec3(s, s, s);

final vec4 ssss #

vec4 get ssss => new vec4(s, s, s, s);

final vec4 ssst #

vec4 get ssst => new vec4(s, s, s, t);

final vec3 sst #

vec3 get sst => new vec3(s, s, t);

final vec4 ssts #

vec4 get ssts => new vec4(s, s, t, s);

final vec4 sstt #

vec4 get sstt => new vec4(s, s, t, t);

vec2 st #

vec2 get st => new vec2(s, t);
set st(vec2 arg) {
 s = arg.s;
 t = arg.t;
}

final vec3 sts #

vec3 get sts => new vec3(s, t, s);

final vec4 stss #

vec4 get stss => new vec4(s, t, s, s);

final vec4 stst #

vec4 get stst => new vec4(s, t, s, t);

final vec3 stt #

vec3 get stt => new vec3(s, t, t);

final vec4 stts #

vec4 get stts => new vec4(s, t, t, s);

final vec4 sttt #

vec4 get sttt => new vec4(s, t, t, t);

double t #

double get t => y;
set t(double arg) => y = arg;

vec2 ts #

vec2 get ts => new vec2(t, s);
set ts(vec2 arg) {
 t = arg.s;
 s = arg.t;
}

final vec3 tss #

vec3 get tss => new vec3(t, s, s);

final vec4 tsss #

vec4 get tsss => new vec4(t, s, s, s);

final vec4 tsst #

vec4 get tsst => new vec4(t, s, s, t);

final vec3 tst #

vec3 get tst => new vec3(t, s, t);

final vec4 tsts #

vec4 get tsts => new vec4(t, s, t, s);

final vec4 tstt #

vec4 get tstt => new vec4(t, s, t, t);

final vec2 tt #

vec2 get tt => new vec2(t, t);

final vec3 tts #

vec3 get tts => new vec3(t, t, s);

final vec4 ttss #

vec4 get ttss => new vec4(t, t, s, s);

final vec4 ttst #

vec4 get ttst => new vec4(t, t, s, t);

final vec3 ttt #

vec3 get ttt => new vec3(t, t, t);

final vec4 ttts #

vec4 get ttts => new vec4(t, t, t, s);

final vec4 tttt #

vec4 get tttt => new vec4(t, t, t, t);

double x #

double x

final vec2 xx #

vec2 get xx => new vec2(x, x);

final vec3 xxx #

vec3 get xxx => new vec3(x, x, x);

final vec4 xxxx #

vec4 get xxxx => new vec4(x, x, x, x);

final vec4 xxxy #

vec4 get xxxy => new vec4(x, x, x, y);

final vec3 xxy #

vec3 get xxy => new vec3(x, x, y);

final vec4 xxyx #

vec4 get xxyx => new vec4(x, x, y, x);

final vec4 xxyy #

vec4 get xxyy => new vec4(x, x, y, y);

vec2 xy #

vec2 get xy => new vec2(x, y);
set xy(vec2 arg) {
 x = arg.x;
 y = arg.y;
}

final vec3 xyx #

vec3 get xyx => new vec3(x, y, x);

final vec4 xyxx #

vec4 get xyxx => new vec4(x, y, x, x);

final vec4 xyxy #

vec4 get xyxy => new vec4(x, y, x, y);

final vec3 xyy #

vec3 get xyy => new vec3(x, y, y);

final vec4 xyyx #

vec4 get xyyx => new vec4(x, y, y, x);

final vec4 xyyy #

vec4 get xyyy => new vec4(x, y, y, y);

double y #

double y

vec2 yx #

vec2 get yx => new vec2(y, x);
set yx(vec2 arg) {
 y = arg.x;
 x = arg.y;
}

final vec3 yxx #

vec3 get yxx => new vec3(y, x, x);

final vec4 yxxx #

vec4 get yxxx => new vec4(y, x, x, x);

final vec4 yxxy #

vec4 get yxxy => new vec4(y, x, x, y);

final vec3 yxy #

vec3 get yxy => new vec3(y, x, y);

final vec4 yxyx #

vec4 get yxyx => new vec4(y, x, y, x);

final vec4 yxyy #

vec4 get yxyy => new vec4(y, x, y, y);

final vec2 yy #

vec2 get yy => new vec2(y, y);

final vec3 yyx #

vec3 get yyx => new vec3(y, y, x);

final vec4 yyxx #

vec4 get yyxx => new vec4(y, y, x, x);

final vec4 yyxy #

vec4 get yyxy => new vec4(y, y, x, y);

final vec3 yyy #

vec3 get yyy => new vec3(y, y, y);

final vec4 yyyx #

vec4 get yyyx => new vec4(y, y, y, x);

final vec4 yyyy #

vec4 get yyyy => new vec4(y, y, y, y);

Operators

double operator [](int i) #

Returns a component from vec2. This is indexed as an array with i

double operator[](int i) {
 assert(i >= 0 && i < 2);
 switch (i) {
   case 0: return x;
   case 1: return y;
 };
 return 0.0;
}

void operator []=(int i, double v) #

Assigns a component in vec2 the value in v. This is indexed as an array with i

void operator[]=(int i, double v) {
 assert(i >= 0 && i < 2);
 switch (i) {
   case 0: x = v; break;
   case 1: y = v; break;
 };
}

vec2 operator +(vec2 other) #

Returns a new vec2 from this + other

vec2 operator+(vec2 other) => new vec2.raw(x + other.x, y + other.y);

vec2 operator -() #

Returns a new vec2 from -this

vec2 operator-() => new vec2.raw(-x, -y);

vec2 operator -(vec2 other) #

Returns a new vec2 from this - other

vec2 operator-(vec2 other) => new vec2.raw(x - other.x, y - other.y);

vec2 operator *(other) #

Returns a new vec2 scaled by other

vec2 operator*(dynamic other) {
 if (other is num) {
   var o = other.toDouble();
   return new vec2.raw(x * o, y * o);
 }
 if (other is vec2) {
   return new vec2.raw(x * other.x, y * other.y);
 }
}

vec2 operator /(other) #

Returns a new vec2 divided by other

vec2 operator/(dynamic other) {
 if (other is num) {
   var o = 1.0 / other.toDouble();
   return new vec2.raw(x * o, y * o);
 }
 if (other is vec2) {
   return new vec2.raw(x / other.x, y / other.y);
 }
}

Methods

vec2 absolute() #

vec2 absolute() {
 x = x.abs();
 y = y.abs();
 return this;
}

double absoluteError(vec2 correct) #

Returns the absolute error between this and correct

double absoluteError(vec2 correct) {
 return (this - correct).length;
}

vec2 add(vec2 arg) #

vec2 add(vec2 arg) {
 x = x + arg.x;
 y = y + arg.y;
 return this;
}

vec2 clone() #

vec2 clone() {
 return new vec2.copy(this);
}

vec2 copyFrom(vec2 arg) #

vec2 copyFrom(vec2 arg) {
 x = arg.x;
 y = arg.y;
 return this;
}

void copyFromArray(List<num> array, [int offset = 0]) #

Copies elements from array into this starting at offset.

void copyFromArray(List<num> array, [int offset=0]) {
 int i = offset;
 x = array[i].toDouble();
 i++;
 y = array[i].toDouble();
 i++;
}

vec2 copyInto(vec2 arg) #

vec2 copyInto(vec2 arg) {
 arg.x = x;
 arg.y = y;
 return arg;
}

void copyIntoArray(List<num> array, [int offset = 0]) #

Copies this into array starting at offset.

void copyIntoArray(List<num> array, [int offset=0]) {
 int i = offset;
 array[i] = x;
 i++;
 array[i] = y;
 i++;
}

double cross(vec2 other) #

Returns the cross product of this and other, optionally pass in output storage out

double cross(vec2 other) {
 return x * other.y - y * other.x;
}

vec2 div(vec2 arg) #

vec2 div(vec2 arg) {
 x = x / arg.x;
 y = y / arg.y;
 return this;
}

double dot(vec2 other) #

Returns the dot product of this and other

double dot(vec2 other) {
 double sum = 0.0;
 sum += (x * other.x);
 sum += (y * other.y);
 return sum;
}

vec2 makeCopy(vec2 other) #

Make this a copy of [other] [other].

vec2 makeCopy(vec2 other) {
 x = other.x;
 y = other.y;
 return this;
}

vec2 makeRaw(num x_, num y_) #

Components of this are set to the passed in values.

vec2 makeRaw(num x_, num y_) {
 x = x_.toDouble();
 y = y_.toDouble();
 return this;
}

vec2 makeZero() #

Make this the zero vector.

vec2 makeZero() {
 x = 0.0;
 y = 0.0;
 return this;
}

vec2 multiply(vec2 arg) #

vec2 multiply(vec2 arg) {
 x = x * arg.x;
 y = y * arg.y;
 return this;
}

vec2 negate() #

vec2 negate() {
 x = -x;
 y = -y;
 return this;
}

vec2 normalize() #

Normalizes this. Returns this.

vec2 normalize() {
 double l = length;
 if (l == 0.0) {
   return this;
 }
 x /= l;
 y /= l;
 return this;
}

vec2 normalized([vec2 out = null]) #

Normalizes this returns new vector or optional out

vec2 normalized([vec2 out = null]) {
 if (out == null) {
   out = new vec2.raw(x, y);
 }
 double l = out.length;
 if (l == 0.0) {
   return out;
 }
 out.x /= l;
 out.y /= l;
 return out;
}

double normalizeLength() #

Normalizes this. Returns length.

double normalizeLength() {
 double l = length;
 if (l == 0.0) {
   return 0.0;
 }
 x /= l;
 y /= l;
 return l;
}

double relativeError(vec2 correct) #

Returns the relative error between this and correct

double relativeError(vec2 correct) {
 double correct_norm = correct.length;
 double diff_norm = (this - correct).length;
 return diff_norm/correct_norm;
}

vec2 scale(num arg) #

vec2 scale(num arg) {
 double a = arg.toDouble();
 x = x * a;
 y = y * a;
 return this;
}

vec2 scaled(num arg) #

vec2 scaled(num arg) {
 return clone().scale(arg);
}

vec2 set(vec2 arg) #

vec2 set(vec2 arg) {
 x = arg.x;
 y = arg.y;
 return this;
}

vec2 setComponents(num x_, num y_) #

vec2 setComponents(num x_, num y_) {
 x = x_.toDouble();
 y = y_.toDouble();
 return this;
}

vec2 splat(num arg) #

Splats a scalar into all lanes of the vector.

vec2 splat(num arg) {
 double a = arg.toDouble();
 x = a;
 y = a;
 return this;
}

vec2 sub(vec2 arg) #

vec2 sub(vec2 arg) {
 x = x - arg.x;
 y = y - arg.y;
 return this;
}

String toString() #

Returns a printable string

String toString() => '$x,$y';