#! /bin/usr/python3 # Test program for module {contact_example} # Last edited on 2021-03-16 07:50:05 by jstolfi import contact import contact_example import move import move_example import move_parms import path import path_example import palette import hacks import job_parms import rn import pyx import sys from math import sqrt, sin, cos, floor, ceil, pi, nan, inf 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, CTS, deco, ct_arrows): # Plots to files called "tests/out/path_example_TST_{tag}" the oriented paths in the list # {OPHS} and the contacts in the list {CTS}. If {deco} is true also prints the matter footprint and draws # axes, dots, and arrowheads on the traces. If {ct_arrows} is true, prints arrowheads # on the contacts instead of tics. if OPHS == None: OPHS = [] assert type(OPHS) is tuple or type(OPHS) is list assert len(OPHS) >= 1 if CTS == None: CTS = [] assert type(CTS) is tuple or type(CTS) is list 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) # Plot the contacts: clr_ct = pyx.color.rgb(1.000, 0.000, 0.000) # Color of contacts. wd_ct = 1.5*wd_axes # Width of contact lines. arrow_ct = ct_arrows sz_tic_ct = 0 if arrow_ct else wd_ct for ct in CTS: contact.plot_single(c, ct, dp, clr=clr_ct, wd_line=wd_ct, sz_tic=sz_tic_ct, arrow=arrow_ct) hacks.write_plot(c, "tests/out/contact_example_TST_" + tag) return # ---------------------------------------------------------------------- def test_raster_raster_contact(): tag = "raster_raster_contact" mp_trace = mp_fill wd = move_parms.width(mp_trace) n = [4, 3] # Number of rasters in each path. plo = [None,None] # Lower left corner of bbox each path. plo[0] = ( 2, 1 ) plo[1] = ( 1, plo[0][1] + n[0]*wd ) szx = [3, 6] # X extent of traces of each path. OPHS = [None, None] for i in range(2): axis = 0 alt = True PHSi, TRSi = path_example.raster_rectangle(plo[i], 0, n[i], alt, szx[i], wd, mp_trace,None) OPHS[i] = PHSi[0] ct = contact_example.raster_raster_contact(OPHS[0], OPHS[1]) deco = True ct_arrows = True plot(tag, OPHS, [ct,], deco, ct_arrows) return # ---------------------------------------------------------------------- def test_misc_A(): sys.stderr.write("--- testing {plot,misc_A} ---\n") tag = "misc_A" ct = contact_example.misc_A(mp_fill) tr0 = contact.side(ct,0) tr1 = contact.side(ct,1) CTS = [ct,] OPHS = [ path.from_moves([tr0,]), path.from_moves([tr1,]), ] TRS = [ tr0, tr1, ] deco = True ct_arrows = False plot(tag, OPHS, [ct,], deco, ct_arrows) return # ---------------------------------------------------------------------- def test_misc_B(ct_arrows): sys.stderr.write("--- testing {plot,misc_B} with arrow = %s ---\n" % str(ct_arrows)) tag = "misc_B" CTS, OPHS, TRS = contact_example.misc_B(mp_fill, mp_jump) deco = True plot(tag, OPHS, CTS, deco, ct_arrows) return # ---------------------------------------------------------------------- def test_misc_C(): sys.stderr.write("--- testing {plot,misc_C} ---\n") tag = "misc_C" CTS, OPHS = contact_example.misc_C(mp_fill) deco = True ct_arrows = True plot(tag, OPHS, CTS, deco, ct_arrows) return # ---------------------------------------------------------------------- test_raster_raster_contact() test_misc_A() test_misc_B(False) test_misc_B(True) test_misc_C()