• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSAffineTransforms not working as expected?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSAffineTransforms not working as expected?


  • Subject: Re: NSAffineTransforms not working as expected?
  • From: Scott Thompson <email@hidden>
  • Date: Fri, 25 Feb 2005 21:49:29 -0600


On Feb 25, 2005, at 8:27 PM, Sean McBride wrote:

Mike R. Manzano (email@hidden) on 2005-02-25 20:09 said:


Can anyone tell me why this causes a segfault in my program?


        NSAffineTransform* toTimeSpace =

            [ NSAffineTransform transform ] ;

        [ toTimeSpace concat ] ;

        [ [ NSColor blackColor ] set ] ;

        [ [ NSString stringWithString:@"aTime" ]

                drawAtPoint:NSMakePoint(

                    cellFrame.origin.x ,

                    cellFrame.origin.y    )

                withAttributes:attrs                ] ;

        [ [ toTimeSpace invert ] concat ] ;


This works fine if I remove the last line.  This code is being executed 

in an NSCell's


Probably because invert returns void.  Is there no compiler warning?  Try:


[toTimeSpace invert];

[toTimeSpace concat];


You shouldn't try inverting a matrix like this as the means of undoing a transformation.  Instead, you should save and restore the graphics state around your code:


        NSAffineTransform* toTimeSpace =

            [ NSAffineTransform transform ] ;

        [NSGraphicsContext saveGraphicsState];

        [ toTimeSpace concat ] ;

        [ [ NSColor blackColor ] set ] ;

        [ [ NSString stringWithString:@"aTime" ]

                drawAtPoint:NSMakePoint(

                    cellFrame.origin.x ,

                    cellFrame.origin.y    )

                withAttributes:attrs                ] ;

        [ NSGraphicsContext restoreGraphicsState];


The reason this is important is because the invert/concat operation can introduce roundoff errors and you might not get back exactly to the same place that you started in terms of your CTM.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSAffineTransforms not working as expected?
      • From: "Mike R. Manzano" <email@hidden>
References: 
 >NSAffineTransforms not working as expected? (From: "Mike R. Manzano" <email@hidden>)
 >Re: NSAffineTransforms not working as expected? (From: "Sean McBride" <email@hidden>)

  • Prev by Date: Re: NSAffineTransforms not working as expected?
  • Next by Date: Re: Binding name must be same as ivar name?
  • Previous by thread: Re: NSAffineTransforms not working as expected?
  • Next by thread: Re: NSAffineTransforms not working as expected?
  • Index(es):
    • Date
    • Thread