# /usr/bin/python3 # Test program for module {path_example} # Last edited on 2021-03-21 10:27:21 by jstolfi import path_example import move import move_parms import path import contact import job_parms import hacks import pyx import rn import sys from math import sqrt, sin, cos, floor, ceil, inf, nan, pi parms = job_parms.typical() parms['solid_raster_width'] = 1.00 parms['contour_trace_width'] = 0.50 mp_jump = move_parms.make_for_jumps(parms) mp_cont = move_parms.make_for_contours(parms) mp_fill = move_parms.make_for_fillings(parms) wd_fill = move_parms.width(mp_fill) wd_cont = move_parms.width(mp_cont) def plot(tag, OPHS, deco): # Plots to the {pyx} canvas {c} the oriented paths in the list # {OPHS} and the contacts in the list {CTS}, to files ending with # {tag}. If {deco} is true also prints the matter footprint and draws # axes, dots, and arrowheads on the traces. if OPHS == None: OPHS = [] assert type(OPHS) is tuple or type(OPHS) is list assert len(OPHS) >= 1 B = path.bbox(OPHS) pbox = hacks.round_box(B, 1) dp = None c = pyx.canvas.canvas() pyx.unit.set(uscale=0.5, wscale=0.5, vscale=0.5) wd_frame = 0.10 hacks.plot_frame(c, pyx.color.rgb.white, wd_frame, dp, pbox, 0.25) wd_grid = 0.05 hacks.plot_grid(c, None, wd_grid, dp, pbox, 0.25, 1,1) nph = len(OPHS) CLRS = hacks.trace_colors(nph) # Plot the paths: wd_axes = 0.15*min(wd_fill,wd_cont) # Width of jumps and axis lines. axes = deco dots = deco arrows = True matter = deco path.plot_standard(c, OPHS, dp, None, CLRS, wd_axes, axes, dots, arrows, matter) hacks.write_plot(c, "tests/out/path_example_TST_" + tag) return # ---------------------------------------------------------------------- def test_onion(Rc, Rf, nt): sys.stderr.write("--- testing {onion} Rc = %.3f Rf = %.3f nt = %d ---\n" % (Rc,Rf,nt)) tag = "onion%05.2f_%05.2f_%03d" % (Rc,Rf,nt) Rest = max(Rc,Rc) + wd_fill/2 Rbox = ceil(Rest + wd_fill) + 1 ctr = (Rbox,Rbox) phase = 0.5*pi ph, Rin, Rex = path_example.onion(ctr, Rc, mp_cont, Rf, mp_fill, phase, nt, mp_jump) OPHS = [ph,] deco = True plot(tag, OPHS, deco) return # ---------------------------------------------------------------------- def test_gearloose(): sys.stderr.write("--- testing {gearloose} ---\n") tag = "gearloose" R = 10 zigzag = True ph = path_example.gearloose(R, zigzag, mp_cont, mp_fill, mp_jump) OPHS = [ph,] deco = False plot(tag, OPHS, deco) return # ---------------------------------------------------------------------- def test_raster_rectangle(axis, alt): sys.stderr.write("--- testing {raster_rectangle} axis = %d alt = %s ---\n" % (axis,str(alt))) plo = (1,1) nx = 4; ny = 5 step = wd_fill n = ny if axis == 0 else nx sz = (nx-1)*step if axis == 0 else (ny-1)*step PHS, TRS = path_example.raster_rectangle(plo, axis, n, alt, sz, step, mp_fill,mp_jump) path.describe(sys.stderr, PHS, True) # Must plot each path in a separate file because they overlap: for k in range(len(PHS)): ph = PHS[k] tag = ("raster_rectangle_axis%d_alt%d_ph%d" % (axis,int(alt),k)) deco = True plot(tag, [ph,], deco) return # ---------------------------------------------------------------------- def test_spiral_rectangle(): sys.stderr.write("--- testing {spiral_rectangle} ---\n") tag = "spiral_rectangle" plo = (1,1) # Starting point of first spiral szx = 3.27; szy = 5.31 PHS = [] for axis in range(2): for dr in range(2): sys.stderr.write("--- axis = %d dr = %d ---\n" % (axis,dr)) pini = ( plo[0] + dr*(2*szx + 2) , plo[1] + axis*(2*szy + 2) ) ph = path_example.spiral_rectangle(pini, (1-2*dr)*szx, (1-2*axis)*szy, axis, mp_fill) path.describe(sys.stderr, [ph,], True) PHS.append(ph) deco = True plot(tag, PHS, deco) return # ---------------------------------------------------------------------- def test_misc_A(): sys.stderr.write("--- testing {misc_A} ---\n") oph = path_example.misc_A(mp_fill, mp_jump) path.describe(sys.stderr, [oph,], True) plot("misc_A", (oph,), False) def test_misc_B(): sys.stderr.write("--- testing {misc_B} ---\n") oph = path_example.misc_B(mp_fill, mp_jump) plot("misc_B", (oph,), False) def test_misc_C(): sys.stderr.write("--- testing {misc_C} ---\n") OPHS = path_example.misc_C(mp_fill, mp_jump) path.describe(sys.stderr, [oph,], True) plot("misc_C", OPHS, False) def test_misc_D(): sys.stderr.write("--- testing {misc_D} ---\n") OPHS, TRS, JMS = path_example.misc_D(mp_fill, mp_jump) path.describe(sys.stderr, OPHS, True) plot("misc_D", OPHS, False) def test_misc_E(): sys.stderr.write("--- testing {misc_E} ---\n") OPHS, TRS, JMS = path_example.misc_E(mp_fill, mp_jump) path.describe(sys.stderr, OPHS, True) plot("misc_E", OPHS, False) def test_misc_F(alt): sys.stderr.write("--- testing {misc_F} alt = %s ---\n" % str(alt)) tag = ("misc_F_alt%s" % int(alt)) wd = wd_fill # Width of traces ph, ct = path_example.misc_F(alt, mp_fill, mp_jump) OPHS = [ ph, ] path.describe(sys.stderr, OPHS, True) CTS = [ ct, ] deco = False plot(tag, OPHS, deco) return # ---------------------------------------------------------------------- for axis in 0, 1: for alt in False, True: test_raster_rectangle(axis,alt) test_spiral_rectangle() test_misc_F(False) test_misc_F(True) test_gearloose() test_onion(5,0.3,36) test_onion(5,0.3,35) test_onion(5,7,8)