SimpleJavaEngine/src/main/java/speiger/src/coreengine/math/vector/doubles/Vec4dImmutable.java

125 lines
1.7 KiB
Java

package speiger.src.coreengine.math.vector.doubles;
import java.util.Objects;
public class Vec4dImmutable implements Vec4d
{
final double x;
final double y;
final double z;
final double w;
public Vec4dImmutable()
{
x = 0;
y = 0;
z = 0;
w = 0;
}
public Vec4dImmutable(double value)
{
x = value;
y = value;
z = value;
w = value;
}
public Vec4dImmutable(double x, double y, double z, double w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public double getX()
{
return x;
}
@Override
public double getY()
{
return y;
}
@Override
public double getZ()
{
return z;
}
@Override
public double getW()
{
return w;
}
@Override
public Vec4d setX(double x)
{
return this.x == x ? this : Vec4d.of(x, y, z, w);
}
@Override
public Vec4d setY(double y)
{
return this.y == y ? this : Vec4d.of(x, y, z, w);
}
@Override
public Vec4d setZ(double z)
{
return this.z == z ? this : Vec4d.of(x, y, z, w);
}
@Override
public Vec4d setW(double w)
{
return this.w == w ? this : Vec4d.of(x, y, z, w);
}
@Override
public Vec4d copy()
{
return Vec4d.of(this);
}
@Override
public Vec4d set(double x, double y, double z, double w)
{
return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4d.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 Vec4d)
{
Vec4d vec = (Vec4d)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
}
return false;
}
@Override
public String toString()
{
return "Vec4d[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
}