title: Check if CGRect is contained within another (transformed) rect
body: <p>I'm implementing a cropping feature and I'm trying to figure out how to test whether the crop rectangle is fully contained within the transformed image view. i.e. there should be no whitespace in the cropped portion of the image.</p>
  
  <p>I've tried to copy the behavior as implemented in this component: <a href="https://github.com/heitorfr/ios-image-editor" rel="nofollow">https://github.com/heitorfr/ios-image-editor</a>, which implements a similar check (see below), but I can't get it to work for my situation.</p>
  
  <pre><code>- (void)checkBoundsWithTransform:(CGAffineTransform)transform
  {
      CGRect r1 = [self boundingBoxForRect:self.preview.cropRect 
                          rotatedByRadians:[self imageRotation]];
      Rectangle r2 = [self applyTransform:transform 
                                   toRect:self.preview.initialImageFrame];
  
      CGAffineTransform t = 
       CGAffineTransformMakeTranslation(CGRectGetMidX(self.preview.cropRect), 
                                        CGRectGetMidY(self.preview.cropRect));
      t = CGAffineTransformRotate(t, -[self imageRotation]);
      t = CGAffineTransformTranslate(t, 
                                     -CGRectGetMidX(self.preview.cropRect), -
                                     CGRectGetMidY(self.preview.cropRect));
  
      Rectangle r3 = [self applyTransform:t toRectangle:r2];
  
      if(CGRectContainsRect([self CGRectFromRectangle:r3],r1)) {
          self.validTransform = transform;
      }
  }
  </code></pre>