mirror of https://github.com/axmolengine/axmol.git
Fix a typo here. Two values are not swapped correctly, max_inclusive is still equal to itself.
This commit is contained in:
parent
c74502da94
commit
8edbbd56a9
|
@ -1,34 +1,34 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
Copyright (c) 2007 Scott Lembcke
|
||||
Copyright (c) 2010 Lam Pham
|
||||
|
||||
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 "CCPointExtension.h"
|
||||
#include "ccMacros.h" // FLT_EPSILON
|
||||
#include <stdio.h>
|
||||
namespace cocos2d {
|
||||
|
||||
Copyright (c) 2010 Lam Pham
|
||||
|
||||
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 "CCPointExtension.h"
|
||||
#include "ccMacros.h" // FLT_EPSILON
|
||||
#include <stdio.h>
|
||||
namespace cocos2d {
|
||||
|
||||
#define kCCPointEpsilon FLT_EPSILON
|
||||
|
||||
CGFloat
|
||||
|
@ -69,10 +69,7 @@ CCPoint ccpLerp(const CCPoint& a, const CCPoint& b, float alpha)
|
|||
float clampf(float value, float min_inclusive, float max_inclusive)
|
||||
{
|
||||
if (min_inclusive > max_inclusive) {
|
||||
float ftmp;
|
||||
ftmp = min_inclusive;
|
||||
min_inclusive = max_inclusive;
|
||||
max_inclusive = min_inclusive;
|
||||
CC_SWAP(min_inclusive, max_inclusive, float);
|
||||
}
|
||||
return value < min_inclusive ? min_inclusive : value < max_inclusive? value : max_inclusive;
|
||||
}
|
||||
|
@ -119,79 +116,79 @@ CCPoint ccpRotateByAngle(const CCPoint& v, const CCPoint& pivot, float angle)
|
|||
CCPoint r = ccpSub(v, pivot);
|
||||
float cosa = cosf(angle), sina = sinf(angle);
|
||||
float t = r.x;
|
||||
r.x = t*cosa - r.y*sina + pivot.x;
|
||||
r.x = t*cosa - r.y*sina + pivot.x;
|
||||
r.y = t*sina + r.y*cosa + pivot.y;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
bool ccpSegmentIntersect(const CCPoint& A, const CCPoint& B, const CCPoint& C, const CCPoint& D)
|
||||
{
|
||||
float S, T;
|
||||
|
||||
if( ccpLineIntersect(A, B, C, D, &S, &T )
|
||||
&& (S >= 0.0f && S <= 1.0f && T >= 0.0f && T <= 1.0f) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
CCPoint ccpIntersectPoint(const CCPoint& A, const CCPoint& B, const CCPoint& C, const CCPoint& D)
|
||||
{
|
||||
float S, T;
|
||||
|
||||
if( ccpLineIntersect(A, B, C, D, &S, &T) )
|
||||
{
|
||||
// Point of intersection
|
||||
CCPoint P;
|
||||
P.x = A.x + S * (B.x - A.x);
|
||||
P.y = A.y + S * (B.y - A.y);
|
||||
return P;
|
||||
}
|
||||
|
||||
return CCPointZero;
|
||||
|
||||
bool ccpSegmentIntersect(const CCPoint& A, const CCPoint& B, const CCPoint& C, const CCPoint& D)
|
||||
{
|
||||
float S, T;
|
||||
|
||||
if( ccpLineIntersect(A, B, C, D, &S, &T )
|
||||
&& (S >= 0.0f && S <= 1.0f && T >= 0.0f && T <= 1.0f) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
CCPoint ccpIntersectPoint(const CCPoint& A, const CCPoint& B, const CCPoint& C, const CCPoint& D)
|
||||
{
|
||||
float S, T;
|
||||
|
||||
if( ccpLineIntersect(A, B, C, D, &S, &T) )
|
||||
{
|
||||
// Point of intersection
|
||||
CCPoint P;
|
||||
P.x = A.x + S * (B.x - A.x);
|
||||
P.y = A.y + S * (B.y - A.y);
|
||||
return P;
|
||||
}
|
||||
|
||||
return CCPointZero;
|
||||
}
|
||||
|
||||
bool ccpLineIntersect(const CCPoint& A, const CCPoint& B,
|
||||
const CCPoint& C, const CCPoint& D,
|
||||
float *S, float *T)
|
||||
{
|
||||
// FAIL: Line undefined
|
||||
if ( (A.x==B.x && A.y==B.y) || (C.x==D.x && C.y==D.y) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const float BAx = B.x - A.x;
|
||||
const float BAy = B.y - A.y;
|
||||
const float DCx = D.x - C.x;
|
||||
const float DCy = D.y - C.y;
|
||||
const float ACx = A.x - C.x;
|
||||
const float ACy = A.y - C.y;
|
||||
|
||||
const float denom = DCy*BAx - DCx*BAy;
|
||||
|
||||
*S = DCx*ACy - DCy*ACx;
|
||||
*T = BAx*ACy - BAy*ACx;
|
||||
|
||||
if (denom == 0)
|
||||
{
|
||||
if (*S == 0 || *T == 0)
|
||||
{
|
||||
// Lines incident
|
||||
return true;
|
||||
}
|
||||
// Lines parallel and not incident
|
||||
return false;
|
||||
}
|
||||
|
||||
*S = *S / denom;
|
||||
*T = *T / denom;
|
||||
|
||||
// Point of intersection
|
||||
// CGPoint P;
|
||||
// P.x = A.x + *S * (B.x - A.x);
|
||||
// P.y = A.y + *S * (B.y - A.y);
|
||||
|
||||
// FAIL: Line undefined
|
||||
if ( (A.x==B.x && A.y==B.y) || (C.x==D.x && C.y==D.y) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const float BAx = B.x - A.x;
|
||||
const float BAy = B.y - A.y;
|
||||
const float DCx = D.x - C.x;
|
||||
const float DCy = D.y - C.y;
|
||||
const float ACx = A.x - C.x;
|
||||
const float ACy = A.y - C.y;
|
||||
|
||||
const float denom = DCy*BAx - DCx*BAy;
|
||||
|
||||
*S = DCx*ACy - DCy*ACx;
|
||||
*T = BAx*ACy - BAy*ACx;
|
||||
|
||||
if (denom == 0)
|
||||
{
|
||||
if (*S == 0 || *T == 0)
|
||||
{
|
||||
// Lines incident
|
||||
return true;
|
||||
}
|
||||
// Lines parallel and not incident
|
||||
return false;
|
||||
}
|
||||
|
||||
*S = *S / denom;
|
||||
*T = *T / denom;
|
||||
|
||||
// Point of intersection
|
||||
// CGPoint P;
|
||||
// P.x = A.x + *S * (B.x - A.x);
|
||||
// P.y = A.y + *S * (B.y - A.y);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -201,4 +198,4 @@ float ccpAngle(const CCPoint& a, const CCPoint& b)
|
|||
if( fabs(angle) < kCCPointEpsilon ) return 0.f;
|
||||
return angle;
|
||||
}
|
||||
}//namespace cocos2d
|
||||
}//namespace cocos2d
|
||||
|
|
Loading…
Reference in New Issue