title: CGRectApplyAffineTransform then CGAffineTransformInvert doesn't return to original position
body: <p>This does not seem possible and I'm sure there's a simple solution but I cannot work it out.  My High School matrix math is a bit rusty :)</p>
  
  <p>I'm building a <code>CGAffineTransform</code> to do translation-rotation-translation of a <code>CGRect</code> and then trying to use the inverse <a href="http://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGAffineTransform/Reference/reference.html#//apple_ref/doc/uid/TP30000946-CH1g-F16979" rel="nofollow">CGAffineTransformInvert</a> to return to the original location. But it doesn't.  I've managed to reduce it to this:</p>
  
  <pre><code>//  start building the transform...
  //  translate so (0,0) is at centre of image
  CGAffineTransform affine = CGAffineTransformMakeTranslation(-100, -100);
  
  //  add a rotate
  affine = CGAffineTransformConcat(affine, CGAffineTransformMakeRotation(M_PI/4));
  
  //  get the inverse
  CGAffineTransform inverseAffine = CGAffineTransformInvert(affine);
  
  //  now test this: pick a starting CGRect
  CGRect start = CGRectMake(50, 40, 10, 20);
  
  // use my CGAffineTransform to move "start" to "midpoint"
  CGRect midpoint = CGRectApplyAffineTransform(start, affine);
  
  //  use the inverse to move "midpoint" to "finish"
  CGRect finish = CGRectApplyAffineTransform(midpoint, inverseAffine);
  
  //  what did we get
  NSLog(@"start    %5.1f %5.1f %5.1f %5.1f", start.origin.x, start.origin.y, start.size.width, start.size.height);
  NSLog(@"midpoint %5.1f %5.1f %5.1f %5.1f", midpoint.origin.x, midpoint.origin.y, midpoint.size.width, midpoint.size.height);
  NSLog(@"finish   %5.1f %5.1f %5.1f %5.1f", finish.origin.x, finish.origin.y, finish.size.width, finish.size.height);
  </code></pre>
  
  <p>The output looks like this:</p>
  
  <pre><code>2011-09-29 ... start     50.0  40.0  10.0  20.0
  2011-09-29 ... midpoint  -7.1 -77.8  21.2  21.2
  2011-09-29 ... finish    40.0  35.0  30.0  30.0
  </code></pre>
  
  <p>Shouldn't the finish rect be the same as the start?  Isn't that what <code>CGAffineTransformInvert</code> is supposed to do?</p>
  
  <p>If I do the same thing but with a <code>CGPoint</code> instead of a <code>CGRect</code> it seems to work ok.</p>