# /usr/bin/python3 # Test program for module {paper_figures_A} # Last edited on 2021-09-23 00:08:30 by stolfi import paper_figures_A 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_figure(tag, version, PCS,PFS,PLS): # Plot functions specific for the various raster type figure. # See {paper_figures_A.make_figure_A} and {paper_figures_A.make_figure_B} for the meaning of {version,PCS,PFS,PLS}. sys.stderr.write(" ... contour paths ...\n") path.show_list(sys.stderr, PCS, True, 2) sys.stderr.write(" ... raster fill elements ...\n") path.show_list(sys.stderr, PFS, True, 2) if PLS != None and len(PLS) != 0: sys.stderr.write(" ... link paths ...\n") path.show_list(sys.stderr, PLS, True, 2) # Validate and show moves: MVS = set() for ph in PCS + PFS + PLS: path.validate(ph) for i in range(path.nelems(ph)): mvi, dri = move.unpack(path.elem(ph, i)) MVS.add(mvi) if len(MVS) != 0: sys.stderr.write(" ... moves ...\n") move.show_list(sys.stderr, tuple(MVS), 2) B = None if len(PCS) != 0: B = rn.box_join(B, path.bbox(PCS)) if len(PFS) != 0: B = rn.box_join(B, path.bbox(PFS)) if len(PLS) != 0: B = rn.box_join(B, path.bbox(PLS)) npasses = 2 if version == 0 else 1 for ps in range(npasses): # Pass 0 for all versions -- plot {PCS,PFS}. # Pass 1 only for version 0 -- plot {PCS,PLS}. dp = None c, szx, szy = hacks.make_canvas(B, dp, True, True, 1, 1) # Plot all the matter traces: jmp = False # Plot traces only. cmatter = pyx.color.rgb(0.900, 0.850, 0.800) # Material footprint color. rwd_matter = 1.13 # Relative width of material footprint. wd_matter = 0 # Extra width of material footprint. dashed = False wd_dots = 0 sz_arrows = 0 wd_axes = 0.15*min(wd_fill,wd_cont) # Width of jumps and axis lines. for ph in PCS + PFS + PLS: path.plot_layer(c, ph, dp, jmp, cmatter, rwd_matter, wd_matter, dashed, wd_dots, sz_arrows) if version == 0: # Plot the contour paths with a subdued color: rwd_cont = 0.80 # Relative width of trace sausages. ccont = pyx.color.rgb( 0.500, 0.600, 1.000 ) axes = True dots = True arrows = False matter = False path.plot_standard(c, PCS, dp, None, [ccont,], rwd_cont, wd_axes, axes, dots, arrows, matter) if version != 0 or ps == 0: # Plot the filling path(s): cfill = pyx.color.rgb(0.050, 0.800, 0.000) rwd_fill = 0.70 # Relative width of link trace sausages. axes = True dots = True arrows = True matter = False path.plot_standard(c, PFS, dp, None, [cfill], rwd_fill, wd_axes, axes, dots, arrows, matter) if version == 0 and ps == 1: # Plot individual links with various colors: nph = len(PLS) CLRS = hacks.trace_colors(nph) rwd_link = 0.50 # Relative width of link trace sausages. axes = True dots = True arrows = False matter = False path.plot_standard(c, PLS, dp, None, CLRS, rwd_link, wd_axes, axes, dots, arrows, matter) hacks.write_plot(c, "tests/out/paper_figures_A_TST_" + tag + ("_v%dp%d" % (version,ps))) return # ---------------------------------------------------------------------- def test_make_figure(): sys.stderr.write("--- testing {make_figure} ---\n") for version in range(6): sys.stderr.write(" ... version %d ...\n" % version) tag = "make_figure" PCS,PFS,PLS = paper_figures_A.make_figure(version, mp_cont, mp_fill, mp_jump) if PFS != None: show_and_plot_figure(tag, version, PCS,PFS,PLS) else: sys.stderr.write("!! version %d not implemented\n") return # ---------------------------------------------------------------------- test_make_figure()