2021-03-12 21:33:46 +00:00
|
|
|
#ifndef SDLPP_HPP_GEOMETRY_VECTOR
|
|
|
|
#define SDLPP_HPP_GEOMETRY_VECTOR
|
|
|
|
|
|
|
|
#include "sdlpp_common.hpp"
|
|
|
|
#include "sdlpp_vector.hpp"
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
namespace SDLPP {
|
2021-03-13 17:36:29 +00:00
|
|
|
template < typename T >
|
|
|
|
double vecDotProduct( const Vec2D< T > &a, const Vec2D< T > &b ) {
|
2021-03-12 21:33:46 +00:00
|
|
|
return a * b;
|
|
|
|
}
|
2021-03-13 17:36:29 +00:00
|
|
|
template < typename T > double vecLengthSquared( const Vec2D< T > &vec ) {
|
2021-03-12 21:33:46 +00:00
|
|
|
return vecDotProduct( vec, vec );
|
|
|
|
}
|
2021-03-13 17:36:29 +00:00
|
|
|
template < typename T > double vecLength( const Vec2D< T > &vec ) {
|
2021-03-12 21:33:46 +00:00
|
|
|
return std::sqrt( vecLengthSquared( vec ) );
|
|
|
|
}
|
2021-03-13 17:36:29 +00:00
|
|
|
template < typename T >
|
|
|
|
double vecDistanceSquared( const Vec2D< T > &a, const Vec2D< T > &b ) {
|
2021-03-12 21:33:46 +00:00
|
|
|
return vecLengthSquared( a - b );
|
|
|
|
}
|
2021-03-13 17:36:29 +00:00
|
|
|
template < typename T >
|
|
|
|
double vecDistance( const Vec2D< T > &a, const Vec2D< T > &b ) {
|
2021-03-12 21:33:46 +00:00
|
|
|
return vecLength( a - b );
|
|
|
|
}
|
|
|
|
} // namespace SDLPP
|
|
|
|
|
|
|
|
#endif
|