From 32cbb6d876c3666221cf705bdbbb62ba4964c230 Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Fri, 4 Jun 2021 13:47:16 +0200 Subject: [PATCH] fix: fixed sonarqube-reported casting bugs --- .../marvelous/gamelibrary/IntVector2.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/IntVector2.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/IntVector2.java index 16493f3..40fb353 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/IntVector2.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/IntVector2.java @@ -53,7 +53,7 @@ public class IntVector2 implements Serializable { } public static float length(int x, int y) { - return (float)Math.sqrt(x * x + y * y); + return (float)Math.sqrt((double) x * x + y * y); } public float length() { @@ -61,7 +61,7 @@ public class IntVector2 implements Serializable { } public static float length2(int x, int y) { - return x * x + y * y; + return (float) x * x + y * y; } public float length2 () { @@ -119,8 +119,8 @@ public class IntVector2 implements Serializable { } public static float distance(int x1, int y1, int x2, int y2) { - final float x_d = x2 - x1; - final float y_d = y2 - y1; + final float x_d = (float) x2 - x1; + final float y_d = (float) y2 - y1; return (float)Math.sqrt(x_d * x_d + y_d * y_d); } @@ -134,8 +134,8 @@ public class IntVector2 implements Serializable { /** Equivalent to the minimum amount of king moves to go from A to B in chess */ public static float distanceChebyshev(int x1, int y1, int x2, int y2) { - final float x_d = x2 - x1; - final float y_d = y2 - y1; + final float x_d = (float) x2 - x1; + final float y_d = (float) y2 - y1; return Math.max(Math.abs(x_d), Math.abs(y_d)); } @@ -150,8 +150,8 @@ public class IntVector2 implements Serializable { } public static float distanceManhattan(int x1, int y1, int x2, int y2) { - final float x_d = x2 - x1; - final float y_d = y2 - y1; + final float x_d = (float) x2 - x1; + final float y_d = (float) y2 - y1; return Math.abs(x_d) + Math.abs(y_d); } @@ -164,8 +164,8 @@ public class IntVector2 implements Serializable { } public static float distance2(int x1, int y1, int x2, int y2) { - final float x_d = x2 - x1; - final float y_d = y2 - y1; + final float x_d = (float) x2 - x1; + final float y_d = (float) y2 - y1; return x_d * x_d + y_d * y_d; }