Difference between revisions of "User talk:Cron Stardust/LLVector Spec"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with "== Using returned references more completely == While I converted all the method signatures that had a return type of void to const LLVector&, there are still several methods tha…")
 
Line 6: Line 6:
</cpp>
</cpp>
I certainly think so, but I'll leave this change to stew for a bit - I've got bigger spuds to fry ATM. [[User:Cron Stardust|Cron Stardust]] 15:40, 6 April 2014 (PDT)
I certainly think so, but I'll leave this change to stew for a bit - I've got bigger spuds to fry ATM. [[User:Cron Stardust|Cron Stardust]] 15:40, 6 April 2014 (PDT)
== clear() vs setZero() ==
In prediction of the argument, I chose setZero because of the greater semantic meaning: setZero explicitly states, right up front, that it is setting the vector to a magnitude of 0.  A potential argument in favor of ''clear'' is that it is easier to type: less characters and no shift-key.  But this argument is based on laziness instead of code clarity - after all, why not just go with ''s0()''?  Kinda ridiculous IMNSHO.
A stronger argument would be that while setZero carries the meaning of ''set magnitude to 0'' clear would carry the meaning of ''clear all members'' - the difference being moot in all cases but LLVector4: a 4-vector of <0,0,0,1> still has a magnitude of 0, but it is not fully cleared.  To counter this argue that that is the correct meaning and result: setZero would work with the XYZ components, while some other method would work on switching the meaning of the vector: a vector with a W-component of 0 is an untranslatable direction+magnitude, while a vector with a W-component of 1 is a point in 3D space with reference to some origin and therefore can be translated. Furthermore, there should be some extra set of methods for 4-vectors to explicitly set the type of vector so as to retain the semantic meaning of the two kinds of vector it can represent - especially since, as far as I currently understand, any other value then 0 or 1 in the W-component is most likely a bug - I'm not sure at this moment, without re-analyzing the matrix multiplication, what the effect of various values other than 0 or 1 would be!

Revision as of 16:50, 11 April 2014

Using returned references more completely

While I converted all the method signatures that had a return type of void to const LLVector&, there are still several methods that return what seems like semi-useless noise: BOOL and NUM. I'm not counting the ones that should return those types, but methods like normalize, which has no business returning NUM. The in-source documentation says "Normalizes and returns the magnitude of LLVector..." Ok... Ummm.... Isn't the result of normalization SUPPOSED TO BE 1.f?!!?!!? Wouldn't it be better if it returned const LLVector& so that we could do: <cpp> LLVector vec(); vec.normalize().scale(3.f); </cpp> I certainly think so, but I'll leave this change to stew for a bit - I've got bigger spuds to fry ATM. Cron Stardust 15:40, 6 April 2014 (PDT)

clear() vs setZero()

In prediction of the argument, I chose setZero because of the greater semantic meaning: setZero explicitly states, right up front, that it is setting the vector to a magnitude of 0. A potential argument in favor of clear is that it is easier to type: less characters and no shift-key. But this argument is based on laziness instead of code clarity - after all, why not just go with s0()? Kinda ridiculous IMNSHO.

A stronger argument would be that while setZero carries the meaning of set magnitude to 0 clear would carry the meaning of clear all members - the difference being moot in all cases but LLVector4: a 4-vector of <0,0,0,1> still has a magnitude of 0, but it is not fully cleared. To counter this argue that that is the correct meaning and result: setZero would work with the XYZ components, while some other method would work on switching the meaning of the vector: a vector with a W-component of 0 is an untranslatable direction+magnitude, while a vector with a W-component of 1 is a point in 3D space with reference to some origin and therefore can be translated. Furthermore, there should be some extra set of methods for 4-vectors to explicitly set the type of vector so as to retain the semantic meaning of the two kinds of vector it can represent - especially since, as far as I currently understand, any other value then 0 or 1 in the W-component is most likely a bug - I'm not sure at this moment, without re-analyzing the matrix multiplication, what the effect of various values other than 0 or 1 would be!