2010-08-04 16:54:58 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __COCOS_CGGEMETRY_H__
|
|
|
|
#define __COCOS_CGGEMETRY_H__
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
#include "CCCommon.h"
|
2011-01-15 18:05:35 +08:00
|
|
|
|
2010-08-04 16:54:58 +08:00
|
|
|
namespace cocos2d {
|
|
|
|
|
|
|
|
typedef float CGFloat;
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCPoint
|
2010-08-04 16:54:58 +08:00
|
|
|
{
|
|
|
|
public:
|
2011-11-18 21:23:54 +08:00
|
|
|
float x;
|
|
|
|
float y;
|
2010-08-04 16:54:58 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2011-11-18 21:23:54 +08:00
|
|
|
CCPoint();
|
|
|
|
CCPoint(float x, float y);
|
2010-08-04 16:54:58 +08:00
|
|
|
|
|
|
|
public:
|
2011-11-18 21:23:54 +08:00
|
|
|
static bool CCPointEqualToPoint(const CCPoint& point1, const CCPoint& point2);
|
2010-08-04 16:54:58 +08:00
|
|
|
};
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCSize
|
2010-08-04 16:54:58 +08:00
|
|
|
{
|
|
|
|
public:
|
2011-11-18 21:23:54 +08:00
|
|
|
float width;
|
|
|
|
float height;
|
2010-08-04 16:54:58 +08:00
|
|
|
|
|
|
|
public:
|
2011-11-18 21:23:54 +08:00
|
|
|
CCSize();
|
|
|
|
CCSize(float width, float height);
|
2010-08-04 16:54:58 +08:00
|
|
|
|
|
|
|
public:
|
2011-11-18 21:23:54 +08:00
|
|
|
static bool CCSizeEqualToSize(const CCSize& size1, const CCSize& size2);
|
2010-08-04 16:54:58 +08:00
|
|
|
};
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCRect
|
2010-08-04 16:54:58 +08:00
|
|
|
{
|
|
|
|
public:
|
2011-11-18 21:23:54 +08:00
|
|
|
CCPoint origin;
|
|
|
|
CCSize size;
|
2010-08-04 16:54:58 +08:00
|
|
|
|
|
|
|
public:
|
2011-11-18 21:23:54 +08:00
|
|
|
CCRect();
|
|
|
|
CCRect(float x, float y, float width, float height);
|
2010-08-04 16:54:58 +08:00
|
|
|
|
|
|
|
public:
|
2011-11-18 21:23:54 +08:00
|
|
|
//! return the leftmost x-value of 'rect'
|
|
|
|
static CGFloat CCRectGetMinX(const CCRect& rect);
|
2010-08-04 16:54:58 +08:00
|
|
|
|
2011-11-18 21:23:54 +08:00
|
|
|
//! return the rightmost x-value of 'rect'
|
|
|
|
static CGFloat CCRectGetMaxX(const CCRect& rect);
|
2010-08-04 16:54:58 +08:00
|
|
|
|
2011-11-18 21:23:54 +08:00
|
|
|
//! return the midpoint x-value of 'rect'
|
|
|
|
static CGFloat CCRectGetMidX(const CCRect& rect);
|
2010-08-04 16:54:58 +08:00
|
|
|
|
2011-11-18 21:23:54 +08:00
|
|
|
//! Return the bottommost y-value of `rect'
|
|
|
|
static CGFloat CCRectGetMinY(const CCRect& rect);
|
2010-08-04 16:54:58 +08:00
|
|
|
|
2011-11-18 21:23:54 +08:00
|
|
|
//! Return the topmost y-value of `rect'
|
|
|
|
static CGFloat CCRectGetMaxY(const CCRect& rect);
|
2010-08-04 16:54:58 +08:00
|
|
|
|
2011-11-18 21:23:54 +08:00
|
|
|
//! Return the midpoint y-value of `rect'
|
|
|
|
static CGFloat CCRectGetMidY(const CCRect& rect);
|
2010-08-04 16:54:58 +08:00
|
|
|
|
2011-11-18 21:23:54 +08:00
|
|
|
static bool CCRectEqualToRect(const CCRect& rect1, const CCRect& rect2);
|
2010-08-04 16:54:58 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
static bool CCRectContainsPoint(const CCRect& rect, const CCPoint& point);
|
2010-09-29 11:49:38 +08:00
|
|
|
|
2011-11-18 21:23:54 +08:00
|
|
|
static bool CCRectIntersectsRect(const CCRect& rectA, const CCRect& rectB);
|
2010-08-04 16:54:58 +08:00
|
|
|
};
|
|
|
|
|
2010-09-29 11:49:38 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
#define CCPointMake(x, y) CCPoint((x), (y))
|
|
|
|
#define CCSizeMake(width, height) CCSize((width), (height))
|
|
|
|
#define CCRectMake(x, y, width, height) CCRect((x), (y), (width), (height))
|
2010-08-04 16:54:58 +08:00
|
|
|
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
const CCPoint CCPointZero = CCPointMake(0,0);
|
2010-08-04 16:54:58 +08:00
|
|
|
|
2011-11-18 21:23:54 +08:00
|
|
|
/* The "zero" size -- equivalent to CCSizeMake(0, 0). */
|
2011-03-07 17:11:57 +08:00
|
|
|
const CCSize CCSizeZero = CCSizeMake(0,0);
|
2010-08-04 16:54:58 +08:00
|
|
|
|
2011-11-18 21:23:54 +08:00
|
|
|
/* The "zero" rectangle -- equivalent to CCRectMake(0, 0, 0, 0). */
|
2011-03-07 17:11:57 +08:00
|
|
|
const CCRect CCRectZero = CCRectMake(0,0,0,0);
|
2010-08-04 16:54:58 +08:00
|
|
|
|
2011-11-18 21:23:54 +08:00
|
|
|
}//namespace cocos2d
|
2010-08-04 16:54:58 +08:00
|
|
|
|
|
|
|
#endif // __COCOS_CGGEMETRY_H__
|