From 08f57430d3d5263a6cc46463a1761fb47fae6ef5 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Tue, 17 Apr 2018 13:26:50 +0800 Subject: [PATCH] struct Point and struct Size overloaded operator - --- core/Action/ActionMoveBy.cpp | 7 ++----- core/Common/Point.cpp | 13 +++++++++---- core/Common/Size.cpp | 13 +++++++++---- core/Transition/TransitionMove.cpp | 6 ++---- core/ecommon.h | 18 ++++++++++-------- 5 files changed, 32 insertions(+), 25 deletions(-) diff --git a/core/Action/ActionMoveBy.cpp b/core/Action/ActionMoveBy.cpp index fb0cbb7d..c2fae766 100644 --- a/core/Action/ActionMoveBy.cpp +++ b/core/Action/ActionMoveBy.cpp @@ -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); } \ No newline at end of file diff --git a/core/Common/Point.cpp b/core/Common/Point.cpp index f648177f..d0336859 100644 --- a/core/Common/Point.cpp +++ b/core/Common/Point.cpp @@ -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); +} \ No newline at end of file diff --git a/core/Common/Size.cpp b/core/Common/Size.cpp index 00f58992..198efe3f 100644 --- a/core/Common/Size.cpp +++ b/core/Common/Size.cpp @@ -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); +} \ No newline at end of file diff --git a/core/Transition/TransitionMove.cpp b/core/Transition/TransitionMove.cpp index a3add2d6..18e5741c 100644 --- a/core/Transition/TransitionMove.cpp +++ b/core/Transition/TransitionMove.cpp @@ -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) diff --git a/core/ecommon.h b/core/ecommon.h index 86ec756f..067df7b8 100644 --- a/core/ecommon.h +++ b/core/ecommon.h @@ -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; };