> Date: Thu, 24 Jan 2013 12:01:28 +1100
> From: Graham Cox <graham....@bigpond.com>
> To: "cocoa-dev@lists.apple.com Dev" <cocoa-dev@lists.apple.com>
> Subject: Re: Coordinate conversions in CALayer

> Boiling down my problem to its bare essentials, why are these two bits of 
> code not equivalent?
> 
> 
>       
>       CGContextTranslateCTM( ctx, pos.x, pos.y );
>       CGContextConcatCTM( ctx, layer.transform );
>       CGContextTranslateCTM(ctx, -(br.origin.x + anch.x * br.size.width), 
> -(br.origin.y + anch.y * br.size.height));
> 
> The above works correctly, but below, which I thought should do the same, 
> does not, if the layer.transform property is not the identity matrix:
> 
> 
>       
>       CGAffineTransform tfm = CGAffineTransformMakeTranslation( pos.x, pos.y 
> );
>       tfm = CGAffineTransformConcat( tfm, layer.transform );
>       tfm = CGAffineTransformTranslate( tfm, -(br.origin.x + anch.x * 
> br.size.width), -(br.origin.y + anch.y * br.size.height));
>       
>       CGContextConcatCTM( ctx, tfm );

They are not equivalent because the first one starts with CGContextTranslateCTM 
but the second one starts with CGAffineTransformMakeTranslation. In other 
words, the first one begins by translating the current transform. The second 
one begins with a plain vanilla translation. The affine transform equivalent of 
CGContextTranslateCTM is CGAffineTransformTranslate. You might want to say this:

CGAffineTransform tfm = CGAffineTransformTranslate( layer.transform, pos.x, 
pos.y );

m.

--
matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Programming iOS 5! http://shop.oreilly.com/product/0636920023562.do
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to