In reference to David Heubners vector class:
http://www.millbridge.de/processing/Vector.pde
Found through an earlier post of mine:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Contribution_3DOpenGL;action=display;num=1116270837
I hope the author doesn't mind me publically discussing this, but I had a few open questions/comments about the class.
For a start, I added my own method to the end:
Code: public Vector clone() {
return new Vector(x[0], x[1], x[2]);
}
This creates a new copy of the clone in memory, which I've found useful. And then I noticed, the class has highly similar methods e.g. rotateZ() and rotateMeZ(). I presume the intention was that you could produce a new vector by rotating the existing vector (rotateZ()) or simply rotate the vector changing its space in memory (rotateMeZ()).
The rotateZ method looks wrong to me because you're not creating a copy of the vector on the line
Vector result = this;, you're just assigning an alias so when the rotation is performed you are actually damaging the vector and returning another alias?
And so, I think the code for rotateZ() (and similar functions) should read:
Quote: public Vector rotateZ(float val) {
Vector result = this.clone();
double cosval = cos(val);
double sinval = sin(val);
double tmp1 = x[0]*cosval - x[1]*sinval;
double tmp2 = x[0]*sinval + x[1]*cosval;
result.x[0] = (float)tmp1;
result.x[1] = (float)tmp2;
return result;
}
The other thing I wanted to add about this class is, would it be possible to have some documentation on this? Lastly, to TomC's comment (in the other post) about renaming it - I don't mind it being called Vector if it has the same functionality as the original plus the extra features. I'm including as needed for the moment.