#! /usr/bin/python3
# Last edited on 2021-09-30 12:07:43 by stolfi

import path_hp
import path
import path_example
import block
import block_example
import job_parms
import move_parms

import sys
import rn
from math import sqrt, sin, cos, log, exp, floor, ceil, inf, nan, pi

parms = job_parms.typical_js()
parms['solid_raster_width'] = 1.0
parms['contour_trace_width'] = 0.5

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

def test_groups():
  sys.stderr.write("--- testing {set_group,get_group} ---\n")
  
  ph = path_example.misc_B(mp_fill, mp_jump)
  
  assert path_hp.get_group(ph) == None
  assert path_hp.get_group(path.rev(ph)) == None

  for oph in ph, path.rev(ph):
    path_hp.set_group(oph, 418)
    assert path_hp.get_group(oph) == 418
    path_hp.set_group(path.rev(oph), 4615)
    assert path_hp.get_group(oph) == 4615
  
  return 
  # ----------------------------------------------------------------------

def test_contacts():
  sys.stderr.write("--- testing {get_contacts,set_contacts} ---\n")
  
  ph = path_example.misc_B(mp_fill, mp_jump)
  
  # ??? Should test with real contacts ???
  ct1 = "FOO"
  ct2 = "BAR"
  ct3 = "BAZ"
  
  for oph in ph, path.rev(ph):
    path_hp.clear_contacts(oph)
    assert tuple(path_hp.get_contacts(oph, 0)) == ()
    assert tuple(path_hp.get_contacts(oph, 1)) == ()
    path_hp.add_contact(oph, 0, ct1)
    path_hp.add_contact(oph, 0, ct2)
    path_hp.add_contact(oph, 1, ct3)
    assert tuple(path_hp.get_contacts(oph, 0)) == (ct1, ct2,)
    assert tuple(path_hp.get_contacts(oph, 1)) == (ct3,)
  
  return 
  # ----------------------------------------------------------------------

def test_blocks():
  sys.stderr.write("--- testing {get_block,set_block} ---\n")
  
  ph = path_example.misc_B(mp_fill, mp_jump)
  
  bc = block.from_paths([ph, path.rev(ph)])
  path_hp.set_block(ph, bc)
  bc1 = path_hp.get_block(ph)
  assert bc1 == bc
  
  return 
  # ----------------------------------------------------------------------

test_groups()
test_contacts()
test_blocks()
