(C++) EuclideanVector

CppEuclideanVector is a class for an Euclidean (X-Y) vector.

./CppEuclideanVector/CppEuclideanVector.pri

 ``` INCLUDEPATH += \     ../../Classes/CppEuclideanVector SOURCES += \     ../../Classes/CppEuclideanVector/euclideanvector.cpp HEADERS += \     ../../Classes/CppEuclideanVector/euclideanvector.h OTHER_FILES += \     ../../Classes/CppEuclideanVector/Licence.txt ```

./CppEuclideanVector/euclideanvector.h

 ``` #ifndef EUCLIDEANVECTOR_H #define EUCLIDEANVECTOR_H #ifdef USE_CUSTOM_RIBI_EUCLIDIAN_VECTOR #include #include namespace ribi { //A Euclidean vector template struct EuclideanVector {   explicit EuclideanVector(const T& any_x, const T& any_y) noexcept     : x { any_x }, y { any_y }   {   }   explicit EuclideanVector(const std::pair& p) noexcept     : x { p.first }, y { p.second }   {   }   explicit EuclideanVector(const EuclideanVector& rhs) noexcept     : x { rhs.x }, y { rhs.y }   {   }   EuclideanVector& operator+=(const EuclideanVector& rhs) noexcept   {     x += rhs.x;     y += rhs.y;     return *this;   }   EuclideanVector& operator*=(const double f) noexcept   {     x*=f;     y*=f;     return *this;   }   T x;   T y; }; template bool operator==(const EuclideanVector& lhs, const EuclideanVector& rhs) noexcept {   return lhs.x == rhs.x && lhs.y == rhs.y; } template bool operator!=(const EuclideanVector& lhs, const EuclideanVector& rhs) noexcept {   return !(lhs == rhs); } template const EuclideanVector operator+(const EuclideanVector& lhs, const EuclideanVector& rhs) noexcept {   return EuclideanVector(lhs.x + rhs.x, lhs.y + rhs.y); } template const EuclideanVector operator/(const EuclideanVector& lhs, const V& rhs) {   #ifndef NDEBUG   { const int x = int {}; assert(x == 0); }   { const double x = double {}; assert(x == 0.0); }   #endif   return EuclideanVector(lhs.x / rhs, lhs.y / rhs); } } //~namespace ribi #endif #endif // EUCLIDEANVECTOR_H ```

./CppEuclideanVector/euclideanvector.cpp

 ``` ```

This page has been created by the tool CodeToHtml