One of the tricks (there are other approaches) is to make one row [segment] at a time, one plane [square] at a time . Turning to the last part of the question, this approach works even if the size of the visited volume is not the same in each dimension (for example: a block of size 100 x 6 x 33).
In other words:
Start at (0,0,0),
move only on the Z axis till the end of the segment, i.e.
(0,0,1), (0,0,2), (0,0,3), ... (0,0,100),
Then move to the next line, i.e.
(0,1,100)
and come backward on the line, i.e.
(0,1,99), (0,1,98), (0,1,97), ... (0,1,0),
Next to the next line, going "forward"
And repeat till the whole "panel is painted", i.e ending at
... (0,100,99), (0,100,100),
Then move, finally, by 1, on the X axis, i.e.
(1,100,100)
and repeat on the other panel,but on this panel going "upward"
etc.
, , . , "" 101 x 101 x 101, (.. ).
! , , - "back-and-forth", , , ).
: ( , ):
! , , [] , , .
, , .. , ( ), "" , "" " ..
(0,0,0) (0,0,1)
(0,1,0) first diagonal, only 1 in lengh.
(0,2,0) "turn around"
(0,1,1) (0,0,2) second diagonal: 2 in length
(0,0,3) "turn around"
(0,1,2) (0,2,1) (0,3,0) third diagonal: 3 in length
(0,4,0) turn around
etc.
, , "", , , , , , , , , "" , .
(, , ) "" . , ( ) , , "" 2.