SimpleJavaEngine/src/main/java/speiger/src/coreengine/math/vector/floats/Vec4fImmutable.java

125 lines
1.7 KiB
Java

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