@Override public float lengthSquared() { final int size = size(); float l = 0; for (int comp = 0; comp < size; comp++) { l += vec[comp] * vec[comp]; } return l; }
public float dot(float... v) { final int size = size(); if (size != v.length) { throw new IllegalArgumentException("Vector sizes must be the same"); } float d = 0; for (int comp = 0; comp < size; comp++) { d += vec[comp] * v[comp]; } return d; }
@Override public VectorNf div(float a) { final int size = size(); final VectorNf d = new VectorNf(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = vec[comp] / a; } return d; }
public VectorNf max(float... v) { final int size = size(); if (size != v.length) { throw new IllegalArgumentException("Vector sizes must be the same"); } final VectorNf d = new VectorNf(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = Math.max(vec[comp], v[comp]); } return d; }
public VectorNf add(float... v) { final int size = size(); if (size != v.length) { throw new IllegalArgumentException("Vector sizes must be the same"); } final VectorNf d = new VectorNf(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = vec[comp] + v[comp]; } return d; }
public VectorNf sub(float... v) { final int size = size(); if (size != v.length) { throw new IllegalArgumentException("Vector sizes must be the same"); } final VectorNf d = new VectorNf(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = vec[comp] - v[comp]; } return d; }
public VectorNf div(float... v) { final int size = size(); if (size != v.length) { throw new IllegalArgumentException("Vector sizes must be the same"); } final VectorNf d = new VectorNf(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = vec[comp] / v[comp]; } return d; }
@Override public VectorNf pow(float power) { final int size = size(); final VectorNf d = new VectorNf(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = (float) Math.pow(vec[comp], power); } return d; }
@Override public VectorNf round() { final int size = size(); final VectorNf d = new VectorNf(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = Math.round(vec[comp]); } return d; }
public VectorNf mul(float... v) { final int size = size(); if (size != v.length) { throw new IllegalArgumentException("Vector sizes must be the same"); } final VectorNf d = new VectorNf(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = vec[comp] * v[comp]; } return d; }
@Override public VectorNf abs() { final int size = size(); final VectorNf d = new VectorNf(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = Math.abs(vec[comp]); } return d; }
@Override public VectorNf pow(float power) { final int size = size(); final VectorNf d = new VectorNf(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = (float) Math.pow(vec[comp], power); } return d; }
@Override public VectorNf round() { final int size = size(); final VectorNf d = new VectorNf(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = Math.round(vec[comp]); } return d; }
@Override public VectorNd toDouble() { final int size = size(); final double[] doubleVec = new double[size]; for (int comp = 0; comp < size; comp++) { doubleVec[comp] = (double) vec[comp]; } return new VectorNd(doubleVec); }
public VectorNf resize(int size) { final VectorNf d = new VectorNf(size); System.arraycopy(vec, 0, d.vec, 0, Math.min(size, size())); return d; }
@Override public VectorNf negate() { final int size = size(); final VectorNf d = new VectorNf(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = -vec[comp]; } return d; }
public VectorNf min(float... v) { final int size = size(); if (size != v.length) { throw new IllegalArgumentException("Vector sizes must be the same"); } final VectorNf d = new VectorNf(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = Math.min(vec[comp], v[comp]); } return d; }
@Override public VectorNf toFloat() { final int size = size(); final float[] floatVec = new float[size]; for (int comp = 0; comp < size; comp++) { floatVec[comp] = (float) vec[comp]; } return new VectorNf(floatVec); }
@Override public VectorNi toInt() { final int size = size(); final int[] intVec = new int[size]; for (int comp = 0; comp < size; comp++) { intVec[comp] = GenericMath.floor(vec[comp]); } return new VectorNi(intVec); }
@Override public VectorNf floor() { final int size = size(); final VectorNf d = new VectorNf(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = GenericMath.floor(vec[comp]); } return d; }