LikhachevAV / OOP2016

0 stars 0 forks source link

Замечания по Vector 3d #6

Open alexey-malov opened 7 years ago

alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
    friend CVector3D operator* (CVector3D const & vector3d, double scalar);
    friend CVector3D operator* (double scalar, CVector3D const & vector3d);
alexey-malov commented 7 years ago
if ((v1 += v2) == v3)
{
}
alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
CVector3D::CVector3D()
{
    x = y = z = 0.0;
}

CVector3D::CVector3D(double x0, double y0, double z0)
{
    x = x0;
    y = y0;
    z = z0;
}
alexey-malov commented 7 years ago
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;
}

Это касается не только сложения, но и других арифметических операций

alexey-malov commented 7 years ago
CVector3D CVector3D::CVector3D::operator- () const
{
    CVector3D result;
    return *this * -1;
}
alexey-malov commented 7 years ago
BOOST_CHECK(CVector(1, 2, 3) == CVector(1, 2, 3));
alexey-malov commented 7 years ago
    BOOST_AUTO_TEST_CASE(return_false_when_not_all_fields_of_both_vectors_are_equal)
    {
        CVector3D vector3(vector1);
        vector3.x++;
        BOOST_CHECK(!(vector3 == vector1));
    }
alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
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 };
}
alexey-malov commented 7 years ago

const CVector3D CVector3D::Normalize()
{
    double length = GetLength();
    if (length != 0)
    {
        x /= length;
        y /= length;
        z /= length;
    }
    return *this;
}
alexey-malov commented 7 years ago
    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); //!
    }