[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.
Log in to post a comment.