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

109 lines
1.5 KiB
Java

package speiger.src.coreengine.math.vector.floats;
import java.util.Objects;
public class Vec3fImmutable implements Vec3f
{
final float x;
final float y;
final float z;
public Vec3fImmutable()
{
x = 0F;
y = 0F;
z = 0F;
}
public Vec3fImmutable(float value)
{
x = value;
y = value;
z = value;
}
public Vec3fImmutable(float x, float y, float z)
{
this.x = x;
this.y = y;
this.z = z;
}
@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 Vec3f setX(float x)
{
return this.x == x ? this : Vec3f.of(x, y, z);
}
@Override
public Vec3f setY(float y)
{
return this.y == y ? this : Vec3f.of(x, y, z);
}
@Override
public Vec3f setZ(float z)
{
return this.z == z ? this : Vec3f.of(x, y, z);
}
@Override
public Vec3f copy()
{
return Vec3f.of(this);
}
@Override
public Vec3f set(float x, float y, float z)
{
return this.x == x && this.y == y && this.z == z ? this : Vec3f.of(x, y, z);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec3f)
{
Vec3f vec = (Vec3f)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
}
return false;
}
@Override
public String toString()
{
return "Vec3f[x="+x+", y="+y+", z="+z+"]";
}
}