Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor CCGeometry #19847

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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