fix: fixed sonarqube-reported casting bugs

This commit is contained in:
Yannik Bretschneider 2021-06-04 13:47:16 +02:00
parent 7b2880cfec
commit 32cbb6d876
1 changed files with 10 additions and 10 deletions

View File

@ -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;
}