補足: 回答内関数のObjective-C版を付記します
// e.g.)
// CGPoint points[4];
// [self rectToPoints: rect points: points];
- (void)rectToPoints:(CGRect)rect points:(CGPoint[4])points {
points[0] = CGPointMake(CGRectGetMinX(rect), CGRectGetMinY(rect));
points[1] = CGPointMake(CGRectGetMaxX(rect), CGRectGetMinY(rect));
points[2] = CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect));
points[3] = CGPointMake(CGRectGetMinX(rect), CGRectGetMaxY(rect));
}
// e.g.)
// CGRect rect = [self pointsToRect: points];
- (CGRect)pointsToRect:(CGPoint[4])points {
CGFloat minX = points[0].x;
CGFloat maxX = points[0].x;
CGFloat minY = points[0].y;
CGFloat maxY = points[0].y;
for (int i = 0; i < 4; i++) {
minX = fminf(minX, points[i].x);
maxX = fmaxf(maxX, points[i].x);
minY = fminf(minY, points[i].y);
maxY = fmaxf(maxY, points[i].y);
}
return CGRectMake(minX, minY, maxX - minX, maxY - minY);
}