From 465921081b321e660ae89520c660bf140f0c7208 Mon Sep 17 00:00:00 2001 From: Oshgnacknak Date: Thu, 1 Jul 2021 23:34:06 +0200 Subject: [PATCH] Add and div --- src/main/java/de/oshgnacknak/gruphi/Vector.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/oshgnacknak/gruphi/Vector.java b/src/main/java/de/oshgnacknak/gruphi/Vector.java index 1d6a453..875e45b 100644 --- a/src/main/java/de/oshgnacknak/gruphi/Vector.java +++ b/src/main/java/de/oshgnacknak/gruphi/Vector.java @@ -14,8 +14,12 @@ public class Vector { } public Vector add(Vector v) { - x += v.x; - y += v.y; + return add(v.x, v.y); + } + + public Vector add(double x, double y) { + this.x += x; + this.y += y; return this; } @@ -31,6 +35,12 @@ public class Vector { return this; } + public Vector div(double d) { + x /= d; + y /= d; + return this; + } + double dot(Vector v) { return x*v.x + y*v.y; } @@ -40,7 +50,7 @@ public class Vector { } public Vector norm() { - return mul(1 / mag()); + return div(mag()); } Vector setMag(double mag) {