#! /usr/bin/python3
# Test program for module {block_example}.
# Last edited on 2021-03-21 11:57:11 by jstolfi

import block_example
import block
import path
import move
import move_parms
import contact
import hacks
import job_parms
import color
import rn
import pyx
import sys
from math import sqrt, sin, cos, floor, ceil, inf, nan, pi

parms = job_parms.typical()

mp_jump = move_parms.make_for_jumps(parms)
mp_cont = move_parms.make_for_contours(parms)
mp_fill = move_parms.make_for_fillings(parms)

wdf = move_parms.width(mp_fill)
wdc = move_parms.width(mp_cont)

def plot(tag, BCS, deco):
  fname = "tests/out/block_example_TST_" + tag
  wd_axes = 0.05*wdf
  axes = deco
  dots = deco
  arrows = deco
  matter = True
  CLRS = hacks.trace_colors(len(BCS))
  block.plot_to_files(fname, BCS, CLRS, wd_axes, matter=True)
  return
  # ----------------------------------------------------------------------

def test_single_raster():
  sys.stderr.write("--- testing {single_raster} ---\n")
  tag = "single_raster"
  xlo = 2
  xhi = 4
  y = 2
  bc = block_example.single_raster(xlo, xhi, y, mp_fill)
  plot(tag, [bc,], True)
  return
  # ----------------------------------------------------------------------

def test_spiral_rectangle():
  sys.stderr.write("--- testing {spiral_rectangle} ---\n")
  tag = "spiral_rectangle"
  plo = (2,1)
  szx = 7*wdf; szy = 6*wdf
  bc = block_example.spiral_rectangle(plo, szx, szy, mp_fill)
  plot(tag, [bc,], True)
  return
  # ----------------------------------------------------------------------

def test_raster_rectangle(hor, ver, alt):
  sys.stderr.write("--- testing {rater_rectangle} hor = %s ver = %s ---\n" % (str(hor), str(ver)))
  tag = ("raster_rectangle_h%d_v%d_a%d" % (int(hor),int(ver),int(alt)))
  plo = (2,2)
  nx = 4
  ny = 6
  bc = block_example.raster_rectangle(plo, nx, ny, hor, ver, alt, mp_fill, mp_jump)
  block.validate(bc)
  plot(tag, [bc,], True)
  return
  # ----------------------------------------------------------------------

def test_onion():
  sys.stderr.write("--- testing {onion} ---\n")
  tag = "onion"
  nch = 6
  ctr = (4,4)
  Rc = 4
  Rf = 1
  bc = block_example.onion(nch, ctr, Rc, mp_cont, Rf, mp_fill, mp_jump)
  block.validate(bc)
  plot(tag, [bc,], True)
  return
  # ----------------------------------------------------------------------

def test_misc_A():
  sys.stderr.write("--- testing {misc_A} ---\n")
  tag = "misc_A"
  BCS, OPHS, TRS, JMS = block_example.misc_A(mp_fill, mp_jump)
  for bc in BCS: block.validate(bc)
  plot(tag, BCS, True)
  return
  # ----------------------------------------------------------------------

def test_misc_B():
  sys.stderr.write("--- testing {misc_B} ---\n")
  tag = "misc_B"
  BCS, OPHS, TRS, JMS = block_example.misc_B(mp_fill, mp_jump)
  for bc in BCS: block.validate(bc)
  plot(tag, BCS, True)
  return
  # ----------------------------------------------------------------------

def test_misc_C():
  sys.stderr.write("--- testing {misc_C} ---\n")
  tag = "misc_C"
  BCS = block_example.misc_C(mp_fill)
  for bc in BCS: block.validate(bc)
  plot(tag, BCS, True)
  return
  # ----------------------------------------------------------------------

def test_misc_D():
  sys.stderr.write("--- testing {misc_D} ---\n")
  tag = "misc_D"
  BCS = block_example.misc_D(mp_fill)
  for bc in BCS: block.validate(bc)
  plot(tag, BCS, True)
  return
  # ----------------------------------------------------------------------

test_single_raster()
test_raster_rectangle(True,False,False)
test_raster_rectangle(True,False,True)
test_raster_rectangle(False,True,True)
test_raster_rectangle(True,True,False)
test_spiral_rectangle()
test_onion()
test_misc_A()
test_misc_B()
test_misc_C()
test_misc_D()
