سؤال

For given transformation calculation,

CGAffineTransform preferredTransform = CGAffineTransformMake(-1, 0, 0, -1, 1920, 1080);
CGAffineTransform transform1 = CGAffineTransformConcat(CGAffineTransformMakeTranslation(-preferredTransform.tx, -preferredTransform.ty), CGAffineTransformMakeRotation(M_PI));
NSLog(@"%@", NSStringFromCGAffineTransform(transform1));

The output would be [-1, 1.2246467991473532e-16, -1.2246467991473532e-16, -1, 1920.0000000000002, 1079.9999999999998] yet I would expect it to be [-1, 0, 0, -1, 1920, 1080]

Why the rounding errors? Should I apply the transformations differently to produce rounded results?

هل كانت مفيدة؟

المحلول

On a 32-bit iPad rounding is correct, However, on a 64-bit iPad the rounding errors occurs. Since rotation by M_PI is the same as scaling by -1, this can be easily fixed by changing it to:

CGAffineTransform preferredTransform = CGAffineTransformMake(-1, 0, 0, -1, 1920, 1080);
CGAffineTransform transform1 = CGAffineTransformConcat(CGAffineTransformMakeTranslation(-preferredTransform.tx, -preferredTransform.ty), **CGAffineTransformMakeScale(-1, -1)**);

NSLog(@"%@", NSStringFromCGAffineTransform(transform1));

نصائح أخرى

The specified rounding errors are due to 64-bit architecture. If you launch on 32-bit simulator, you shouldn't see those rounding errors.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top