Slashdot Mirror


Aqua Enhancements

Marsee writes: "Mike Beam looks at two Aqua enhancements -- one seemingly frivolous and the other not: animated window resizing and drawers." O'Reilly's really invested in Mac OS X, and they often have nice articles for developers on a wide range of subjects in their Mac DevCenter.

2 of 15 comments (clear)

  1. Resolution Independance by Matthias+Wiesmann · · Score: 5, Insightful

    Actually, using floating points is a very good thing for GUI stuff. While it might seem pointless for window sizes, all coordinates in Quartz are floating point. This makes it posible to work in a resolution independant way.

    Thinking of the screen as a discret grid is not the way to go if you want to handle anti-aliasing, sub-pixel text positioning, scaling for a screen with a different size/resolution, etc...

    Remember that Quartz is used for handling on screen drawing, but also printing -- current printers can have 24 times more resolution than your screen (2400 DPI vs 100)- so if you use the discrete grid of your screen to describe stuff for your printer, you can only adress directly one pixel out of 576.

  2. Fixed point by Matthias+Wiesmann · · Score: 4, Informative
    Actually, floating point is quite fast on a PPC. As people already pointed out, for matrix-like computation, PPC has a special instruction that does one multiplication and one addition in one cycle. If this is to slow, on a G4 you can use altivec.

    If you really want not to use floating point calculation, then rational numbers are not the way to go. Instead you should use fixed point numbers. Old 68K based macintoshes (without FPUs) relied on those for fast calculation - in fact as far as I remember, the original Quickdraw toolbox relied of fixed point number for geometric calculations (arcs, slopes, etc.).

    Basically, the idea is to use integers divided by a fixed number, so that the binary number has a fixed point. For instance if you have 32 bits numbers, you assume they are divided by 65536. This means that you have 16 bits before the point, and 16 bits after. This way for additions and substractions, you can use integer operations, calculation can also use the zero and sign flags of the processor. For mulitplication and division, you need to fiddle the integer system a bit (by multiplying or dividing by 2^16), but this could be done using shift operations, which are quite fast.

    The rational structure you propose is not good because a simple addition requires many assembly level operations. For instance to calculate 6/5 + 2/3, you need to do the following calculation:

    1. Find the greatest common dividers of 5 and 3 (this is quite an expensive calculation)
    2. If none is found, multiply 3 by 5.
    3. Multiply 6 by 3 and 2 by 5.
    4. Add the result
    So this basically for a single addition, you need to do perform at least a GCD calculation, one test, three multiplications and one addition. Multiplications and division are a little less costly, but you still need to check if the fraction is simplified.
    Rational numbers are good if you want absolute precision, but for they are not very fast - because there is no support for such a format in current processor instruction sets.

    As for OS X using a vector format, this is, of course the case. Quarty relies on the PDF abstractions and it does support anti-aliasing, and sub-pixel positioning (I don't know for screen scaling). But having a vector format is not sufficient Quickdraw was also vector based, but used an integer coordinate system. This meant that lines, rectangles and arcs had to have their extremities on round coordinates of the Quickdraw grid - the result was not always very satisfactory.