To the same extent you probably know, Apple provides a bunch of functionality representing manipulating objects in 2D universe using CGAffineTransform. Oddly, Apple doesn't provide you with a way to extract the degree, transform, and rotation in sequence from a CGAffineTransform and they don't provide several shearing functionality next to all.
Here are a quantity of supplementary inline functions to facilitate I consume. This adds the capability to extract part ideals of the CGAffineTransform and furthermore adds the capability to create and extract cut in sequence.
To the same extent until the end of time, this code is open to consume exclusive of restriction or limitation, but has rejection warranty whatever. If you set-up a bug, feel open to give permission me know around the set-up so I can incorporate the set-up.
#ifndef __MCP_AFFINE_TRANSFORM_ADDITIONS__
#define __MCP_AFFINE_TRANSFORM_ADDITIONS__
#import <CoreGraphics/CoreGraphics.H>
#ifdef __cplusplus
Extern "C" {
#endif
#define degreesToRadian(x) (M_PI * x / 180.0)
#define radiansToDegrees(x) (180.0 * x / M_PI)
Static inline CGAffineTransform CGAffineTransformMakeShear(CGFloat shearX, CGFloat shearY)
{
Return CGAffineTransformMake(1.F, shearY, shearX, 1.F, 0.F, 0.F);
}
Static inline CGAffineTransform CGAffineTransformShear(CGAffineTransform transform, CGFloat shearX, CGFloat shearY)
{
CGAffineTransform sheared = CGAffineTransformMakeShear(shearX, shearY);
Return CGAffineTransformConcat(transform, sheared);
}
Static inline CGFloat CGAffineTransformGetDeltaX(CGAffineTransform transform) {return transform.Tx;};
Static inline CGFloat CGAffineTransformGetDeltaY(CGAffineTransform transform) {return transform.Ty;};
Static inline CGFloat CGAffineTransformGetScaleX(CGAffineTransform transform) {return sqrtf( (transform.A * transform.A) + (transform.C * transform.C) );};
Static inline CGFloat CGAffineTransformGetScaleY(CGAffineTransform transform) {return sqrtf( (transform.B * transform.B) + (transform.D * transform.D) );};
Static inline CGFloat CGAffineTransformGetShearX(CGAffineTransform transform) {return transform.B;};
Static inline CGFloat CGAffineTransformGetShearY(CGAffineTransform transform) {return transform.C;};
Static inline CGFloat CGPointAngleBetweenPoints(CGPoint chief, CGPoint second)
{
CGFloat dy = support.Y - chief.Y;
CGFloat dx = support.X - chief.X;
Return atan2f(dy, dx);
}
Static inline CGFloat CGAffineTransformGetRotation(CGAffineTransform transform)
{
// No exact way to comprehend rotation improbable exclusive of knowing order of all preceding operations
// So, we'll cheat. We'll apply the transformation to two points and followed by determine the
// outlook betwen persons two points
CGPoint testPoint1 = CGPointMake(-100.F, 0.F);
CGPoint testPoint2 = CGPointMake(100.F, 0.F);
CGPoint transformed1 = CGPointApplyAffineTransform(testPoint1, transform);
CGPoint transformed2 = CGPointApplyAffineTransform(testPoint2, transform);
Return CGPointAngleBetweenPoints(transformed1, transformed2);
}
#ifdef __cplusplus
}
#endif
#endif
No comments:
Post a Comment