def test_polygon_system_test(self): poly1 = polygon_class.polygon_object(small_square) poly2 = polygon_class.polygon_object(large_square) poly3 = polygon_class.polygon_object(source_square) poly = poly3.difference(poly1) assert allclose(poly.area,source_square_area-small_square_area/2) poly = poly2.intersection(poly) assert allclose(poly.area,large_square_area*3/5-small_square_area/2)
def _test_speed(self): from time import time t0=time() for i in xrange(1000): poly1 = polygon_class.polygon_object(small_square) poly2 = polygon_class.polygon_object(large_square) poly3 = polygon_class.polygon_object(source_square) poly = poly3.difference(poly1) assert allclose(poly.area,source_square_area-small_square_area/2) poly = poly2.intersection(poly) assert allclose(poly.area,large_square_area*3/5-small_square_area/2) print 'Time to run 1000 polygon diffs: '+str(time()-t0)
def FIXME_test_polygon_object_invalid(self): try: poly = polygon_class.polygon_object(invalid) msg = 'Should have raised an invalid polygon!!!!' assert 1 == 0, msg except ValueError: pass
def test_contains_point3(self): outline = [[ -35. , 149.5 ], [ -32.925 ,149.5 ], [ -32.925 ,151.4 ], [ -33.5 ,151.9 ], [ -33.25 ,152.25 ], [ -33.25 ,152.33 ], [ -34.4 ,151.35 ], [ -34.74 ,151.15 ], [ -35. ,151.1 ], [ -35. ,149.5 ]] # The position of these points have not been manually checked. point = (-32.789999999999999, 151.96000000000001) po = polygon_object(outline) is_in = po.contains_point(point) assert not is_in point = (-33.109999999999999, 151.94) is_in = po.contains_point(point) assert not is_in point = (-33.170000000000002, 152.12) is_in = po.contains_point(point) assert not is_in
def test_contains_point(self): outline = [(-32.3999999999999990, 151.1500000000000100), (-32.7500000000000000, 152.1699999999999900), (-33.4500000000000030, 151.4300000000000100), (-32.3999999999999990, 151.1500000000000100)] # This point is outside the triangle point = (-33.280000000000001, 151.61000000000001) po = polygon_object(outline) is_in = po.contains_point(point) assert not is_in
def test_contains_point2(self): outline = [(-35.0, 149.5), (-32.399999999999999, 149.5), (-32.399999999999999, 151.15000000000001), (-33.450000000000003, 151.43000000000001), (-32.75, 152.16999999999999), (-32.75, 152.75999999999999), (-34.399999999999999, 151.34999999999999), (-34.740000000000002, 151.15000000000001), (-35.0, 151.09999999999999), (-35.0, 149.5)] # This point is outside point = (-32.789999999999999, 151.96000000000001) po = polygon_object(outline) is_in = po.contains_point(point) assert not is_in point = (-33.170000000000002, 152.12) is_in = po.contains_point(point) assert is_in
def test_complex_polygon_difference(self): poly1 = polygon_class.polygon_object(small_square) poly2 = polygon_class.polygon_object(narrow_square) poly = poly1.difference(poly2) assert allclose(poly.area,small_square_area/2)
def test_polygon_difference4(self): poly1 = polygon_class.polygon_object(large_square) poly2 = polygon_class.polygon_object(large_square) poly = poly1.difference(poly2) assert allclose(poly.area,0.) assert poly is polygon_class.empty_polygon
def test_polygon_difference3(self): poly1 = polygon_class.polygon_object(large_square) poly2 = polygon_class.polygon_object(source_square) poly = poly1.difference(poly2) assert allclose(poly.area,large_square_area*2/5)
def test_polygon_difference2(self): poly1 = polygon_class.polygon_object(small_square) poly2 = polygon_class.polygon_object(source_square) poly = poly1.difference(poly2) assert allclose(poly.area,small_square_area/2)
def test_polygon_object(self): poly = polygon_class.polygon_object(small_square) assert allclose(poly.area,small_square_area)
def test_polygon_intersection2(self): poly1 = polygon_class.polygon_object(small_square) poly2 = polygon_class.polygon_object(source_square) poly = poly1.intersection(poly2) assert allclose(poly.area,small_square_area/2)
def test_polygon_intersection(self): poly1 = polygon_class.polygon_object(small_square) poly2 = polygon_class.polygon_object(large_square) poly = poly1.intersection(poly2) assert poly1 is poly