|
From: Roger H. <rog...@mi...> - 2004-12-01 14:31:02
|
On Tuesday, November 30, 2004, at 06:38 pm, James W. Walker wrote: > "Lane Roathe" <la...@if...> wrote: > >> Why? Any operation that you would want to overload should be able to >> become an inlined function call just as easily. The actual operation >> code >> remains nearly identical. (at least in my experience.) >> >>> From someone who's still trying to get the latest builds to work in >>> my >> products, I'd rather see easily read/understood/maintainable code. The >> more programmers who can read the code and _really_ understand what's >> happening the more contributions to that code base you will get. > > Using overloaded operators for vector addition and scalar-times-vector > multiplication results in code that is closer to mathematical > notation, which to me makes it easier to read. Multiplication of > vectors is more doubtful, since math has dot and cross products while > C++ has only one * operator. > Yes, I have functions called DotProduct which returns a float and CrossProduct which return a vector. Operator * works on a vector and a float, a point and a float,a vector and a matrix or two matrices, in both 2D and 3D. Operators + and - work of a pair of vectors, a point and a vector (returning a point) or for + only a vector and a point as vector - point does not really make sense. For operator - there is also one which takes two points and returns a vector. The unary - operator works on vectors and point though I would be happy to ditch the point one as it is a bit dodgy mathematically, and you can do the same thing by multiplying by -1 anyway. |