2010-07-13 13:44:00 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "CGGeometry.h"
|
|
|
|
|
|
|
|
// implementation of CGPoint
|
2010-08-04 15:46:12 +08:00
|
|
|
namespace cocos2d {
|
2010-07-13 13:44:00 +08:00
|
|
|
|
|
|
|
CGPoint::CGPoint(void)
|
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGPoint::CGPoint(float x, float y)
|
|
|
|
{
|
|
|
|
this->x = x;
|
|
|
|
this->y = y;
|
|
|
|
}
|
|
|
|
|
2010-09-29 11:49:38 +08:00
|
|
|
bool CGPoint::CGPointEqualToPoint(const CGPoint& point1, const CGPoint& point2)
|
2010-07-13 13:44:00 +08:00
|
|
|
{
|
|
|
|
return ((point1.x == point2.x) && (point1.y == point2.y));
|
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of CGSize
|
|
|
|
|
|
|
|
CGSize::CGSize(void)
|
|
|
|
{
|
|
|
|
width = 0;
|
|
|
|
height = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGSize::CGSize(float width, float height)
|
|
|
|
{
|
|
|
|
this->width = width;
|
|
|
|
this->height = height;
|
|
|
|
}
|
|
|
|
|
2010-09-29 11:49:38 +08:00
|
|
|
bool CGSize::CGSizeEqualToSize(const CGSize& size1, const CGSize& size2)
|
2010-07-13 13:44:00 +08:00
|
|
|
{
|
|
|
|
return ((size1.width == size2.width) && (size1.height == size2.height));
|
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of CGRect
|
|
|
|
|
|
|
|
CGRect::CGRect(void)
|
|
|
|
{
|
|
|
|
origin.x = 0;
|
|
|
|
origin.y = 0;
|
|
|
|
|
|
|
|
size.width = 0;
|
|
|
|
size.height = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGRect::CGRect(float x, float y, float width, float height)
|
|
|
|
{
|
|
|
|
origin.x = x;
|
|
|
|
origin.y = y;
|
|
|
|
|
|
|
|
size.width = width;
|
|
|
|
size.height = height;
|
|
|
|
}
|
|
|
|
|
2010-09-29 11:49:38 +08:00
|
|
|
bool CGRect::CGRectEqualToRect(const CGRect& rect1, const CGRect& rect2)
|
2010-07-13 13:44:00 +08:00
|
|
|
{
|
|
|
|
return (CGPoint::CGPointEqualToPoint(rect1.origin, rect2.origin)
|
|
|
|
&& CGSize::CGSizeEqualToSize(rect1.size, rect2.size));
|
|
|
|
}
|
|
|
|
|
2010-09-29 11:49:38 +08:00
|
|
|
CGFloat CGRect::CGRectGetMaxX(const CGRect& rect)
|
2010-07-13 13:44:00 +08:00
|
|
|
{
|
|
|
|
return rect.origin.x + rect.size.width;
|
|
|
|
}
|
|
|
|
|
2010-09-29 11:49:38 +08:00
|
|
|
CGFloat CGRect::CGRectGetMidX(const CGRect& rect)
|
2010-07-13 13:44:00 +08:00
|
|
|
{
|
|
|
|
return (float)(rect.origin.x + rect.size.width / 2.0);
|
|
|
|
}
|
|
|
|
|
2010-09-29 11:49:38 +08:00
|
|
|
CGFloat CGRect::CGRectGetMinX(const CGRect& rect)
|
2010-07-13 13:44:00 +08:00
|
|
|
{
|
|
|
|
return rect.origin.x;
|
|
|
|
}
|
|
|
|
|
2010-09-29 11:49:38 +08:00
|
|
|
CGFloat CGRect::CGRectGetMaxY(const CGRect& rect)
|
2010-07-13 13:44:00 +08:00
|
|
|
{
|
|
|
|
return rect.origin.y + rect.size.height;
|
|
|
|
}
|
|
|
|
|
2010-09-29 11:49:38 +08:00
|
|
|
CGFloat CGRect::CGRectGetMidY(const CGRect& rect)
|
2010-07-13 13:44:00 +08:00
|
|
|
{
|
|
|
|
return (float)(rect.origin.y + rect.size.height / 2.0);
|
|
|
|
}
|
|
|
|
|
2010-09-29 11:49:38 +08:00
|
|
|
CGFloat CGRect::CGRectGetMinY(const CGRect& rect)
|
2010-07-13 13:44:00 +08:00
|
|
|
{
|
|
|
|
return rect.origin.y;
|
|
|
|
}
|
|
|
|
|
2010-09-29 11:49:38 +08:00
|
|
|
bool CGRect::CGRectContainsPoint(const CGRect& rect, const CGPoint& point)
|
2010-07-13 13:44:00 +08:00
|
|
|
{
|
|
|
|
bool bRet = false;
|
|
|
|
|
|
|
|
if (point.x >= CGRectGetMinX(rect) && point.x <= CGRectGetMaxX(rect)
|
|
|
|
&& point.y >= CGRectGetMinY(rect) && point.y <= CGRectGetMaxY(rect))
|
|
|
|
{
|
|
|
|
bRet = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
2010-09-29 11:49:38 +08:00
|
|
|
|
|
|
|
bool CGRect::CGRectIntersectsRect(const CGRect& rectA, const CGRect& rectB)
|
|
|
|
{
|
2010-09-29 16:06:03 +08:00
|
|
|
return !(CGRectGetMaxX(rectA) < CGRectGetMinX(rectB)||
|
|
|
|
CGRectGetMaxX(rectB) < CGRectGetMinX(rectA)||
|
|
|
|
CGRectGetMaxY(rectA) < CGRectGetMinY(rectB)||
|
|
|
|
CGRectGetMaxY(rectB) < CGRectGetMinY(rectB));
|
2010-09-29 11:49:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-04 15:46:12 +08:00
|
|
|
}//namespace cocos2d {
|