[Drawkit] Handling full circles with DKArcPath

Brad Larson larson at sonoplot.com
Wed Oct 1 12:20:44 PDT 2008


Sorry I've been a little quiet lately, I've been working on another  
couple of projects.

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 );
}

you can achieve this.  One side-effect is that the first stage in  
drawing an arc (specifying the radius) will now show a full circle  
instead of just the radius line and a couple of control points.  This  
might also be preferred behavior, as it will show the range over which  
an arc can be drawn at that radius.

Also, to make sure that the radius width control point does not  
overlap the starting and ending angle control points, I needed to  
alter the angle method in DKArcPath from

- (float)			angle
{
	if([self arcType] == kDKArcPathCircle )
		return 0.0;
	else
	{
		float angle = ( mStartAngle + mEndAngle ) * 0.5f;
		if ( mEndAngle < mStartAngle )
			angle += pi;
			
		return angle;
	}
}

to

- (float)			angle
{
	if([self arcType] == kDKArcPathCircle )
		return 0.0;
	else
	{			
		float angle = ( mStartAngle + mEndAngle ) * 0.5f;
		if (fabs(mEndAngle - mStartAngle) < 0.001)
			angle -= pi;
		if ( mEndAngle < mStartAngle )
			angle += pi;
			
		return angle;
	}
}

If you can see any problems with this approach, or have a better way  
of achieving the same result, please let me know.


______________________
Brad Larson
SonoPlot, Inc.
3030 Laura Lane, Suite 120
Middleton, WI 53562





More information about the Drawkit mailing list