2013-10-12 15:25:45 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:47:11 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2017-02-14 14:36:57 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-10-24 21:55:48 +08:00
|
|
|
Copyright (c) 2021 Bytedance Inc.
|
2013-10-12 15:25:45 +08:00
|
|
|
|
2022-07-09 01:23:11 +08:00
|
|
|
https://axis-project.github.io/
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-10-23 23:27:14 +08:00
|
|
|
#ifndef __MATH_RECT_H__
|
|
|
|
#define __MATH_RECT_H__
|
2013-10-12 15:25:45 +08:00
|
|
|
|
2021-10-23 23:27:14 +08:00
|
|
|
#include "math/Vec2.h"
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-27 11:34:52 +08:00
|
|
|
* @addtogroup base
|
2013-10-12 15:25:45 +08:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2015-03-27 11:34:52 +08:00
|
|
|
|
2015-03-24 21:33:55 +08:00
|
|
|
/**Rectangle area.*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL Rect
|
2013-10-12 15:25:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-24 21:33:55 +08:00
|
|
|
/**Low left point of rect.*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 origin;
|
2015-03-24 21:33:55 +08:00
|
|
|
/**Width and height of the rect.*/
|
2021-10-23 23:27:14 +08:00
|
|
|
Vec2 size;
|
2013-10-12 15:25:45 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
2015-03-24 21:33:55 +08:00
|
|
|
Constructor an empty Rect.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
Rect();
|
|
|
|
/**
|
2015-03-24 21:33:55 +08:00
|
|
|
Constructor a rect.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
Rect(float x, float y, float width, float height);
|
|
|
|
/**
|
2015-06-04 15:43:31 +08:00
|
|
|
Constructor a rect.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2021-10-23 23:27:14 +08:00
|
|
|
Rect(const Vec2& pos, const Vec2& dimension);
|
2015-06-04 15:43:31 +08:00
|
|
|
/**
|
2015-03-24 21:33:55 +08:00
|
|
|
Copy constructor.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
Rect(const Rect& other);
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
Rect& operator=(const Rect& other);
|
2013-10-12 15:25:45 +08:00
|
|
|
/**
|
2015-03-24 21:33:55 +08:00
|
|
|
Set the x, y, width and height of Rect.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
void setRect(float x, float y, float width, float height);
|
|
|
|
/**
|
2015-03-24 21:33:55 +08:00
|
|
|
Get the left of the rect.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
float getMinX() const; /// return the leftmost x-value of current rect
|
2013-10-12 15:25:45 +08:00
|
|
|
/**
|
2015-03-24 21:33:55 +08:00
|
|
|
Get the X coordinate of center point.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
float getMidX() const; /// return the midpoint x-value of current rect
|
2013-10-12 15:25:45 +08:00
|
|
|
/**
|
2015-03-24 21:33:55 +08:00
|
|
|
Get the right of rect.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
float getMaxX() const; /// return the rightmost x-value of current rect
|
2013-10-12 15:25:45 +08:00
|
|
|
/**
|
2015-03-24 21:33:55 +08:00
|
|
|
Get the bottom of rect.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
float getMinY() const; /// return the bottommost y-value of current rect
|
2013-10-12 15:25:45 +08:00
|
|
|
/**
|
2015-03-24 21:33:55 +08:00
|
|
|
Get the Y coordinate of center point.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
float getMidY() const; /// return the midpoint y-value of current rect
|
2013-10-12 15:25:45 +08:00
|
|
|
/**
|
2015-03-24 21:33:55 +08:00
|
|
|
Get top of rect.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
float getMaxY() const; /// return the topmost y-value of current rect
|
2013-10-12 15:25:45 +08:00
|
|
|
/**
|
2015-03-24 21:33:55 +08:00
|
|
|
Compare two rects.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
bool equals(const Rect& rect) const;
|
|
|
|
/**
|
2015-03-24 21:33:55 +08:00
|
|
|
Check if the points is contained in the rect.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
bool containsPoint(const Vec2& point) const;
|
2013-10-12 15:25:45 +08:00
|
|
|
/**
|
2015-03-24 21:33:55 +08:00
|
|
|
Check the intersect status of two rects.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
bool intersectsRect(const Rect& rect) const;
|
|
|
|
/**
|
2015-04-12 16:32:11 +08:00
|
|
|
Check the intersect status of the rect and a circle.
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
bool intersectsCircle(const Vec2& center, float radius) const;
|
|
|
|
/**
|
2015-03-24 21:33:55 +08:00
|
|
|
Get the min rect which can contain this and rect.
|
2013-10-12 15:25:45 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
Rect unionWithRect(const Rect& rect) const;
|
2015-03-24 21:33:55 +08:00
|
|
|
/**Compute the min rect which can contain this and rect, assign it to this.*/
|
2014-09-18 13:11:10 +08:00
|
|
|
void merge(const Rect& rect);
|
2015-03-24 21:33:55 +08:00
|
|
|
/**An empty Rect.*/
|
2013-10-12 15:25:45 +08:00
|
|
|
static const Rect ZERO;
|
|
|
|
};
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2013-10-12 15:25:45 +08:00
|
|
|
|
2015-03-27 11:34:52 +08:00
|
|
|
// end of base group
|
|
|
|
/// @}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // __MATH_RECT_H__
|