Open alexey-malov opened 7 years ago
friend CVector3D operator* (CVector3D const & vector3d, double scalar);
friend CVector3D operator* (double scalar, CVector3D const & vector3d);
if ((v1 += v2) == v3)
{
}
[x] Не реализовано скалярное произведение векторов
[x] Не реализовано векторное произведение векторов
[x] Не реализована нормализация вектора
CVector3D::CVector3D()
{
x = y = z = 0.0;
}
CVector3D::CVector3D(double x0, double y0, double z0)
{
x = x0;
y = y0;
z = z0;
}
CVector3D CVector3D::operator+ (CVector3D const & vector1) const
{
CVector3D result;
result.x = x + vector1.x;
result.y = y + vector1.y;
result.z = z + vector1.z;
return result;
}
return { x + vector1.x, y + vector1.y, z + vector1.z };
Это касается не только сложения, но и других арифметических операций
CVector3D CVector3D::CVector3D::operator- () const
{
CVector3D result;
return *this * -1;
}
return {-x, -y, -z};
BOOST_CHECK(CVector(1, 2, 3) == CVector(1, 2, 3));
BOOST_AUTO_TEST_CASE(return_false_when_not_all_fields_of_both_vectors_are_equal)
{
CVector3D vector3(vector1);
vector3.x++;
BOOST_CHECK(!(vector3 == vector1));
}
const CVector3D CrossProduct(CVector3D const& vector1, CVector3D const& vector2)
{
return{ vector1.y * vector2.z -
vector1.z * vector2.y, vector1.z * vector2.x -
vector1.x * vector2.z, vector1.x * vector2.y -
vector1.y * vector2.x };
}
const CVector3D CVector3D::Normalize()
{
double length = GetLength();
if (length != 0)
{
x /= length;
y /= length;
z /= length;
}
return *this;
}
[ ] Либо возвращать void и модифицировать себя, либо возвращать новый CVector3d, а себя не модифицировать
[ ] Метод не покрыт тестами
BOOST_AUTO_TEST_CASE(return_false_when_y_of_both_vectors_not_are_equal)
{
CVector3D vector1 = { 1, 2, 3 };
CVector3D vector3 = { 1, 5, 3 };
BOOST_CHECK(!(vector3 == vector1));
BOOST_CHECK(vector3.x == vector1.x); //!
BOOST_CHECK(vector3.y != vector1.y); //!
BOOST_CHECK(vector3.z == vector1.z); //!
}