Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: a couple of CGContext questions



On Jan 31, 2007, at 03:18 AM, Mike Kluev wrote:

I would not recommend that approach, as the math is non-trivial, and
you can get subtle floating point errors (due to rounding).

Curious, would the errors be observable on the screen or paper.

What errors you see will depend entirely on how sensitive what you are rendering is to rounding errors. Any errors in accuracy in the CTM gets propagated to every calculation in CG, which can lead to unexpected results. How likely you are to notice these errors is dependent on the context of usage and how large the error is. But the nature of floating point math on a computer means that small errors can be come large errors if you aren't careful with your order of operations.


In principle, performing an inverse of a 3x3 matrix (which is what a CG CTM basically is, we just don't store some fields since they are constant) requires performing a lot (about a dozen) matrix determinants (which leads to lots of multiplications, additions and subtractions). In practice, there are better methods that you can use, but the more intelligent/faster the method, the more code you have to write, maintain and test. Mathworld has a pretty good write up at <http://mathworld.wolfram.com/MatrixInverse.html>

At some point, it really isn't worth it, and outside of specific situations you aren't going to get the same results as popping the GState stack, and you certainly aren't going to get the result any faster.

Your far
better off doing a CGContextSaveGState() when you first get the
context, and if you ever need to go back to the initial CTM, popping
state until you reach the default state again (then saving state
again to preserve that).

But that will reset the whole context to the saved state. What if the OP needs to reset only the CTM, while leaving other context parameters intact?

Honestly, you'll just have to set them up again. In almost all cases this will be cheaper than inverting the CTM to, and you can always try to rearrange your drawing order to avoid having to setup a lot of state each time.
--
Reality is what, when you stop believing in it, doesn't go away.
Failure is not an option. It is a privilege reserved for those who try.


David Duncan

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: a couple of CGContext questions (From: Mike Kluev <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.