Add and div

This commit is contained in:
2021-07-01 23:34:06 +02:00
parent bddaa19ca4
commit 465921081b

View File

@ -14,8 +14,12 @@ public class Vector {
} }
public Vector add(Vector v) { public Vector add(Vector v) {
x += v.x; return add(v.x, v.y);
y += v.y; }
public Vector add(double x, double y) {
this.x += x;
this.y += y;
return this; return this;
} }
@ -31,6 +35,12 @@ public class Vector {
return this; return this;
} }
public Vector div(double d) {
x /= d;
y /= d;
return this;
}
double dot(Vector v) { double dot(Vector v) {
return x*v.x + y*v.y; return x*v.x + y*v.y;
} }
@ -40,7 +50,7 @@ public class Vector {
} }
public Vector norm() { public Vector norm() {
return mul(1 / mag()); return div(mag());
} }
Vector setMag(double mag) { Vector setMag(double mag) {