15
$\begingroup$

Bug introduced in 8.0.4 or earlier and persisting through 11.0.1 or later


I have noticed cases where Line produces dots in a graphics object when I think it shouldn't. The first of these is:

Line[{{0., 0.}}]

The second is:

Line[{{0., 0.}, {0., 0.}}]

Longer lists of same point do not produce dots. To see this evaluate

repeatPts [pt_, n_] := Line[ConstantArray[pt, n]]
Graphics[{Thickness[.125], repeatPts[{0., 0.}, #], repeatPts[{1., 1.}, #]},
  ImageSize -> 50, Frame -> True, FrameTicks -> None, PlotRangePadding -> .3] & /@ Range[5]

Dots.png

Is this version or platform depended? I got the results shown above on with V9.0.1 running on OS X. Should it be considered a bug or a weird feature?

$\endgroup$
  • 1
    $\begingroup$ 9.0.1, Linux: another behavior $\endgroup$ – ybeltukov Dec 7 '13 at 23:50
  • $\begingroup$ 8.0.4 Linux, same as above. (Including square-looking dots in the last three) $\endgroup$ – ssch Dec 7 '13 at 23:51
  • 1
    $\begingroup$ 9.0.1 OS X, slightly different: dropbox.com/s/42kwqfdu3cv4vh5/… $\endgroup$ – Szabolcs Dec 8 '13 at 0:14
  • 1
    $\begingroup$ With Line[..., VertexColors -> {Red, Blue}] the result is quite surprising. $\endgroup$ – ybeltukov Dec 8 '13 at 0:15
  • 1
    $\begingroup$ If it helps, Exporting to eps we see in the anomolous cases it is actually drawing a little circle (8 bezier arcs in fact -- some 12 lines of code to make a dot!). A default Point[] on the other hand is rendered as a zero length line with a round endcap. $\endgroup$ – george2079 Dec 9 '13 at 15:02
3
$\begingroup$

Inspired by george2079's answer:

line[arg__] := Line[arg];
line[{x_ ..}, ___] := {};
$\endgroup$
  • $\begingroup$ Way faster than mine if you have lots of points. $\endgroup$ – george2079 Dec 9 '13 at 18:38
8
$\begingroup$

Possible workaround (tested on V9.0.1, Linux): just add VertexColors -> {Black} option.

Without this option I get

repeatPts[pt_, n_] := Line[ConstantArray[pt, n]]
   Graphics[{Thickness[.125], CapForm[cap], repeatPts[{0., 0.}, #], 
    repeatPts[{1., 1.}, #]}, ImageSize -> 50, Frame -> True, 
     FrameTicks -> None, PlotRangePadding -> .3] & /@ 
   Range[5] /. {{cap -> "Round"}, {cap -> "Square"}, {cap -> "Butt"}} // Grid

enter image description here

This behavior is completely unexpected: why 3 or more points differs from 1 and 2? Why in the first row the size of the points is quite different? Why we see something in the third row? (CapForm["Butt"] is the absence of the cap).

With VertexColors -> {Black} the result is much better:

repeatPts[pt_, n_] := Line[ConstantArray[pt, n], VertexColors -> {Black}]
   Graphics[{Thickness[.125], CapForm[cap], repeatPts[{0., 0.}, #], 
    repeatPts[{1., 1.}, #]}, ImageSize -> 50, Frame -> True, 
     FrameTicks -> None, PlotRangePadding -> .3] & /@ 
   Range[5] /. {{cap -> "Round"}, {cap -> "Square"}, {cap -> "Butt"}} // Grid

enter image description here

Now everything is clean: there is no line with 1 point (the first column). In the other cases this point is the cap of the line with zero length.

$\endgroup$
  • $\begingroup$ Unfortunately, in the real code that inspired this question, I need to use CapForm["Round"]. $\endgroup$ – m_goldberg Dec 8 '13 at 1:48
  • $\begingroup$ @m_goldberg In my opinion everything is fine with CapForm["Round"]. It produces a small dot, which is about line thickness (as well as with very close points). Could you give a minimal example of your problem? $\endgroup$ – ybeltukov Dec 8 '13 at 1:57
  • $\begingroup$ The example I gave in the question is as concise as I can make it. The result I want is no dots in any of the cases where the same point is repeated. $\endgroup$ – m_goldberg Dec 8 '13 at 3:04
4
$\begingroup$

I brought this to the attention of the WRI tech support. This was their reply:

I am writing to let you know that I have reported this bad behavior to our development team. I would also like to point out (if you were not aware) that the behavior you observed is even different between operating systems (for example, in Linux the points always appear, but when more than three points are present the "point" is a square).

I conclude from this that WRI will investigate this problem as a bug, and perhaps fix it in a future release.

$\endgroup$
2
$\begingroup$

A bit of an obvoius hack but it does the job.

repeatPts[pt_,n_] := (If[ Length@Tally[#] == 1 , {}  , Line[#]] &@ ConstantArray[pt, n])
Graphics[{Thickness[.125], repeatPts[{0., 0.}, #], 
     repeatPts[{1., 1.}, #]}, ImageSize -> 50, Frame -> True, 
     FrameTicks -> None, PlotRangePadding -> .3] & /@ Range[5]

.. a bit faster :

 If[ Equal @@ # , {} , Line[#]] &@
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.