# /usr/bin/python3 # Test program for module {raster_example} # Last edited on 2021-09-22 23:52:35 by stolfi import raster_example import move import move_parms import path import path_hp import contact import contact_hp 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_js() 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 show_and_plot(tag, OPHS, deco): # Plots the oriented paths in the list {OPHS} 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 sys.stderr.write(" ... {show_and_plot} paths ...\n") path.show_list(sys.stderr, OPHS, True, 2) for oph in OPHS: path.validate(oph) dp = None nph = len(OPHS) CLRS = hacks.trace_colors(nph) # Plot the paths: rwd = 0.80 wd_axes = 0.15*min(wd_fill,wd_cont) # Width of jumps and axis lines. grid = True fname = "tests/out/raster_example_TST_" + tag path.plot_to_files(fname, OPHS, CLRS, rwd, wd_axes, grid, deco) return # ---------------------------------------------------------------------- def test_patch_array(cols, rows, nx, ny, islands): sys.stderr.write("--- testing {patch_array} ---\n") sys.stderr.write("cols = %s\n" % cols) sys.stderr.write("rows = %s\n" % rows) sys.stderr.write("nx = %s\n" % nx) sys.stderr.write("ny = %s\n" % ny) sys.stderr.write("islands = %s\n" % islands) split = True max_lines = 5 tag = \ "patch_array" + \ ("_c%02d" % cols) + \ ("_r%02d" % rows) + \ ("_nx%02d" % nx) + \ ("_ny%02d" % nx) + \ ("_is%s" % "FT"[islands]) mp_link = mp_fill OCRS, OPHS, CTS = raster_example.patch_array(cols, rows, nx,ny, islands, mp_cont, mp_fill, mp_link) sys.stderr.write(" ... contours ...\n") ncr = len(OCRS) path.show_list(sys.stderr, OCRS, True, 2) sys.stderr.write(" ... raster fill elements ...\n") nph = len(OPHS) path.show_list(sys.stderr, OPHS, True, 2) sys.stderr.write(" ... contacts ...\n") nct = len(CTS) contact.show_list(sys.stderr, CTS, 2) # ??? Should validate output -- contours, links, contacts, etc. ??? rwd = 0.80 wd_axes = 0.05*wd_fill tics = False arrows = False clt_ct = pyx.color.rgb(1.000, 0.050, 0.000) # Contact color. clr_cr = pyx.color.rgb(0.200, 1.000, 1.000) # Contour color. CLRS = [clr_cr,]*ncr + hacks.trace_colors(nph) fname = "tests/out/raster_example_TST_" + tag contact.plot_to_files(fname, CTS, clt_ct, OCRS + OPHS, CLRS, rwd, wd_axes, tics, arrows) return # ---------------------------------------------------------------------- def test_rasters_A(): sys.stderr.write("--- testing {rasters_A} ---\n") tag = ("rasters_A") xdir = ( cos(pi/6), sin(pi/6) ) ydir = ( -xdir[1], +xdir[0] ) yphase = 0.45 eps = 0.15*wd_fill # Magnitude of perturbations. OPHS = raster_example.rasters_A(mp_fill, xdir, ydir, yphase, eps) sys.stderr.write(" ... raster fill elements ...\n") path.show_list(sys.stderr, OPHS, True, 2) sys.stderr.write(" ... moves ...\n") OMVS = [ path.elem(oph, 0) for oph in OPHS ] move.show_list(sys.stderr, OMVS, 2) deco = True show_and_plot(tag, OPHS, deco) # ---------------------------------------------------------------------- test_rasters_A() nx = 3 ny = 20 test_patch_array( 5, 2, nx, ny, True) test_patch_array( 7, 1, nx, ny, False) test_patch_array(10, 1, nx, ny, False) test_patch_array(13, 1, nx, ny, False)