#! /bin/usr/python3
# Test program for module {seam}
# Last edited on 2021-03-16 21:56:16 by jstolfi

import seam
import seam_example
import move
import move_parms
import path
import block
import block_example
import contact
import contact_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)

def test_basics():
  sys.stderr.write("--- testing {make,get_contacts,side,which_side,is_directed} ---\n")
  BCS, OPHS, TRS, JMS = block_example.misc_A(mp_fill, mp_jump)
  bc0 = BCS[0]
  bc1 = BCS[1]
  MVS0 = block.moves(bc0)
  MVS1 = block.moves(bc1)
  CTS = contact.from_move_lists(MVS0, MVS1, 0, 0)
  for drc in False, True:
    sm = seam.make(bc0, bc1, CTS, drc)
    assert seam.is_directed(sm) == drc
    assert tuple(CTS) == seam.get_contacts(sm)
    assert seam.side(sm, 0) == bc0
    assert seam.side(sm, 1) == bc1
    assert seam.which_side(bc0, sm) == 0
    assert seam.which_side(bc1, sm) == 1
  return
  # ----------------------------------------------------------------------
  
def test_plot_to_files():
  sys.stderr.write("--- testing {plot_to_files} ---\n")

  tag = "A"
  SMS, BCS = seam_example.misc_A(mp_fill)
  nsm = len(SMS)
  nbc = len(BCS)
  
  fname = ("tests/out/seam_TST_plot_to_files_%s" % tag)
  clr = pyx.color.rgb(1.000, 0.200, 0.000)
  CLRS = hacks.trace_colors(nbc)
  wd_axes = 0.05*wd_fill
  matter = True
  seam.plot_to_files(fname, SMS, clr, BCS, CLRS, wd_axes, matter)
  return
  # ----------------------------------------------------------------------
  
def test_plot_standard():
  sys.stderr.write("--- testing {plot_standard} ---\n")

  tag = "B"
  SMS, BCS = seam_example.misc_A(mp_fill)
  nsm = len(SMS)
  nbc = len(BCS)
  
  clr = pyx.color.rgb(1.000, 0.200, 0.000)
  CLRS = hacks.trace_colors(nbc)
  wd_axes = 0.05*wd_fill
  matter = True
 
  c = pyx.canvas.canvas()
  pyx.unit.set(uscale=1.00, wscale=1.00, vscale=1.00)

  dp = None
  axes = True
  dots = True
  arrows = True
  matter = True
  wd_line = 3*wd_axes
  grid = True
  seam.plot_standard \
    ( c, SMS, dp, clr, wd_line, BCS, CLRS, wd_axes, \
      axes=axes, dots=dots, arrows=arrows, matter=matter, grid=grid
    )
  
  fname = ("tests/out/seam_TST_plot_standard_%s" % tag)
  hacks.write_plot(c, fname)
  return
  # ----------------------------------------------------------------------
 

# def test_heuristic_fields():
#   sys.stderr.write("--- testing {get_paths,set_paths,get_coverage,set_coverage} ---\n")
# 
#   TRS, JMS = move.misc_C(mp_fill, mp_jump)
#   BCS = block.misc_B(TRS, JMS)
#   SMS = seam.misc_A(TRS)
# 
#   sm = SMS[0]
#   
#   iscov = [ False, True, ]
#   seam.set_coverage_status(sm, iscov)
#   iscov1 = seam.get_coverage_status(sm)
#   assert iscov1 == iscov
# 
#   # Some paths that contain the sides of the seam:
#   assert seam.side(sm, 0) == TRS[0]
#   assert seam.side(sm, 1) == TRS[1]
#   bc0 = BCS[0] # Move 0 should be {TRS[0])
#   bc1 = BCS[2] # Move 2 should be {TRS[1])
#   bc2 = path.concat([ path.from_moves([TRS[0],]), path.from_moves([TRS[9],])], True, False, mp_jump)
#   bc3 = path.from_moves([TRS[1],])
#   bcss = [ [ bc0, path.rev(bc0), bc2 ], [ bc1, bc3, path.rev(bc3), ] ]
#   seam.set_paths(sm, bcss)
#   bcss1 = seam.get_paths(sm)
#   assert bcss1 == bcss
#   return
#   # ----------------------------------------------------------------------

test_basics()
test_plot_standard()
test_plot_to_files()

# test_print_seam_table
# test_coverage_times(TRS, JMS, BCS, SMS)
# test_heuristic_fields()
