#579 Vertical/horizontal lines sometimes not drawn

closed-accepted
nobody
None
5
2012-02-20
2012-02-17
David Leverton
No

[Note: I initially sent this to the gnuplot-bugs mailing list per the FAQ, before seeing the note at https://lists.sourceforge.net/lists/listinfo/gnuplot-bugs that the tracker is preferred, but it hasn't appeared in the archive yet, so if it's waiting in a moderation queue it can be discarded.]

gnuplot (all tested versions, including current CVS) has a bug where vertical or horizontal lines won't be drawn if one point is on the top or right edge of the graph and the other is off the edge of the graph on the other side (with clip one enabled, of course). Attached is a test case, a fix, and the output of the test case before and after applying the patch for reference (in SVG format primarily because I couldn't be bothered installing the headers needed to build the image output terminals). It passes make check, although I'm not sure if that's comprehensive or if there's some other way to make sure it doesn't break anything.

The problem occurs because the code checks whether the top or right edge of the graph is between (inclusive) the in-range and out-range points, and if it is, assumes that that must be the intersection point, but that's not appropriate in the described situation. The code that handles diagonal lines already takes this into account, it seems that check was just missed for the vertical and horizontal cases.

There is a slight change in behaviour in that edge_intersect would previously always return non-zero for horizontal and vertical lines, but with the patch it returns zero in the same cases as for diagonal ones, namely that one point is on the edge of the graph and the other is off it in such a way that the line doesn't actually cross the graph area. I think this way is cleaner and more consistent.

Discussion

  • David Leverton
    David Leverton
    2012-02-17

    Test case

     
    Attachments
  • David Leverton
    David Leverton
    2012-02-17

    Data for test case

     
    Attachments
  • David Leverton
    David Leverton
    2012-02-17

    I'm afraid I'm not quite sure what the mailman page for the bugs list means by making the data file "inline" (I didn't see anything in the documentation to suggest that the data file can be included in the main input file, but I might have missed something), if that applies to the tracker as well, so I'm attaching it. Hope that's OK.

     
  • David Leverton
    David Leverton
    2012-02-17

    Output of test case

     
    Attachments
  • David Leverton
    David Leverton
    2012-02-17

    Output of test case after applying patch

     
    Attachments
  • David Leverton
    David Leverton
    2012-02-17

    Fix

     
    Attachments
  • Ethan Merritt
    Ethan Merritt
    2012-02-20

    Accepted for CVS.
    Thanks.

     
  • Ethan Merritt
    Ethan Merritt
    2012-02-20

    • status: open --> closed-accepted