Search in sources :

Example 1 with Vector3D

use of com.laytonsmith.PureUtilities.Vector3D in project CommandHelper by EngineHub.

the class ObjectGenerator method vector.

/**
 * Modifies an existing vector using a given vector object. Because Vector3D is immutable, this method does not
 * actually modify the existing vector, but creates a new one.
 *
 * @param v the original vector
 * @param c the vector array
 * @param t the target
 * @return the Vector
 */
public Vector3D vector(Vector3D v, Construct c, Target t) {
    if (c instanceof CArray) {
        CArray va = (CArray) c;
        double x = v.X();
        double y = v.Y();
        double z = v.Z();
        if (!va.isAssociative()) {
            if (va.size() == 3) {
                // 3rd dimension vector
                x = Static.getNumber(va.get(0, t), t);
                y = Static.getNumber(va.get(1, t), t);
                z = Static.getNumber(va.get(2, t), t);
            } else if (va.size() == 2) {
                // 2nd dimension vector
                x = Static.getNumber(va.get(0, t), t);
                y = Static.getNumber(va.get(1, t), t);
            } else if (va.size() == 1) {
                x = Static.getNumber(va.get(0, t), t);
            }
        } else {
            if (va.containsKey("x")) {
                x = Static.getNumber(va.get("x", t), t);
            }
            if (va.containsKey("y")) {
                y = Static.getNumber(va.get("y", t), t);
            }
            if (va.containsKey("z")) {
                z = Static.getNumber(va.get("z", t), t);
            }
        }
        return new Vector3D(x, y, z);
    } else if (c instanceof CNull) {
        // fulfilling the todo?
        return v;
    } else {
        throw new CREFormatException("Expecting an array, received " + c.getCType(), t);
    }
}
Also used : Vector3D(com.laytonsmith.PureUtilities.Vector3D) CArray(com.laytonsmith.core.constructs.CArray) CREFormatException(com.laytonsmith.core.exceptions.CRE.CREFormatException) CNull(com.laytonsmith.core.constructs.CNull)

Aggregations

Vector3D (com.laytonsmith.PureUtilities.Vector3D)1 CArray (com.laytonsmith.core.constructs.CArray)1 CNull (com.laytonsmith.core.constructs.CNull)1 CREFormatException (com.laytonsmith.core.exceptions.CRE.CREFormatException)1