Arc bug in pic preprocessor

Kaare Christian kc at rna.UUCP
Tue Mar 4 03:26:12 AEST 1986


I have recently encountered a pair of obscure pic bugs. I didn't see any
reference to this in browsing through our bug report archives. If
this has already been reported please excuse my duplication.

Description 1: Pic has trouble drawing a semi-circle. If two
endpoints and a corresponding radius are specified, pic doubles
the radius in a needless attempt to avoid impossibly small radii.
	.PS
	arc radius 1i from 0,0 to 2,0
	.PE
The input given above will produce an arc with radius 2i, instead
of the requested 1i radius.

Description 2: Pic enters an infinite loop if an arc is specified
with radius zero.  Yes, I know that you shouldn't specify an arc with
radius zero, but lets pity the poor soul who does.
	.PS
	arc radius 0
	.PE

Repeat by trying the two examples on your copy of pic.  Don't do
them together, the infinite loop will hide the arc problem.

In the original code, an impossibly small radius was incorrectly
detected (the op was <=, should be <) and the remedy was to repeatedly
double the radius until a large enough value was attained. (Hence the
looping problem.) My fix correctly detects too small radii, and
substitutes the minimial radius when the given radius is too small.
This seems better.

Fix: Here are the diffs to `arcgen.c' in the pic distribution.

95,96c95,100
< 		for (r=prevrad; (d = r*r - (dx2*dx2+dy2*dy2)) <= 0.0; r *= 2)
< 			;	/* this kludge gets around too-small radii */
---
> 		r=prevrad;
> 		if ((d = r*r - (dx2*dx2+dy2*dy2)) < 0.0) {
> 			/* this kludge gets around too-small radii */
> 			r = sqrt(dx2*dx2+dy2*dy2);/* smallest possible radius */
> 			d = 0;
> 		}

Fun: Try this pic-ture.
	.PS
	C: circle radius .5i
	arc from C.c + (-.25,0) to C.c + (.25,0) radius .25i
	circle radius .05i at C.c + (-.2,.2)
	circle radius .05i at C.c + (.2,.2)
	.PE

Kaare Christian
cmcl2!rna!kc or dial direct 212-759-3929

What would the sticky bit have been called if ibm had invented Unix?



More information about the Net.bugs mailing list