00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00047 #import <CoreGraphics/CGGeometry.h>
00048 #import <math.h>
00049 #import <objc/objc.h>
00050
00051 #ifdef __cplusplus
00052 extern "C" {
00053 #endif
00054
00059 #define ccp(__X__,__Y__) CGPointMake(__X__,__Y__)
00060
00061
00066 static inline CGPoint
00067 ccpNeg(const CGPoint v)
00068 {
00069 return ccp(-v.x, -v.y);
00070 }
00071
00076 static inline CGPoint
00077 ccpAdd(const CGPoint v1, const CGPoint v2)
00078 {
00079 return ccp(v1.x + v2.x, v1.y + v2.y);
00080 }
00081
00086 static inline CGPoint
00087 ccpSub(const CGPoint v1, const CGPoint v2)
00088 {
00089 return ccp(v1.x - v2.x, v1.y - v2.y);
00090 }
00091
00096 static inline CGPoint
00097 ccpMult(const CGPoint v, const CGFloat s)
00098 {
00099 return ccp(v.x*s, v.y*s);
00100 }
00101
00106 static inline CGPoint
00107 ccpMidpoint(const CGPoint v1, const CGPoint v2)
00108 {
00109 return ccpMult(ccpAdd(v1, v2), 0.5f);
00110 }
00111
00116 static inline CGFloat
00117 ccpDot(const CGPoint v1, const CGPoint v2)
00118 {
00119 return v1.x*v2.x + v1.y*v2.y;
00120 }
00121
00126 static inline CGFloat
00127 ccpCross(const CGPoint v1, const CGPoint v2)
00128 {
00129 return v1.x*v2.y - v1.y*v2.x;
00130 }
00131
00136 static inline CGPoint
00137 ccpPerp(const CGPoint v)
00138 {
00139 return ccp(-v.y, v.x);
00140 }
00141
00146 static inline CGPoint
00147 ccpRPerp(const CGPoint v)
00148 {
00149 return ccp(v.y, -v.x);
00150 }
00151
00156 static inline CGPoint
00157 ccpProject(const CGPoint v1, const CGPoint v2)
00158 {
00159 return ccpMult(v2, ccpDot(v1, v2)/ccpDot(v2, v2));
00160 }
00161
00166 static inline CGPoint
00167 ccpRotate(const CGPoint v1, const CGPoint v2)
00168 {
00169 return ccp(v1.x*v2.x - v1.y*v2.y, v1.x*v2.y + v1.y*v2.x);
00170 }
00171
00176 static inline CGPoint
00177 ccpUnrotate(const CGPoint v1, const CGPoint v2)
00178 {
00179 return ccp(v1.x*v2.x + v1.y*v2.y, v1.y*v2.x - v1.x*v2.y);
00180 }
00181
00186 static inline CGFloat
00187 ccpLengthSQ(const CGPoint v)
00188 {
00189 return ccpDot(v, v);
00190 }
00191
00196 CGFloat ccpLength(const CGPoint v);
00197
00202 CGFloat ccpDistance(const CGPoint v1, const CGPoint v2);
00203
00208 CGPoint ccpNormalize(const CGPoint v);
00209
00214 CGPoint ccpForAngle(const CGFloat a);
00215
00220 CGFloat ccpToAngle(const CGPoint v);
00221
00222
00226 float clampf(float value, float min_inclusive, float max_inclusive);
00227
00231 CGPoint ccpClamp(CGPoint p, CGPoint from, CGPoint to);
00232
00236 CGPoint ccpFromSize(CGSize s);
00237
00245 CGPoint ccpCompOp(CGPoint p, float (*opFunc)(float));
00246
00254 CGPoint ccpLerp(CGPoint a, CGPoint b, float alpha);
00255
00256
00260 BOOL ccpFuzzyEqual(CGPoint a, CGPoint b, float variance);
00261
00262
00267 CGPoint ccpCompMult(CGPoint a, CGPoint b);
00268
00272 float ccpAngleSigned(CGPoint a, CGPoint b);
00273
00277 float ccpAngle(CGPoint a, CGPoint b);
00278
00286 CGPoint ccpRotateByAngle(CGPoint v, CGPoint pivot, float angle);
00287
00309 BOOL ccpLineIntersect(CGPoint p1, CGPoint p2,
00310 CGPoint p3, CGPoint p4,
00311 float *s, float *t);
00312
00313 #ifdef __cplusplus
00314 }
00315 #endif