2022-05-21 06:32:35 -04:00
|
|
|
package xyz.valnet.engine.math;
|
|
|
|
|
|
2023-01-02 00:26:39 -05:00
|
|
|
import java.io.Serializable;
|
|
|
|
|
|
|
|
|
|
public class Vector2i implements Serializable {
|
2022-05-21 06:32:35 -04:00
|
|
|
|
|
|
|
|
public int x, y;
|
|
|
|
|
|
|
|
|
|
public Vector2i() {
|
|
|
|
|
x = 0;
|
|
|
|
|
y = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Vector2i(int x, int y) {
|
|
|
|
|
this.x = x;
|
|
|
|
|
this.y = y;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-21 08:57:05 -04:00
|
|
|
public boolean equals(Vector2i other) {
|
|
|
|
|
return x == other.x && y == other.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isOneOf(Vector2i[] others) {
|
|
|
|
|
for(Vector2i other : others) {
|
2023-01-06 12:14:13 -05:00
|
|
|
if(other.equals(this)) {
|
2022-05-21 08:57:05 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-22 02:08:41 -04:00
|
|
|
public float distanceTo(int x, int y) {
|
|
|
|
|
int a = this.x - x;
|
|
|
|
|
int b = this.y - y;
|
|
|
|
|
return (float) Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-26 14:39:29 -05:00
|
|
|
public Vector2f asFloat() {
|
|
|
|
|
return new Vector2f(x, y);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-11 05:09:35 -05:00
|
|
|
public Vector2i north() {
|
|
|
|
|
return new Vector2i(x, y - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Vector2i east() {
|
|
|
|
|
return new Vector2i(x + 1, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Vector2i south() {
|
|
|
|
|
return new Vector2i(x, y + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Vector2i west() {
|
|
|
|
|
return new Vector2i(x - 1, y);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-27 09:56:56 -05:00
|
|
|
public Box getTileBox() {
|
|
|
|
|
return new Box(x, y, 1, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-21 06:32:35 -04:00
|
|
|
}
|