All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mikera.transformz.impl.ConstantTransform4 Maven / Gradle / Ivy

Go to download

Fast double-precision vector and matrix maths library for Java, supporting N-dimensional numeric arrays.

There is a newer version: 0.67.0
Show newest version
package mikera.transformz.impl;

import mikera.transformz.ATranslation;
import mikera.transformz.Translation;
import mikera.transformz.marker.ISpecialisedTransform;
import mikera.vectorz.AVector;
import mikera.vectorz.Vector4;

/**
 * Class represnting a transform that returns a 4D constant
 * @author Mike
 *
 */
public final class ConstantTransform4 extends AConstantTransform implements ISpecialisedTransform {
	private double x,y,z,t;
	
	/**
	 * Creates a new constant transform, using the provided vector as the constant value
	 * Does *not* take a defensive copy
	 * @param inputDimensions
	 * @param value
	 */
	public ConstantTransform4(int inputDimensions, AVector value) {
		super(inputDimensions);
		x=value.get(0);
		y=value.get(1);
		z=value.get(2);
		t=value.get(3);
	}
	
	@Override
	public double calculateElement(int i, AVector inputVector) {
		switch (i) {
			case 0: return x;
			case 1: return y;
			case 2: return z;
			case 3: return t;
			default: throw new IndexOutOfBoundsException("Index: "+i);
		}
	}

	@Override
	public int outputDimensions() {
		return 4;
	}

	@Override
	public void transform(AVector source, AVector dest) {
		if (dest instanceof Vector4) {
			transform(source,(Vector4)dest);
			return;
		}
		assert(source.length()==inputDimensions());
		dest.set(0,x);
		dest.set(1,y);
		dest.set(2,z);
		dest.set(3,t);
	}
	
	public void transform(AVector source, Vector4 dest) {
		assert(source.length()==inputDimensions());
		dest.x=x;
		dest.y=y;
		dest.z=z;
		dest.t=t;
	}


	@Override
	public ATranslation getTranslation() {
		return new Translation(new double[]{x,y,z,t});
	}

	@Override
	public AVector getConstantValue() {
		return new Vector4(x,y,z,y);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy