You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
2.2 KiB
145 lines
2.2 KiB
package mightypork.utils.math.vect;
|
|
|
|
|
|
import mightypork.utils.annotations.FactoryMethod;
|
|
import mightypork.utils.math.num.Num;
|
|
|
|
|
|
/**
|
|
* Coordinate with immutable numeric values.<br>
|
|
* This coordinate is guaranteed to never change, as opposed to view.
|
|
*
|
|
* @author MightyPork
|
|
*/
|
|
public final class VectVal extends VectMathStatic<VectVal> {
|
|
|
|
@SuppressWarnings("hiding")
|
|
public static final VectVal ZERO = new VectVal(0, 0, 0);
|
|
@SuppressWarnings("hiding")
|
|
public static final VectVal ONE = new VectVal(1, 1, 1);
|
|
|
|
|
|
/**
|
|
* Make a constant vector
|
|
*
|
|
* @param value source vector
|
|
* @return new constant vec
|
|
*/
|
|
@FactoryMethod
|
|
public static VectVal make(Vect value)
|
|
{
|
|
return value.copy(); // let the vect handle it
|
|
}
|
|
|
|
|
|
/**
|
|
* Make a constant vector
|
|
*
|
|
* @param x X value
|
|
* @param y Y value
|
|
* @return new constant vec
|
|
*/
|
|
@FactoryMethod
|
|
public static VectVal make(double x, double y)
|
|
{
|
|
return make(x, y, 0);
|
|
}
|
|
|
|
|
|
/**
|
|
* Make a constant vector
|
|
*
|
|
* @param x X value
|
|
* @param y Y value
|
|
* @return new constant vec
|
|
*/
|
|
@FactoryMethod
|
|
public static VectVal make(Num x, Num y)
|
|
{
|
|
return make(x, y, Num.ZERO);
|
|
}
|
|
|
|
|
|
/**
|
|
* Make a constant vector
|
|
*
|
|
* @param x X value
|
|
* @param y Y value
|
|
* @param z Z value
|
|
* @return new constant vector
|
|
*/
|
|
@FactoryMethod
|
|
public static VectVal make(double x, double y, double z)
|
|
{
|
|
return new VectVal(x, y, z);
|
|
}
|
|
|
|
|
|
/**
|
|
* Make a constant vector
|
|
*
|
|
* @param x X value
|
|
* @param y Y value
|
|
* @param z Z value
|
|
* @return new constant vector
|
|
*/
|
|
@FactoryMethod
|
|
public static VectVal make(Num x, Num y, Num z)
|
|
{
|
|
return new VectVal(x.value(), y.value(), z.value());
|
|
}
|
|
|
|
private final double x, y, z;
|
|
|
|
|
|
VectVal(Vect other) {
|
|
this(other.x(), other.y(), other.z());
|
|
}
|
|
|
|
|
|
VectVal(double x, double y, double z) {
|
|
this.x = x;
|
|
this.y = y;
|
|
this.z = z;
|
|
}
|
|
|
|
|
|
@Override
|
|
public double x()
|
|
{
|
|
return x;
|
|
}
|
|
|
|
|
|
@Override
|
|
public double y()
|
|
{
|
|
return y;
|
|
}
|
|
|
|
|
|
@Override
|
|
public double z()
|
|
{
|
|
return z;
|
|
}
|
|
|
|
|
|
/**
|
|
* @deprecated it's useless to copy a constant
|
|
*/
|
|
@Override
|
|
@Deprecated
|
|
public VectVal copy()
|
|
{
|
|
return this; // it's constant already
|
|
}
|
|
|
|
|
|
@Override
|
|
public VectVal result(double x, double y, double z)
|
|
{
|
|
return new VectVal(x, y, z);
|
|
}
|
|
|
|
}
|
|
|