# /usr/bin/python3 # Test program for module {paper_figures_A} # Last edited on 2021-10-19 13:32:37 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, OCRS,OPHS,OLKS): # 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,OCRS,OPHS,OLKS}. sys.stderr.write(" ... contour paths ...\n") path.show_list(sys.stderr, OCRS, True, 2) sys.stderr.write(" ... raster fill elements ...\n") path.show_list(sys.stderr, OPHS, True, 2) if OLKS != None and len(OLKS) != 0: sys.stderr.write(" ... link paths ...\n") path.show_list(sys.stderr, OLKS, True, 2) # Validate and show moves: MVS = set() for ph in OCRS + OPHS + OLKS: 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(OCRS) != 0: B = rn.box_join(B, path.bbox(OCRS)) if len(OPHS) != 0: B = rn.box_join(B, path.bbox(OPHS)) if len(OLKS) != 0: B = rn.box_join(B, path.bbox(OLKS)) npasses = 2 if version == 0 else 1 for ps in range(npasses): # Pass 0 for all versions -- plot {OCRS,OPHS}. # Pass 1 only for version 0 -- plot {OCRS,OLKS}. 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 = hacks.matter_color(None) # 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 OCRS + OPHS + OLKS: 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, OCRS, 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, OPHS, 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(OLKS) 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, OLKS, 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" OCRS,OPHS,OLKS = paper_figures_A.make_figure(version, mp_cont, mp_fill, mp_jump) if OPHS != None: show_and_plot_figure(tag, version, OCRS,OPHS,OLKS) else: sys.stderr.write("!! version %d not implemented\n") return # ---------------------------------------------------------------------- test_make_figure()