from __future__ import absolute_import, division

def exercise_polygon():
  from dials.util import is_inside_polygon
  from scitbx.array_family import flex

  poly = flex.vec2_double(((0,0), (1,0), (1,1), (0,1)))
  assert is_inside_polygon(poly, 0, 0)
  assert is_inside_polygon(poly, 0.5, 0.5)
  assert not is_inside_polygon(poly, 1, 1.01)

  points = flex.vec2_double(((0.3, 0.8), (0.3, 1.5), (-8,9), (0.00001, 0.9999)))
  assert list(is_inside_polygon(poly, points)) == [True, False, False, True]

def run():
  exercise_polygon()
  print 'OK'

if __name__ == '__main__':
  run()

@@ -502,33 +502,1199 @@
 def 
-run():%0A  exercise_polygon
+exercise_dynamic_shadowing():%0A  import os%0A  import libtbx.load_env%0A  try:%0A    dials_regression = libtbx.env.dist_path('dials_regression')%0A  except KeyError, e:%0A    print 'SKIP: dials_regression not configured'%0A    exit(0)%0A%0A  path = os.path.join(%0A    dials_regression, %22shadow_test_data/DLS_I04_SmarGon/Th_3_O45_C45_P48_1_0500.cbf%22)%0A%0A  from dxtbx.datablock import DataBlockFactory%0A  format_kwargs = %7B'dynamic_shadowing': True%7D%0A  assert os.path.exists(path), path%0A  datablock = DataBlockFactory.from_filenames(%5Bpath%5D, format_kwargs=format_kwargs)%5B0%5D%0A  imageset = datablock.extract_imagesets()%5B0%5D%0A  detector = imageset.get_detector()%0A  scan = imageset.get_scan()%0A  masker = imageset.reader().get_format().get_goniometer_shadow_masker()%0A  assert masker is not None%0A  mask = masker.get_mask(detector, scan_angle=scan.get_oscillation()%5B0%5D)%0A  assert len(mask) == len(detector)%0A  # only shadowed pixels masked%0A  assert (mask%5B0%5D.count(True), mask%5B0%5D.count(False)) == (5797243, 426758)%0A  mask = imageset.get_mask(0)%0A  # dead pixels, pixels in gaps, etc also masked%0A  assert (mask%5B0%5D.count(True), mask%5B0%5D.count(False)) == (5306061, 917940)%0A%0A%0Adef run():%0A  exercise_polygon()%0A  exercise_dynamic_shadowing
 ()%0A 

add test for dynamic shadowing