Create helper class for distance calculation

This commit is contained in:
2022-08-19 11:30:18 +02:00
parent 44782d1328
commit a4c7f48a23
2 changed files with 77 additions and 2 deletions

View File

@@ -0,0 +1,74 @@
package com.bartlomiejpluta.base.util.math;
import org.joml.Vector2dc;
import org.joml.Vector2fc;
import org.joml.Vector2ic;
import static java.lang.Math.*;
public class Distance {
public static int chebyshev(int ax, int ay, int bx, int by) {
return max(abs(ax - bx), abs(ay - by));
}
public static float chebyshev(float ax, float ay, float bx, float by) {
return max(abs(ax - bx), abs(ay - by));
}
public static double chebyshev(double ax, double ay, double bx, double by) {
return max(abs(ax - bx), abs(ay - by));
}
public static int chebyshev(Vector2ic a, Vector2ic b) {
return max(abs(a.x() - b.x()), abs(a.y() - b.y()));
}
public static float chebyshev(Vector2fc a, Vector2fc b) {
return max(abs(a.x() - b.x()), abs(a.y() - b.y()));
}
public static double chebyshev(Vector2dc a, Vector2dc b) {
return max(abs(a.x() - b.x()), abs(a.y() - b.y()));
}
public static int manhattan(int ax, int ay, int bx, int by) {
return abs(ax - bx) + abs(ay - by);
}
public static float manhattan(float ax, float ay, float bx, float by) {
return abs(ax - bx) + abs(ay - by);
}
public static double manhattan(double ax, double ay, double bx, double by) {
return abs(ax - bx) + abs(ay - by);
}
public static int manhattan(Vector2ic a, Vector2ic b) {
return abs(a.x() - b.x()) + abs(a.y() - b.y());
}
public static float manhattan(Vector2fc a, Vector2fc b) {
return abs(a.x() - b.x()) + abs(a.y() - b.y());
}
public static double manhattan(Vector2dc a, Vector2dc b) {
return abs(a.x() - b.x()) + abs(a.y() - b.y());
}
public static double euclidean(float ax, float ay, float bx, float by) {
return sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
}
public static double euclidean(double ax, double ay, double bx, double by) {
return sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
}
public static double euclidean(Vector2fc a, Vector2fc b) {
return sqrt((a.x() - b.x()) * (a.x() - b.x()) + (a.y() - b.y()) * (a.y() - b.y()));
}
public static double euclidean(Vector2dc a, Vector2dc b) {
return sqrt((a.x() - b.x()) * (a.x() - b.x()) + (a.y() - b.y()) * (a.y() - b.y()));
}
}