Skip to content

Commit

Permalink
refactor CCGeometry (#19847)
Browse files Browse the repository at this point in the history
* remove redundant copy constructor and copy assignment operator
* use delegate constructor to simply code
* fix a documentation error
  • Loading branch information
JohnCoconut authored and minggo committed Jun 21, 2019
1 parent d09918b commit 4afda3a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 44 deletions.
30 changes: 5 additions & 25 deletions cocos/math/CCGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,18 @@ NS_CC_BEGIN

// implementation of Size

Size::Size() : width(0), height(0)
Size::Size() : Size(0.0f, 0.0f)
{
}

Size::Size(float w, float h) : width(w), height(h)
{
}

Size::Size(const Size& other) : width(other.width), height(other.height)
{
}

Size::Size(const Vec2& point) : width(point.x), height(point.y)
{
}

Size& Size::operator= (const Size& other)
{
setSize(other.width, other.height);
return *this;
}

Size& Size::operator= (const Vec2& point)
{
setSize(point.x, point.y);
Expand Down Expand Up @@ -101,28 +91,18 @@ const Size Size::ZERO = Size(0, 0);
// implementation of Rect

Rect::Rect()
: Rect(0.0f, 0.0f, 0.0f, 0.0f)
{
setRect(0.0f, 0.0f, 0.0f, 0.0f);
}

Rect::Rect(float x, float y, float width, float height)
: origin(x, y), size(width, height)
{
setRect(x, y, width, height);
}
Rect::Rect(const Vec2& pos, const Size& dimension)
{
setRect(pos.x, pos.y, dimension.width, dimension.height);
}

Rect::Rect(const Rect& other)
{
setRect(other.origin.x, other.origin.y, other.size.width, other.size.height);
}

Rect& Rect::operator= (const Rect& other)
Rect::Rect(const Vec2& pos, const Size& dimension)
: origin(pos), size(dimension)
{
setRect(other.origin.x, other.origin.y, other.size.width, other.size.height);
return *this;
}

void Rect::setRect(float x, float y, float width, float height)
Expand Down
21 changes: 2 additions & 19 deletions cocos/math/CCGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CC_DLL Size
/**Height of the Size.*/
float height;
public:
/**Conversion from Vec2 to Size.*/
/**Conversion from Size to Vec2.*/
operator Vec2() const
{
return Vec2(width, height);
Expand All @@ -63,15 +63,9 @@ class CC_DLL Size
*/
Size();
Size(float width, float height);
Size(const Size& other);
explicit Size(const Vec2& point);
/**@}*/

/**
* @js NA
* @lua NA
*/
Size& operator= (const Size& other);
/**
* @js NA
* @lua NA
Expand Down Expand Up @@ -119,7 +113,7 @@ class CC_DLL Rect
/**Low left point of rect.*/
Vec2 origin;
/**Width and height of the rect.*/
Size size;
Size size;

public:
/**
Expand All @@ -138,17 +132,6 @@ class CC_DLL Rect
*/
Rect(const Vec2& pos, const Size& dimension);
/**
Copy constructor.
* @js NA
* @lua NA
*/
Rect(const Rect& other);
/**
* @js NA
* @lua NA
*/
Rect& operator= (const Rect& other);
/**
Set the x, y, width and height of Rect.
* @js NA
* @lua NA
Expand Down

0 comments on commit 4afda3a

Please sign in to comment.