FR: dot product for Point<Type>


I was about to multiply two Points (as they are used synonymous to vectors), but was amazed, that operator*(Point<Type>) returns a Point and not a scalar value, as I mathematically expected. I think multiplying vectors/points elementwise is not so commonly used, is it?

Would be nice to have at least the alternative by a method though, my suggestion for juce_Point.h:

    /** Compute the dot product of two points */
    template <typename OtherType>
    ValueType dotProduct (Point<OtherType> other) const noexcept    { return (ValueType) ((x * other.x) + (y * other.y)); }

Quite simple...


A dot product is something I'd expect in a linear algebra library, but not in a GUI class...


You are right, I use the Point for linear algebra to calculate the attenuation in a surround panning scenario. So it might be off topic for Juce's gui classes, but not for the audio computations. If there are reasons not to use Point<Type> for that kind of stuff, please let me know. I'm happy for alternatives, but I thought just for a dot product I don't add another library to my dependencies.

Well, it's no big deal to implement it in my own code, but formulas look nicer if they use correct operators instead of copy and paste terms...


Well, I would prefer not to add it to Point<>, simply because the right place for it would be some kind of vector class in some kind of DSP or math module. Point is restricted to 2D and is meant for GUI-related geometry (and in particular positions on the screen), whereas the concept of a dot product of two vectors is defined for any number of dimensions.

So in case in the future we will add a class to JUCE that is meant for this kind of calculations, I'll make sure we add a dot product to it ;-)


fair enough. Maybe we talk then about ambisonic or auro3D and won't get far with a 2D point anyway ;-)


template<typename ValueType>
FloatType Point< ValueType >::getDotProduct ( Point< ValueType >  other ) const


Wow, I totally overlooked it! Thanks :-)


...thanks from my side as well. I often forget to look also for getXXX(), I'm just not used to this naming convention...