diff --git a/src/Vectors.h b/src/Vectors.h index e9c5a5b..db563ab 100644 --- a/src/Vectors.h +++ b/src/Vectors.h @@ -29,10 +29,12 @@ struct CoordinatesVector return sqrt(sum_of_squares); } - // Use SFINAE to allow normalization of floating point + // Use SFINAE to allow normalization of floating point. + // The template argument is used to force substitution and thus checking the enable_if. /// Normalizes the vector using its euclidean norm. /// \return Nothing, the vector is normalized in-place. - typename std::enable_if::value,void>::type + template + typename std::enable_if::value,void>::type normalize() { double norm = magnitude(); @@ -104,6 +106,11 @@ struct Vec2 : public CoordinatesVector Vec2() = default; + Vec2(const Vec2& original): x(CoordinatesVector::coordinates[0]), y(CoordinatesVector::coordinates[1]) + { + std::copy(std::begin(original.coordinates), std::end(original.coordinates), std::begin(CoordinatesVector::coordinates)); + } + // Cast-copy constructor in order to use the operators of the mother class. Vec2(const CoordinatesVector& origin) { @@ -133,12 +140,17 @@ struct Vec3 : CoordinatesVector Vec3() = default; - // Cast-copy constructor in order to use the operators of the mother class. - Vec3(const CoordinatesVector& origin) + Vec3(const Vec3& original): x(CoordinatesVector::coordinates[0]), y(CoordinatesVector::coordinates[1]), z(CoordinatesVector::coordinates[2]) { - if (this != &origin) + std::copy(std::begin(original.coordinates), std::end(original.coordinates), std::begin(CoordinatesVector::coordinates)); + } + + // Cast-copy constructor in order to use the operators of the mother class. + Vec3(const CoordinatesVector& original) + { + if (this != &original) { - std::copy(std::begin(origin.coordinates),std::end(origin.coordinates),std::begin(CoordinatesVector::coordinates)); + std::copy(std::begin(original.coordinates), std::end(original.coordinates), std::begin(CoordinatesVector::coordinates)); } }