cocos2d-iphone  2.1
Improved Cocos2D API Reference (iOS version) for www.kobold2d.com developers
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Defines
CGPointExtension.h File Reference
#import "ccMacros.h"
#import <CoreGraphics/CGGeometry.h>
#import <math.h>
#import <objc/objc.h>
+ Include dependency graph for CGPointExtension.h:

Functions

static CGPoint ccp (CGFloat x, CGFloat y)
static CGPoint ccpNeg (const CGPoint v)
static CGPoint ccpAdd (const CGPoint v1, const CGPoint v2)
static CGPoint ccpSub (const CGPoint v1, const CGPoint v2)
static CGPoint ccpMult (const CGPoint v, const CGFloat s)
static CGPoint ccpMidpoint (const CGPoint v1, const CGPoint v2)
static CGFloat ccpDot (const CGPoint v1, const CGPoint v2)
static CGFloat ccpCross (const CGPoint v1, const CGPoint v2)
static CGPoint ccpPerp (const CGPoint v)
static CGPoint ccpRPerp (const CGPoint v)
static CGPoint ccpProject (const CGPoint v1, const CGPoint v2)
static CGPoint ccpRotate (const CGPoint v1, const CGPoint v2)
static CGPoint ccpUnrotate (const CGPoint v1, const CGPoint v2)
static CGFloat ccpLengthSQ (const CGPoint v)
static CGFloat ccpDistanceSQ (const CGPoint p1, const CGPoint p2)
CGFloat ccpLength (const CGPoint v)
CGFloat ccpDistance (const CGPoint v1, const CGPoint v2)
CGPoint ccpNormalize (const CGPoint v)
CGPoint ccpForAngle (const CGFloat a)
CGFloat ccpToAngle (const CGPoint v)
float clampf (float value, float min_inclusive, float max_inclusive)
CGPoint ccpClamp (CGPoint p, CGPoint from, CGPoint to)
CGPoint ccpFromSize (CGSize s)
CGPoint ccpCompOp (CGPoint p, float(*opFunc)(float))
CGPoint ccpLerp (CGPoint a, CGPoint b, float alpha)
BOOL ccpFuzzyEqual (CGPoint a, CGPoint b, float variance)
CGPoint ccpCompMult (CGPoint a, CGPoint b)
float ccpAngleSigned (CGPoint a, CGPoint b)
float ccpAngle (CGPoint a, CGPoint b)
CGPoint ccpRotateByAngle (CGPoint v, CGPoint pivot, float angle)
BOOL ccpLineIntersect (CGPoint p1, CGPoint p2, CGPoint p3, CGPoint p4, float *s, float *t)
BOOL ccpSegmentIntersect (CGPoint A, CGPoint B, CGPoint C, CGPoint D)
CGPoint ccpIntersectPoint (CGPoint A, CGPoint B, CGPoint C, CGPoint D)

Detailed Description

CGPoint extensions based on Chipmunk's cpVect file. These extensions work both with CGPoint and cpVect.

The "ccp" prefix means: "CoCos2d Point"

Examples:

  • ccpAdd( ccp(1,1), ccp(2,2) ); // preferred cocos2d way
  • ccpAdd( CGPointMake(1,1), CGPointMake(2,2) ); // also ok but more verbose
  • cpvadd( cpv(1,1), cpv(2,2) ); // way of the chipmunk
    • ccpAdd( cpv(1,1), cpv(2,2) ); // mixing chipmunk and cocos2d (avoid)
    • cpvadd( CGPointMake(1,1), CGPointMake(2,2) ); // mixing chipmunk and CG (avoid)

Function Documentation

static CGPoint ccp ( CGFloat  x,
CGFloat  y 
) [inline, static]

Helper macro that creates a CGPoint

Returns:
CGPoint
Since:
v0.7.2
static CGPoint ccpAdd ( const CGPoint  v1,
const CGPoint  v2 
) [inline, static]

Calculates sum of two points.

Returns:
CGPoint
Since:
v0.7.2
float ccpAngle ( CGPoint  a,
CGPoint  b 
)
Returns:
the angle in radians between two vector directions
Since:
v0.99.1
float ccpAngleSigned ( CGPoint  a,
CGPoint  b 
)
Returns:
the signed angle in radians between two vector directions
Since:
v0.99.1
CGPoint ccpClamp ( CGPoint  p,
CGPoint  from,
CGPoint  to 
)

Clamp a point between from and to.

Since:
v0.99.1
CGPoint ccpCompMult ( CGPoint  a,
CGPoint  b 
)

Multiplies a nd b components, a.x*b.x, a.y*b.y

Returns:
a component-wise multiplication
Since:
v0.99.1
CGPoint ccpCompOp ( CGPoint  p,
float(*)(float)  opFunc 
)

Run a math operation function on each point component absf, fllorf, ceilf, roundf any function that has the signature: float func(float); For example: let's try to take the floor of x,y ccpCompOp(p,floorf);

Since:
v0.99.1
static CGFloat ccpCross ( const CGPoint  v1,
const CGPoint  v2 
) [inline, static]

Calculates cross product of two points.

