SFTtech / openage

Free (as in freedom) open source clone of the Age of Empires II engine 🚀
http://openage.dev
Other
12.73k stars 1.12k forks source link

vector.h should have functions like magnitude and inverse #380

Closed amit2103 closed 9 years ago

amit2103 commented 9 years ago

While there is no limit to probably the operations that we need, I think these two should be implemented in the implementation for openage. If its deemed necessary I can code this. However if for our current implementation this is not deemed necessary, feel free to close this issue.

TheJJ commented 9 years ago

I would say when we need this feature we should implement it. We're not programming a standard library, so things should be added when needed.

amit2103 commented 9 years ago

@TheJJ Correct...This should be so...I really assumed that magnitude and inverse will be needed at some point. It might not be the case.

TheJJ commented 9 years ago

If we should need it at some point, we can reopen this issue. Otherwise we should focus on things we actually need now :smile:

amit2103 commented 9 years ago

Yep :+1:

zuntrax commented 9 years ago

We already have norm which probably does what you described by magnitude. An additive inverse can be computed by multiplying with -1.

amit2103 commented 9 years ago

By magnitude I meant that suppose there is a vector (6,8) its magnitude will be then √( 36 + 64 ). Inverse yes can be obtained by multiplying by -1...but I assumed that its better for the Vector to give its inverse than letting the user compute it.

TheJJ commented 9 years ago

The norm function in https://github.com/SFTtech/openage/blob/57d766332ad9420321d3855379cced7564c22263/libopenage/util/vector.h#L130 indeed computes the length.

amit2103 commented 9 years ago

Indeed it does. Out of curiosity though , shouldn't it be done more or less faster by using the method I described, than using the dot product here?