55 lines
1.1 KiB
Java
55 lines
1.1 KiB
Java
package shootergame.util.math.vec;
|
|
|
|
import shootergame.util.math.MathHelpers;
|
|
|
|
public class Vec2d
|
|
{
|
|
public double x;
|
|
public double y;
|
|
|
|
public Vec2d(double x, double y)
|
|
{
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
|
|
public double distance(Vec2d other) {
|
|
return MathHelpers.distance2d(x, y, other.x, other.y);
|
|
}
|
|
|
|
public static double distance(Vec2d v1, Vec2d v2) {
|
|
return v1.distance(v2);
|
|
}
|
|
|
|
public boolean equal(Vec2d other) {
|
|
return x == other.x && y == other.y;
|
|
}
|
|
|
|
public Vec2d add(Vec2d other) {
|
|
return new Vec2d(this.x + other.x, this.y + other.y);
|
|
}
|
|
|
|
public Vec2d subtract(Vec2d other) {
|
|
return new Vec2d(this.x - other.x, this.y - other.y);
|
|
}
|
|
|
|
public Vec2d multiply(Vec2d other) {
|
|
return new Vec2d(this.x * other.x, this.y * other.y);
|
|
}
|
|
|
|
public Vec2d divide(Vec2d other) {
|
|
return new Vec2d(this.x / other.x, this.y / other.y);
|
|
}
|
|
|
|
public Vec2d copy() {
|
|
return new Vec2d(x, y);
|
|
}
|
|
|
|
public double squareDistance(Vec2d other)
|
|
{
|
|
double dx = MathHelpers.positive(other.x - x);
|
|
double dy = MathHelpers.positive(other.y - y);
|
|
return MathHelpers.biggest(dx, dy);
|
|
}
|
|
}
|