Skip Menu |

This queue is for tickets about the PDF-API2 CPAN distribution.

Report information
The Basics
Id: 98541
Status: open
Priority: 0/
Queue: PDF-API2

People
Owner: Nobody in particular
Requestors: philperry [...] hvc.rr.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: bogen() handling edge cases
Date: Tue, 02 Sep 2014 11:19:25 -0400
To: bug-PDF-API2 [...] rt.cpan.org
From: Phil M Perry <philperry [...] hvc.rr.com>
PDF::API2 v2.022 Perl 5.16.3 Windows 7 severity: Wishlist There is at least one error case for Content.pm's bogen() method. If the radius ($r) is less than half the distance between the two points, this is documented as an error condition, but there appears to be nothing in the code to handle it. Normally, $r should be greater than half the distance between the points, so as to produce four arcs. The limiting case of $r exactly equal to half the distance degenerates to a straight line between the points. How exactly should bogen() handle $r that is too small? Should it fail in some manner, or treat it as exactly one half the distance? I have updated the POD to clarify the minimum size for $r, and submitted it to the maintainer, but the code should probably be updated to handle this situation.
Subject: [rt.cpan.org #98541]
Date: Sat, 23 Jan 2016 14:22:32 -0500
To: bug-PDF-API2 [...] rt.cpan.org
From: Phil M Perry <philperry [...] hvc.rr.com>
The code produces odd results for a radius $r that's too small. It takes the arcsine of the ratio of the distance between the points divided by twice the given radius. If $r is too small, this is arcsine of a number greater than 1.0, which isn't defined! So definitely, it needs to be fixed. The minimum $r, which needs to be checked for (and possibly fixed) is one-half the distance between the points, giving a semicircle centered at the midway point between the points. The current code leaves the validation of $r to the user. I think there are two possibilities for this bug. One is that it gives an error message somewhere, possibly disrupting the output, and the second is that it simply silently lengthens the radius $r to one-half the distance between the points, returning a semicircle. Does anyone have a strong opinion one way or the other? How about (in general) error conditions for other calls -- should we silently massage the parameters (where possible) to give minimally acceptable results, and/or give an error message? If an error message is given somewhere (stdout?), should we also "fix up" the call to produce minimally acceptable results (such as the semicircle rather than a funny double arc, in this case)? In this call, a minimum radius places the arc center midway between the two points, and draws a semicircle. As the radius becomes larger than the minimum, it moves off the line between the two points, and the resulting arc approaches a straight line for very large radii. To make an arc longer than the minimum case (i.e., greater than 180 degrees), you need to set one of the arc() flags ($outer) to 1, and flip ($reverse = 1) the arc. Apparently, the resulting arc is normally clockwise from point 1 to point 2, at least given the side of the line the arc center moves to. Note that my original comments said that the minimal case is a straight line between the points -- that is incorrect. It is a semicircle centered on that line.
Subject: [rt.cpan.org #98541]
Date: Sun, 24 Jan 2016 11:53:34 -0500
To: bug-PDF-API2 [...] rt.cpan.org
From: Phil M Perry <philperry [...] hvc.rr.com>
By the way, to add a comment to this thread, just email bug-PDF-API2 [at] rt.cpan.org with subject line [rt.cpan.org #98541]. Note 1 space between org and #, and the [ ] around the whole subject. Nothing else. If you don't follow this format carefully, you will end up creating a new bug report! HTML formatting within the body does not work.
PDF::API2's normal behavior when passed invalid input is undefined. It'll either blow up (often at a later place than where the input was provided) or accept the invalid input and produce an unusable or unexpected file. I'd be happy to review a patch that causes bogen() to die immediately if passed invalid input. That makes more sense to me than trying to guess what the radius should have been.
Subject: [rt.cpan.org #98541]
Date: Thu, 18 Feb 2016 00:11:27 -0500
To: bug-PDF-API2 [...] rt.cpan.org
From: Phil M Perry <philperry [...] hvc.rr.com>
We should certainly move towards clearly defining what PDF::API2 does when given invalid input. I can live with an immediate die(). Would it be acceptable to also provide commented-out code to silently "fix" the invalid input and carry on (in this particular case, increase the radius to the minimum)? That way, the user can easily do it that way if they want to. It could be a run-time switch, but that might complicate/slow the code by an unacceptable amount. It would even be possible to have a "hook" for handling invalid inputs: if an invalid input (here, a too-small radius) is seen, call a function. The default behavior for the function would be simply to die, but a user could choose code to do a fixup and return the corrected radius. That way, all this stuff is isolated in a separate routine (same file). For consistency, we would want to do the same for other invalid inputs.
FYI, this is fixed in PDF::Builder