Returns:
CGFloat
Since:
v0.7.2
CGFloat ccpDistance ( const CGPoint  v1,
const CGPoint  v2 
)

Calculates the distance between two points

Returns:
CGFloat
Since:
v0.7.2
static CGFloat ccpDistanceSQ ( const CGPoint  p1,
const CGPoint  p2 
) [inline, static]

Calculates the square distance between two points (not calling sqrt() )

Returns:
CGFloat
Since:
v1.1
static CGFloat ccpDot ( const CGPoint  v1,
const CGPoint  v2 
) [inline, static]

Calculates dot product of two points.

Returns:
CGFloat
Since:
v0.7.2
CGPoint ccpForAngle ( const CGFloat  a)

Converts radians to a normalized vector.

Returns:
CGPoint
Since:
v0.7.2
CGPoint ccpFromSize ( CGSize  s)

Quickly convert CGSize to a CGPoint

Since:
v0.99.1
BOOL ccpFuzzyEqual ( CGPoint  a,
CGPoint  b,
float  variance 
)
Returns:
if points have fuzzy equality which means equal with some degree of variance.
Since:
v0.99.1
CGFloat ccpLength ( const CGPoint  v)

Calculates distance between point an origin

Returns:
CGFloat
Since:
v0.7.2
static CGFloat ccpLengthSQ ( const CGPoint  v) [inline, static]

Calculates the square length of a CGPoint (not calling sqrt() )

Returns:
CGFloat
Since:
v0.7.2
CGPoint ccpLerp ( CGPoint  a,
CGPoint  b,
float  alpha 
)

Linear Interpolation between two points a and b

Returns:
alpha == 0 ? a alpha == 1 ? b otherwise a value between a..b
Since:
v0.99.1
BOOL ccpLineIntersect ( CGPoint  p1,
CGPoint  p2,
CGPoint  p3,
CGPoint  p4,
float *  s,
float *  t 
)

A general line-line intersection test

Parameters:
p1is the startpoint for the first line P1 = (p1 - p2)
p2is the endpoint for the first line P1 = (p1 - p2)
p3is the startpoint for the second line P2 = (p3 - p4)
p4is the endpoint for the second line P2 = (p3 - p4)
sis the range for a hitpoint in P1 (pa = p1 + s*(p2 - p1))
tis the range for a hitpoint in P3 (pa = p2 + t*(p4 - p3))
Returns:
bool indicating successful intersection of a line note that to truly test intersection for segments we have to make sure that s & t lie within [0..1] and for rays, make sure s & t > 0 the hit point is p3 + t * (p4 - p3); the hit point also is p1 + s * (p2 - p1);
Since:
v0.99.1
static CGPoint ccpMidpoint ( const CGPoint  v1,
const CGPoint  v2 
) [inline, static]

Calculates midpoint between two points.

Returns:
CGPoint
Since:
v0.7.2
static CGPoint ccpMult ( const CGPoint  v,
const CGFloat  s 
) [inline, static]

Returns point multiplied by given factor.

Returns:
CGPoint
Since:
v0.7.2
static CGPoint ccpNeg ( const CGPoint  v) [inline, static]

Returns opposite of point.

Returns:
CGPoint
Since:
v0.7.2
CGPoint ccpNormalize ( const CGPoint  v)

Returns point multiplied to a length of 1.

Returns:
CGPoint
Since:
v0.7.2
static CGPoint ccpPerp ( const CGPoint  v) [inline, static]

Calculates perpendicular of v, rotated 90 degrees counter-clockwise -- cross(v, perp(v)) >= 0

Returns:
CGPoint
Since:
v0.7.2
static CGPoint ccpProject ( const CGPoint  v1,
const CGPoint  v2 
) [inline, static]

Calculates the projection of v1 over v2.

Returns:
CGPoint
Since:
v0.7.2
static CGPoint ccpRotate ( const CGPoint  v1,
const CGPoint  v2 
) [inline, static]

Rotates two points.

Returns:
CGPoint
Since:
v0.7.2
CGPoint ccpRotateByAngle ( CGPoint  v,
CGPoint  pivot,
float  angle 
)

Rotates a point counter clockwise by the angle around a pivot

Parameters:
vis the point to rotate
pivotis the pivot, naturally
angleis the angle of rotation cw in radians
Returns:
the rotated point
Since:
v0.99.1
static CGPoint ccpRPerp ( const CGPoint  v) [inline, static]

Calculates perpendicular of v, rotated 90 degrees clockwise -- cross(v, rperp(v)) <= 0

Returns:
CGPoint
Since:
v0.7.2
static CGPoint ccpSub ( const CGPoint  v1,
const CGPoint  v2 
) [inline, static]

Calculates difference of two points.

Returns:
CGPoint
Since:
v0.7.2
CGFloat ccpToAngle ( const CGPoint  v)

Converts a vector to radians.

Returns:
CGFloat
Since:
v0.7.2
static CGPoint ccpUnrotate ( const CGPoint  v1,
const CGPoint  v2 
) [inline, static]

Unrotates two points.

Returns:
CGPoint
Since:
v0.7.2
float clampf ( float  value,
float  min_inclusive,
float  max_inclusive 
)

Clamp a value between from and to.

Since:
v0.99.1