Most of those should be obvious implementations. The surprise, if any, comes
from the fact that pen_down() puts a point on the track. This makes sense
though, if you think about it. If you touch a pen to a piece of paper you have
made a mark, even though you have not yet drawn a line. The Turtle should
function the same way.
Well, using this way, it may create “invalid” segment.
By definition:
track ::= [segment, segment, …] # drawing data
segment ::= [point, point, …] # points to be joined by line
segments
point ::= [x, y] # pair of floats
I was thinking a “no-empty” segment must have at least 2 points.
If we allow pen_down to make a mark, it may create invalid segment.
This test code shows:
home
pd # mark [0,0]
pu
fd 100
pd
right 90
fd 100
pu
p track # ==> [[[0.0, 0.0]], [[0.0, 100.0], [100.0, 100.0]]]
so [[0.0, 0.0]] is not a valid segment, it is just a “mark”.
And the Tk-viewer even not show it as a “point”.
( for drawing the point [0,0], it maybe a segment like [[0,0],[0,0]] ? )
Anyway, in case you write your own viewer,
if we accept “mark”, you need to test the invalid segment.