[Drawkit] Bounding box derivation errors?

Michael Caron michael.r.caron at gmail.com
Sat Apr 18 09:08:08 PDT 2009


Hi Graham!

So I've spent some time really digging into all this transform stuff  
and I think there's a bug in calculating bounds for DKDrawable*  
objects, at least DKArcPath because that's what I'm using for my  
experiments. I placed an NSLog statement in the bounds method for  
DKArcPath so that it will output the coords of the bounds rectangle  
obtained strictly from the member path before any massaging  
(represented by the "DKArc: Path Bounds" lines below in "EXPERIMENT  
OUTPUT"). I then output what the bounding box is after taking the  
union of all drawable objects on the current layer (represented by  
"DRAW: Bounding Box" lines below in "EXPERIMENT OUTPUT").

To create the experiment, I placed a single arc on a  
DKObjectDrawingLayer (which is active for drawing) in a DKDrawing  
which also contains a guide layer and a grid layer. I created the arc  
by instantiating a DKArcPath with a certain location obtained by using  
the pointForGridLocation method of the grid and radius by using the  
quartzDistanceForGridDistance method of the grid. Then I set the  
starting and ending angles. After creating the arc, I added it to the  
current layer.

Next, I called the unionOfAllObjectBounds method on the current layer  
and logged it (see output below). During that call, the path bounds of  
the arc's path member were also logged. I then used the  
applyTransformToObjects on the currentLayer using a scaleby transform.  
Again, logged both the union of all the object bounds as well as the  
arc's path bounds.

As you can see from the output, after the transform the raw path of  
the arc behaves as expected, scaling everything by the scale factor  
(1000). The width and height of the bounding box are appropriately  
larger. However, the union bounding box's width and height do not  
change by the appropriate scale factor. I've also noticed that the  
mRadius member of DKArcPath does not change after the transform is  
applied, but the mCentre member does (it's an explicit transform of  
the point).

So it seems that either the union of the bounds is being calculated  
incorrectly or the bounds on the DKArcPath are being calculated  
incorrectly.

I'm going to look further into this and see if I can solve the  
bounding problem.

EXPERIMENT OUTPUT
-------------------------------------------------------------------------------------------------
BEFORE TNSFM:
-------------
DKArc: Path Bounds:                  (25.099012,   25.047211),     
(25.101004,   25.049202)
              Width:                   0.001992
             Height:                   0.001991
DRAW:  Bounding Box B4 Transform:    (16.029093,   15.976345),     
(34.170921,   34.120068)
                            Width:     18.141828
                           Height:     18.143723

AFTER TNSFM:
-------------
DKArc: Path Bounds:                  (25099.009766,25047.210938),  
(25101.005859,25049.205078)
              Width:                   1.996093
             Height:                   1.99414
DRAW:  Bounding Box After Transform: (25090.937500,25039.134766),  
(25109.080078,25057.281250)
                            Width:     18.142578
                           Height:     18.146484



Best regards,
Michael Caron
------------------------------------------------
michael.r.caron at gmail.com
http://techrad.wordpress.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.apptree.net/pipermail/drawkit-apptree.net/attachments/20090418/393dcf34/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
URL: <http://lists.apptree.net/pipermail/drawkit-apptree.net/attachments/20090418/393dcf34/attachment.pgp>


More information about the Drawkit mailing list