struct Point and struct Size overloaded operator -

This commit is contained in:
Nomango 2018-04-17 13:26:50 +08:00
parent 3fe75c7325
commit 08f57430d3
5 changed files with 32 additions and 25 deletions

View File

@ -27,10 +27,7 @@ void e2d::ActionMoveBy::_update()
}
// 移动节点
m_pTarget->setPos(
m_BeginPos.x + m_MoveVec.x * m_fRateOfProgress,
m_BeginPos.y + m_MoveVec.y * m_fRateOfProgress
);
m_pTarget->setPos(m_BeginPos + m_MoveVec * m_fRateOfProgress);
}
e2d::ActionMoveBy * e2d::ActionMoveBy::clone() const
@ -40,5 +37,5 @@ e2d::ActionMoveBy * e2d::ActionMoveBy::clone() const
e2d::ActionMoveBy * e2d::ActionMoveBy::reverse() const
{
return new ActionMoveBy(m_fDuration, Vector(-m_MoveVec.x, -m_MoveVec.y));
return new ActionMoveBy(m_fDuration, -m_MoveVec);
}

View File

@ -13,22 +13,22 @@ e2d::Point::Point(double x, double y)
this->y = y;
}
e2d::Point e2d::Point::operator+(Point const & p)
e2d::Point e2d::Point::operator+(Point const & p) const
{
return Point(x + p.x, y + p.y);
}
e2d::Point e2d::Point::operator-(Point const & p)
e2d::Point e2d::Point::operator-(Point const & p) const
{
return Point(x - p.x, y - p.y);
}
e2d::Point e2d::Point::operator*(double const & value)
e2d::Point e2d::Point::operator*(double const & value) const
{
return Point(x * value, y * value);
}
e2d::Point e2d::Point::operator/(double const & value)
e2d::Point e2d::Point::operator/(double const & value) const
{
return Point(x / value, y / value);
}
@ -37,3 +37,8 @@ e2d::Point::operator e2d::Size() const
{
return Size(x, y);
}
e2d::Point e2d::Point::operator-() const
{
return Point(-x, -y);
}

View File

@ -12,22 +12,22 @@ e2d::Size::Size(double width, double height)
this->height = height;
}
e2d::Size e2d::Size::operator+(Size const & size)
e2d::Size e2d::Size::operator+(Size const & size) const
{
return Size(width + size.width, height + size.height);
}
e2d::Size e2d::Size::operator-(Size const & size)
e2d::Size e2d::Size::operator-(Size const & size) const
{
return Size(width - size.width, height - size.height);
}
e2d::Size e2d::Size::operator*(double const & value)
e2d::Size e2d::Size::operator*(double const & value) const
{
return Size(width * value, height * value);
}
e2d::Size e2d::Size::operator/(double const & value)
e2d::Size e2d::Size::operator/(double const & value) const
{
return Size(width / value, height / value);
}
@ -36,3 +36,8 @@ e2d::Size::operator e2d::Point() const
{
return Point(width, height);
}
e2d::Size e2d::Size::operator-() const
{
return Size(-width, -height);
}

View File

@ -42,13 +42,11 @@ void e2d::TransitionMove::_updateCustom()
{
if (m_pPrevScene)
{
auto root = m_pPrevScene->getRoot();
root->setPos(m_Vector * m_fRateOfProgress);
m_pPrevScene->getRoot()->setPos(m_Vector * m_fRateOfProgress);
}
if (m_pNextScene)
{
auto root = m_pNextScene->getRoot();
root->setPos(m_NextPos + m_Vector * m_fRateOfProgress);
m_pNextScene->getRoot()->setPos(m_NextPos + m_Vector * m_fRateOfProgress);
}
if (m_fRateOfProgress >= 1)

View File

@ -43,10 +43,11 @@ struct Point
Point(double x, double y);
Point operator + (Point const & p);
Point operator - (Point const & p);
Point operator * (double const & value);
Point operator / (double const & value);
Point operator + (Point const & p) const;
Point operator - (Point const & p) const;
Point operator * (double const & value) const;
Point operator / (double const & value) const;
Point operator - () const;
operator e2d::Size() const;
};
@ -65,10 +66,11 @@ struct Size
Size(double width, double height);
Size operator + (Size const & size);
Size operator - (Size const & size);
Size operator * (double const & value);
Size operator / (double const & value);
Size operator + (Size const & size) const;
Size operator - (Size const & size) const;
Size operator * (double const & value) const;
Size operator / (double const & value) const;
Size operator - () const;
operator e2d::Point() const;
};