Potrzebuje stworzyć swoją klasa do wykonywania obliczeń na wektorach. Teraz daje poprawne wyniki lecz w jakiś dziwny sposób zmieniają się wartości na których pracuje. Mógłby ktoś mi pomóc w zlokalizowaniu błędu?
#pragma once
#include"LibsAndDeclarations.h"
template<class T = float>
class Vector
{
public:
T x;
T y;
Vector();
Vector(Vector &aVector);
Vector(T aX, T aY);
~Vector();
Vector & operator = (Vector &aVector)
{
this->x = aVector.x;
this->y = aVector.y;
return *this;
}
Vector & operator += (Vector &aVector)
{
this->x += aVector.x;
this->y += aVector.y;
return *this;
}
Vector & operator -= (Vector &aVector)
{
this->x -= aVector.x;
this->y -= aVector.y;
return *this;
}
Vector & operator *= (T aMulti)
{
this->x *= aMulti;
this->y *= aMulti;
return *this;
}
Vector & operator /= (T aDiv)
{
this->x *= aDiv;
this->y *= aDiv;
return *this;
}
Vector & operator + (Vector &aVector)
{
this->x += aVector.x;
this->y += aVector.y;
return *this;
}
Vector & operator - (Vector &aVector)
{
this->x -= aVector.x;
this->y -= aVector.y;
return *this;
}
Vector & operator * (T aMulti)
{
this->x *= aMulti;
this->y *= aMulti;
return *this;
}
Vector & operator / (T aDiv)
{
this->x /= aDiv;
this->y /= aDiv;
return *this;
}
Vector & operator - ()
{
this->x = -x;
this->y = -y;
return *this;
}
T & operator [] (const int aConter)
{
if (aConter == 0)
return x;
else if (aConter == 1)
return y;
else
{
std::cout << "Wyjscie poza rozmiar vectora! " << std::endl;
exit(0);
}
}
T length()
{
return (T)std::sqrt(x*x + y*y);
}
void normalize()
{
T temp = length();
if (0 != temp)
{
x /= temp;
y /= temp;
}
}
// Wektor prostokatny
Vector perpendicular()
{
return Vector(-y, x);
}
// Iloczyn skalarny
T dotProduct(Vector &aVector)
{
return x * aVector.x + y * aVector.y;
}
// Minimalny kat miedzy wektorami
T angle(Vector &aVector)
{
return (T)std::acos(dotProduct(aVector) / length() * aVector.length());
}
// Iloczyn skalarny z wektorem prostopadlym
T perpDotProduct(Vector &aVector)
{
return this->perpendicular().dotProduct(aVector);
}
void reset()
{
this->x = 0;
this->y = 0;
}
void setVector(Vector &aVector)
{
this->x = aVector.x;
this->y = aVector.y;
}
};
template<class T>
inline Vector<T>::Vector()
{
x = 0;
y = 0;
}
template<class T>
inline Vector<T>::Vector(Vector & aVector)
{
this->x = aVector.x;
this->y = aVector.y;
}
template<class T>
inline Vector<T>::Vector(T aX, T aY)
{
this->x = aX;
this->y = aY;
}
template<class T>
inline Vector<T>::~Vector()
{
}