edgar-mtz-e / slimdx

Automatically exported from code.google.com/p/slimdx
0 stars 0 forks source link

Vector instance/static methods (design) #461

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I noticed some inconsistencies in the Vector classes.

Length() and LengthSquared() on vectors are instance methods, which is
fine. But Normalize() has both an instance and a static method.

I feel Normalize() has a reason to be an instance method, because it has
side effects (the object will be overwritten with the end result). This is
not the case with Length() or LengthSquared(). They really act more like
property getters.

I can't quite figure out why the static Normalize(v) exists unless to allow
users to pick between both "styles".

In that spirit, shouldn't Length() and LengthSquared() also be available as
static methods?

And could perhaps the instance Length() and LengthSquared() be turned into
property getters, to reflect their nature of pure queries?

Original issue reported on code.google.com by carl.ad...@gmail.com on 24 Mar 2009 at 1:21

GoogleCodeExporter commented 9 years ago
Length() and LengthSquared() perform calculations, which is why they are 
methods.
They are also easily called inline with other code, which is why there are no 
static
overloads. 

Normalize is a special case because it is sometimes desirable to normalize a 
vector
without copying a new instance, while at other times you want to use the result 
as an
intermediate in a calculation.

These are not inconsistencies, but design choices.

Original comment by Mike.Popoloski on 24 Mar 2009 at 1:46

GoogleCodeExporter commented 9 years ago
Thanks for clearing it up, I understand now.

Original comment by carl.ad...@gmail.com on 24 Mar 2009 at 2:28