CGAffineTransform.h
1 /* Copyright (c) 2006-2007 Christopher J. W. Lloyd 2 3 Permission is hereby granted, free of charge, to any person obtaining a copy of 4 this software and associated documentation files (the "Software"), to deal in 5 the Software without restriction, including without limitation the rights to 6 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 the Software, and to permit persons to whom the Software is furnished to do so, 8 subject to the following conditions: 9 10 The above copyright notice and this permission notice shall be included in all 11 copies or substantial portions of the Software. 12 13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 19 20 #import <CoreGraphics/CGGeometry.h> 21 #import <CoreGraphics/CoreGraphicsExport.h> 22 23 typedef struct { 24 CGFloat a; 25 CGFloat b; 26 CGFloat c; 27 CGFloat d; 28 CGFloat tx; 29 CGFloat ty; 30 } CGAffineTransform; 31 32 COREGRAPHICS_EXPORT const CGAffineTransform CGAffineTransformIdentity; 33 34 COREGRAPHICS_EXPORT bool CGAffineTransformIsIdentity(CGAffineTransform xform); 35 36 static CGAffineTransform __CGAffineTransformMake(CGFloat a, CGFloat b, CGFloat c, 37 CGFloat d, CGFloat tx, CGFloat ty) 38 { 39 CGAffineTransform xform = {a, b, c, d, tx, ty}; 40 return xform; 41 } 42 #define CGAffineTransformMake __CGAffineTransformMake 43 44 COREGRAPHICS_EXPORT CGAffineTransform 45 CGAffineTransformMakeRotation(CGFloat radians); 46 COREGRAPHICS_EXPORT CGAffineTransform 47 CGAffineTransformMakeScale(CGFloat scalex, CGFloat scaley); 48 COREGRAPHICS_EXPORT CGAffineTransform 49 CGAffineTransformMakeTranslation(CGFloat tx, CGFloat ty); 50 51 COREGRAPHICS_EXPORT CGAffineTransform 52 CGAffineTransformConcat(CGAffineTransform xform, CGAffineTransform append); 53 COREGRAPHICS_EXPORT CGAffineTransform 54 CGAffineTransformInvert(CGAffineTransform xform); 55 56 COREGRAPHICS_EXPORT CGAffineTransform 57 CGAffineTransformRotate(CGAffineTransform xform, CGFloat radians); 58 COREGRAPHICS_EXPORT CGAffineTransform 59 CGAffineTransformScale(CGAffineTransform xform, CGFloat scalex, CGFloat scaley); 60 COREGRAPHICS_EXPORT CGAffineTransform 61 CGAffineTransformTranslate(CGAffineTransform xform, CGFloat tx, CGFloat ty); 62 63 static CGPoint __CGPointApplyAffineTransform(CGPoint point, CGAffineTransform xform) { 64 CGPoint p; 65 66 p.x = xform.a * point.x + xform.c * point.y + xform.tx; 67 p.y = xform.b * point.x + xform.d * point.y + xform.ty; 68 69 return p; 70 } 71 #define CGPointApplyAffineTransform __CGPointApplyAffineTransform 72 73 static CGSize __CGSizeApplyAffineTransform(CGSize size, CGAffineTransform xform) { 74 CGSize s; 75 76 s.width = xform.a * size.width + xform.c * size.height; 77 s.height = xform.b * size.width + xform.d * size.height; 78 79 return s; 80 } 81 #define CGSizeApplyAffineTransform __CGSizeApplyAffineTransform 82 83 COREGRAPHICS_EXPORT CGRect CGRectApplyAffineTransform(CGRect rect, 84 CGAffineTransform t);