# Tools to create some example blocks. # Last edited on 2021-03-21 11:55:48 by jstolfi import block_example_IMP def single_raster(xlo, xhi, y, mp_trace): # Returns a block that is a single raster line with endpoints # {(xlo,y)} and {(xhy, y)} and parameters {mp_trace}, with two choices # -- the two orientations. return block_example_IMP.single_raster(xlo, xhi, y, mp_trace) def raster_rectangle(plo, nx, ny, hor, ver, alt, mp_trace, mp_jump): # Returns a block whose choices (4 or 8) are paths of # raster traces filling a rectangle, connected by link traces or jumps. # # All moves in the block will share the {Move_Parms} records # {mp_trace} or {mp_jump}, as appropriate. The spacing of the rasters # will be the trace width {wd} implied by {mp_trace}. The ENDPOINTS of # the rasters will span a rectangle of width {(nx-1)*wd} and height # {(ny-1)*wd}, with lower left corner {plo}. # # If the bool {hor} is true, the choices of the block will include two # paths that share the same {ny} horizontal rasters of length # {(nx-1)*wd}. If {ver} is true, the choices will include two paths # that share the same {nx} vertical rasters of length {(ny-1)*wd}. In # either casse, the paths differ on the orientation of the first # raster, and therefore on the set of connectors used. # # If the bool {alt} is false, the rasters will have the same # orientation and will be connected by jumps. If {alt} is true, they # will have alternating orientations and will be connected by link # traces. # # In any case, the reversal of each path {ph} above will also be # included in the block, right after {ph}. Thus, if only one of {hor} # and {ver} is true, the block will have four choices; if both are # true, it will have eight choices. At least one of them must be true. # # Note that the nominal sausages and decorations (arrows, dots, etc.) # will overflow that rectangle by {wd/2} or more in every direction. # The counts {nx} and {ny} must be at least 2. return block_example_IMP.raster_rectangle(plo, nx, ny, hor, ver, alt, mp_trace, mp_jump) def spiral_rectangle(plo, szx, szy, mp_trace): # Returns a block with 4 choices, which are spral paths filling # the rectangle with corners {plo} and {plo + (szx,szy)}, # as in {path_example.spiral_rectangle}. All choices will turn # counterclockwise, starting at the four corners of the rectangle # and ending somewhere in the middle. return block_example_IMP.spiral_rectangle(plo, szx, szy, mp_trace) def onion(nch, ctr, Rc, mp_cont, Rf, mp_fill, mp_jump): # Returns a block that has {nch} choices, each being a path created by # {path_example.onion} with those parameters, but with {nch} values of {phase} # equally spaced on the circle. return block_example_IMP.onion(nch, ctr, Rc, mp_cont, Rf, mp_fill, mp_jump) # SAMPLE BLOCKS FOR THE UNIT TEST PROGRAM def misc_A(mp_trace, mp_jump): # Returns a list {BCS} of three blocks whose choices are created by {path_example.misc_E}. # Also returns a list {OPHS} of the paths and lists {TRS} and {JMS} # of the traces and moves. # # The blocks and their choices are: # # block n choices # ------ - ---------- # BCS[0] 4 OPHS[0], ~OPHS[0], OPHS[1], ~OPHS[1] # BCS[1] 2 OPHS[3], OPHS[4] # BCS[2] 1 OPHS[2] # # where {n} is the number of choices, and {~ph} means {path.rev(ph)}. # # Those paths have a total of ten traces and five internal jumps. # Note that choices 0 and 1 of block {BCS[0]} share the same moves, and # ditto for choices 2 and 3. return block_example_IMP.misc_A(mp_trace, mp_jump) def misc_B(mp_trace, mp_jump): # Returns a list {BCS} of three blocks whose choices are created by {path_example.misc_E}. # Also returns the list {OPHS} of the paths and the lists {TRS} and {JMS} # of their traces and moves. # # This example is similar to {misc_A} but the paths are joined into blocks in different ways. # # The blocks and their choices are: # # block n choices # ------ - ---------- # BCS[0] 5 OPHS[0], ~OPHS[0], OPHS[4], ~OPHS[4], OPHS[2] # BCS[1] 2 OPHS[1], ~OPHS[1] # BCS[2] 1 OPHS[3] # # where {n} is the number of choices, and {~ph} means {path.rev(ph)}. return block_example_IMP.misc_B(mp_trace, mp_jump) def misc_C(mp_trace): # Returns a list {BCS} of seven blocks, each a serpentine raster fill of a rectangle. # Five are arranged in a horizontal row, and the other two are # above and below the seecond of these five blocks. return block_example_IMP.misc_C(mp_trace) def misc_D(mp_trace): # Returns a list {BCS} of four blocks, each a serpentine raster fill # of a rectangle. There are two wide blocks at top and bottom, and two # narrower "roads", side by side, between the two. The bottom block # and the roads have four choices, all with horizontal traces, while # the top block has eight choices, half with horizontal traces and # half with vertical traces. return block_example_IMP.misc_D(mp_trace) def misc_E(mp_trace, mp_jump): # Returns a list {BCS} of two blocks, each a raster fill of a # rectangle, side by side, each with four choices. The left one has # horizontal rasters, in alternating directions, connected by link # traces, while the right one has vertical rasters, in the same # direction, connected by jumps. return block_example_IMP.misc_E(mp_trace, mp_jump)