I’m writing a vector math api with a design that some may consider strange and myself have some doubts of it’s usefulness.
The design is similar to the vecmath api from Java 3D in which classes are used to store vector data but in my case i have Float2,Float3,… Int2,Int3,… which are all final. Attributes correspond to the name of the class (the primitive) and are all public e0,e1,e2,… matching the count given by the class suffix number. For example:
public final class Float4 { public float e0,e1,e2,e3; }.
I don’t have classes that extend other classes like VectorX extends TupleX to avoid virtual methods.
Storage classes don’t have any methods, only public attributes.
I have a final class called Vec which supports static final methods (again to avoid virtual methods) and uses the storage classes above as arguments. For example ‘Vec.clear(aFloat4)’, ‘Vec.fill(aDouble3,1.0)’ or ‘double d=Vec.len(aFloat4)’ which returns the length of aFloat4.
Since there are too many methods for every possible combination of vector operation and storage class and the code is too I’m generating the Vec.java file using another java file called VecMaker.java. The storage types are Byte, Short, Int, Float, Double and the dimensions are 2, 3, 4, 9, 16. 9 and 16 is because i’m encoding matrices in a linear array. There’s 30 storage classes and thus 30 clear methods for maximum efficiency. With all the other methods to do vector math there will be something like 1000 methods, maybe more.
I have some doubts about this.
Should i use storage classes like the ones described above or don’t use any storage classes and work with arrays of primitives or primitive data buffers directly in method arguments?
Is the decision to use final and non-virtual methods for the vector math operations a good decision for performance?
Should i have final storage classes and avoid extending classes like what happens with the vecmath api?
Will having classes with thousands of static final methods cause any performance problems?