SimpleJavaEngine/src/main/java/speiger/src/coreengine/math/vector/ints/Vec2iImmutable.java

93 lines
1.2 KiB
Java

package speiger.src.coreengine.math.vector.ints;
import java.util.Objects;
public class Vec2iImmutable implements Vec2i
{
final int x;
final int y;
public Vec2iImmutable()
{
x = 0;
y = 0;
}
public Vec2iImmutable(int value)
{
x = value;
y = value;
}
public Vec2iImmutable(int x, int y)
{
this.x = x;
this.y = y;
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public int getX()
{
return x;
}
@Override
public int getY()
{
return y;
}
@Override
public Vec2i setX(int x)
{
return this.x == x ? this : Vec2i.of(x, y);
}
@Override
public Vec2i setY(int y)
{
return this.y == y ? this : Vec2i.of(x, y);
}
@Override
public Vec2i copy()
{
return Vec2i.of(this);
}
@Override
public Vec2i set(int x, int y)
{
return this.x == x && this.y == y ? this : Vec2i.of(x, y);
}
@Override
public int hashCode()
{
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec2i)
{
Vec2i vec = (Vec2i)obj;
return vec.getX() == x && vec.getY() == y;
}
return false;
}
@Override
public String toString()
{
return "Vec2i[x="+x+", y="+y+"]";
}
}