![]() |
API 0.9.5
|
00001 /* 00002 * CGAffineTransform.j 00003 * AppKit 00004 * 00005 * Created by Francisco Tolmasky. 00006 * Copyright 2008, 280 North, Inc. 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 00024 00025 #define _function(inline) function inline { return _##inline; } 00026 00027 _function(CGAffineTransformMake(a, b, c, d, tx, ty)) 00028 _function(CGAffineTransformMakeIdentity()) 00029 _function(CGAffineTransformMakeCopy(anAffineTransform)) 00030 00031 _function(CGAffineTransformMakeScale(sx, sy)) 00032 _function(CGAffineTransformMakeTranslation(tx, ty)) 00033 _function(CGAffineTransformTranslate(aTransform, tx, ty)) 00034 _function(CGAffineTransformScale(aTransform, sx, sy)) 00035 00036 _function(CGAffineTransformConcat(lhs, rhs)) 00037 _function(CGPointApplyAffineTransform(aPoint, aTransform)) 00038 _function(CGSizeApplyAffineTransform(aSize, aTransform)) 00039 00040 _function(CGAffineTransformIsIdentity(aTransform)) 00041 _function(CGAffineTransformEqualToTransform(lhs, rhs)) 00042 00043 _function(CGStringCreateWithCGAffineTransform(aTransform)) 00044 00045 /* 00046 FIXME: !!!! 00047 @return void 00048 @group CGAffineTransform 00049 */ 00050 function CGAffineTransformCreateCopy(aTransform) 00051 { 00052 return _CGAffineTransformMakeCopy(aTransform); 00053 } 00054 00063 function CGAffineTransformMakeRotation(anAngle) 00064 { 00065 var sin = SIN(anAngle), 00066 cos = COS(anAngle); 00067 00068 return _CGAffineTransformMake(cos, sin, -sin, cos, 0.0, 0.0); 00069 } 00070 00078 function CGAffineTransformRotate(aTransform, anAngle) 00079 { 00080 var sin = SIN(anAngle), 00081 cos = COS(anAngle); 00082 00083 return { 00084 a:aTransform.a * cos + aTransform.c * sin, 00085 b:aTransform.b * cos + aTransform.d * sin, 00086 c:aTransform.c * cos - aTransform.a * sin, 00087 d:aTransform.d * cos - aTransform.b * sin, 00088 tx:aTransform.tx, 00089 ty:aTransform.ty 00090 }; 00091 } 00092 00099 function CGAffineTransformInvert(aTransform) 00100 { 00101 var determinant = 1 / (aTransform.a * aTransform.d - aTransform.b * aTransform.c); 00102 00103 return { 00104 a:determinant * aTransform.d, 00105 b:-determinant * aTransform.b, 00106 c:-determinant * aTransform.c, 00107 d:determinant * aTransform.a, 00108 tx:determinant * (aTransform.c * aTransform.ty - aTransform.d * aTransform.tx), 00109 ty:determinant * (aTransform.b * aTransform.tx - aTransform.a * aTransform.ty) 00110 }; 00111 } 00112 00121 function CGRectApplyAffineTransform(aRect, anAffineTransform) 00122 { 00123 var top = _CGRectGetMinY(aRect), 00124 left = _CGRectGetMinX(aRect), 00125 right = _CGRectGetMaxX(aRect), 00126 bottom = _CGRectGetMaxY(aRect), 00127 topLeft = CGPointApplyAffineTransform(_CGPointMake(left, top), anAffineTransform), 00128 topRight = CGPointApplyAffineTransform(_CGPointMake(right, top), anAffineTransform), 00129 bottomLeft = CGPointApplyAffineTransform(_CGPointMake(left, bottom), anAffineTransform), 00130 bottomRight = CGPointApplyAffineTransform(_CGPointMake(right, bottom), anAffineTransform), 00131 minX = MIN(topLeft.x, topRight.x, bottomLeft.x, bottomRight.x), 00132 maxX = MAX(topLeft.x, topRight.x, bottomLeft.x, bottomRight.x), 00133 minY = MIN(topLeft.y, topRight.y, bottomLeft.y, bottomRight.y), 00134 maxY = MAX(topLeft.y, topRight.y, bottomLeft.y, bottomRight.y); 00135 00136 return _CGRectMake(minX, minY, (maxX - minX), (maxY - minY)); 00137 } 00138 00145 function CPStringFromCGAffineTransform(anAffineTransform) 00146 { 00147 return '{' + anAffineTransform.a + ", " + anAffineTransform.b + ", " + anAffineTransform.c + ", " + anAffineTransform.d + ", " + anAffineTransform.tx + ", " + anAffineTransform.ty + '}'; 00148 }