2023-03-21 09:56:13 +01:00
|
|
|
package school_project;
|
|
|
|
|
2023-04-21 20:00:15 +02:00
|
|
|
import java.io.Serializable;
|
|
|
|
|
2023-03-21 09:56:13 +01:00
|
|
|
/**
|
|
|
|
* This is used to represent a position/vector/... any ensemble of 2 elements that have to work together in
|
|
|
|
* a plan. This way we can use some basic operations over them.
|
|
|
|
*/
|
2023-04-21 20:00:15 +02:00
|
|
|
public class Vec2 implements Serializable {
|
2023-03-21 09:56:13 +01:00
|
|
|
public int x, y;
|
|
|
|
|
|
|
|
public Vec2() {
|
2023-03-23 11:24:34 +01:00
|
|
|
x = 0;
|
|
|
|
y = 0;
|
2023-03-21 09:56:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public Vec2(int x, int y ){
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
}
|
2023-04-21 20:00:15 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (obj instanceof Vec2 vec) {
|
|
|
|
return this.x == vec.x && this.y == vec.y;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2023-04-27 10:35:36 +02:00
|
|
|
|
|
|
|
public Vec2 add(Vec2 o){
|
|
|
|
return new Vec2(x + o.x, y + o.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "("+x+","+y+")";
|
|
|
|
}
|
2023-03-21 09:56:13 +01:00
|
|
|
}
|