From b4f8efaec20632bd7e645db8b8ef3eca7ad48205 Mon Sep 17 00:00:00 2001 From: hneemann Date: Sun, 15 Apr 2018 10:08:16 +0200 Subject: [PATCH] added some helper methods to VectorFloat --- .../digital/draw/graphics/Polygon.java | 2 +- .../digital/draw/graphics/VectorFloat.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/neemann/digital/draw/graphics/Polygon.java b/src/main/java/de/neemann/digital/draw/graphics/Polygon.java index 46bf0fd25..c069406a5 100644 --- a/src/main/java/de/neemann/digital/draw/graphics/Polygon.java +++ b/src/main/java/de/neemann/digital/draw/graphics/Polygon.java @@ -84,7 +84,7 @@ public class Polygon implements Iterable { * @param p the end point to add * @return this for chained calls */ - public Polygon add(Vector c1, Vector c2, Vector p) { + public Polygon add(VectorInterface c1, VectorInterface c2, VectorInterface p) { isBezierStart.add(points.size()); points.add(c1); points.add(c2); diff --git a/src/main/java/de/neemann/digital/draw/graphics/VectorFloat.java b/src/main/java/de/neemann/digital/draw/graphics/VectorFloat.java index 9a71bdf8d..a45092fda 100644 --- a/src/main/java/de/neemann/digital/draw/graphics/VectorFloat.java +++ b/src/main/java/de/neemann/digital/draw/graphics/VectorFloat.java @@ -51,6 +51,16 @@ public class VectorFloat implements VectorInterface { return tr.transform(this); } + /** + * Creates a new vector which has the value this+a + * + * @param a a + * @return this+a + */ + public VectorFloat add(VectorInterface a) { + return new VectorFloat(x + a.getXFloat(), y + a.getYFloat()); + } + /** * Subtracts the given vector * @@ -61,6 +71,26 @@ public class VectorFloat implements VectorInterface { return new VectorFloat(x - sub.getXFloat(), y - sub.getYFloat()); } + /** + * Creates a new vector which has the value this*a + * + * @param a a + * @return this*a + */ + public VectorFloat mul(int a) { + return new VectorFloat(x * a, y * a); + } + + /** + * Creates a new vector which has the value this/d + * + * @param d a + * @return this/d + */ + public VectorFloat div(int d) { + return new VectorFloat(x / d, y / d); + } + @Override public boolean equals(Object o) { if (this == o) return true;