hadean/src/main/java/xyz/valnet/engine/math/Vector2i.java

63 lines
1.0 KiB
Java
Raw Normal View History

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;
}
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)) {
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);
}
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
}