[Drawkit] Handling full circles with DKArcPath
Alastair Houghton
alastair at alastairs-place.net
Thu Oct 16 03:09:42 PDT 2008
On 1 Oct 2008, at 20:20, Brad Larson wrote:
> In working on our draw program, our users were requesting the
> ability to draw full circles with the arc tool, as well as the arc
> segments. Right now, if you try to do this, the arc will disappear
> as soon as the starting and ending angles are the same. A better
> behavior would be for a full circle to be formed in that case. By
> altering the endAngle method on DKArcPath from
>
> - (float) endAngle
> {
> return RADIANS_TO_DEGREES( mEndAngle );
> }
>
> to
>
> - (float) endAngle
> {
> if (fabs(mEndAngle - mStartAngle) < 0.001)
> return RADIANS_TO_DEGREES( mStartAngle ) + 360.0;
> else
> return RADIANS_TO_DEGREES( mEndAngle );
> }
[snip]
> If you can see any problems with this approach, or have a better way
> of achieving the same result, please let me know.
A better approach to solving this problem would be to alter the code
that handles interaction with the user so that it keeps track of what
they're actually doing with the end angle. That way you can make
arbitrarily small arcs *and* full circles without having problems
where one turns into the other unexpectedly.
The code that iPartition uses for its pie chart does something very
much like this to avoid exactly this type of problem. That is, if you
move your mouse repeatedly around the chart in an anticlockwise
direction, it will cause the segment you're resizing to grow to
maximum size and then stay there, whereas if you move it repeatedly in
a clockwise direction, it will cause the segment to shrink to minimum
size. There is no situation where you can move clockwise and end up
with maximum size, or move anticlockwise and end up with minimum size.
I don't have time to contribute an implementation (and I'm not working
on drawing-related code right now anyway), but it isn't hugely tricky
to get this kind of thing working, and it's *much* nicer to use than
any system that causes the thing to jump from one end to the other.
Kind regards,
Alastair.
--
http://alastairs-place.net
More information about the Drawkit
mailing list