[Drawkit] DKDrawableObject angle
Graham Cox
graham.cox at bigpond.com
Wed Apr 22 22:45:32 PDT 2009
On 23/04/2009, at 11:16 AM, Michael Caron wrote:
> What is the meaning of the angle property of a DKDrawableObject? I
> see it being used when computing the bounds of the object. The
> inline comments say that it's the angle of the object with respect
> to the container. Is the container the same as the View? Does this
> property show if the object has been rotated or not? As in, if the
> object is not rotated, it's got an angle of 0 rad. But if it's
> rotated, then it's non-zero?
The container of an object is the object that contains it. Containers
include layers and groups.
The angle is the angle relative to its container. Layers can't be
rotated, so this is equivalent to the absolute angle relative to the
view. But groups can be rotated, so the angle is the angle within the
group. The absolute angle will be the group angle + the object angle
(though as groups can be nested you'd have to sum up all possible
container angles to arrive at an absolute value, if you ever needed it).
All drawable objects have an angle property, but many of them just
return 0. Mostly it's shapes and their derivatives that allow this to
readily vary. The property allows you to tell if the object has been
rotated relative to its container, but doesn't tell you if it is
aligned in the view (for example, an object could be in a group such
that the group's rotation and the object's rotation cancel out,
showing the object aligned exactly to the view, but the angle property
would be non-zero).
The reason that the angle affects the bounds is because the bounds is
always container-aligned. Thus a rotated rectangle's bounds will have
a width and height that is different from the size reported by the -
size property, which is the true size of the object, regardless of
rotation (i.e. a side length x is always x even when rotated).
> Maybe I'm missing something really basic here, but DKArcPath states
> in the inline comments for the angle method that:
>
> the overall angle is considered to be halfway between the start and
> end points around the arc
>
> I don't follow this, unless you're simply stating that this is so.
> Consider an arc with starting angle of 0 and ending angle of pi/2 .
> I would assume that the angle of the arc is pi/2, not pi/4. Or does
> this have something to do with the question that I asked earlier
> about the angle being something to do with rotation?
>
Because all drawables define an angle property, for an arc the angle
is defined to be halfway between the arc ends. You can see this when
rotating an arc - you get a highlight line at the halfway mark. I
forget precisely why I chose to do it that way now, but I recall that
it did simplify a bunch of stuff.
--Graham
More information about the Drawkit
mailing list