Ignore:
Timestamp:
Jun 22, 2010, 12:04:32 PM (13 years ago)
Author:
hudson
Message:

More swb tests passing. Cleaned up some pylint errors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/geometry/test_polygon.py

    r7858 r7866  
    11#!/usr/bin/env python
     2
     3""" Test suite to test polygon functionality. """
    24
    35import unittest
    46import numpy as num
    5 from math import sqrt, pi
    67from anuga.utilities.numerical_tools import ensure_numeric
    78from anuga.utilities.system_tools import get_pathname_from_package
    89
    9 from polygon import *
    10 from polygon import _poly_xy
     10from polygon import _poly_xy, separate_points_by_polygon, \
     11                    populate_polygon, polygon_area, is_inside_polygon, \
     12                    read_polygon, point_on_line, point_in_polygon, \
     13                    plot_polygons, outside_polygon, is_outside_polygon, \
     14                    intersection, is_complex, is_inside_triangle, \
     15                    interpolate_polyline, inside_polygon, in_and_outside_polygon
     16                   
    1117from polygon_function import Polygon_function
    1218from anuga.coordinate_transforms.geo_reference import Geo_reference
     
    401407
    402408        polygon = [[0,0], [1,0], [0.5,-1], [2, -1], [2,1], [0,1]]
    403         points = [ [0.5, 1.4], [0.5, 0.5], [1, -0.5], [1.5, 0], [0.5, 1.5], [0.5, -0.5]]
     409        points = [ [0.5, 1.4], [0.5, 0.5], [1, -0.5], [1.5, 0], [0.5, 1.5], \
     410                        [0.5, -0.5]]
    404411        res, count = separate_points_by_polygon( points, polygon )
    405412
     
    14011408
    14021409    def test_no_intersection(self):
     1410        """ Test 2 non-touching lines don't intersect. """
    14031411        line0 = [[-1,1], [1,1]]
    14041412        line1 = [[0,-1], [0,0]]
     
    14691477
    14701478        # Overlap
    1471         line0 = [[0,5], [7,19]]
    1472         line1 = [[1,7], [10,25]]
     1479        line0 = [[0, 5], [7, 19]]
     1480        line1 = [[1, 7], [10, 25]]
    14731481        status, value = intersection(line0, line1)
    14741482        assert status == 2
     
    15121520
    15131521
    1514     def NOtest_inside_polygon_main(self):
    1515         # FIXME (Ole): Why is this disabled?
    1516         #print "inside",inside
    1517         #print "outside",outside
    1518 
    1519         assert not inside_polygon((0.5, 1.5), polygon)
    1520         assert not inside_polygon((0.5, -0.5), polygon)
    1521         assert not inside_polygon((-0.5, 0.5), polygon)
    1522         assert not inside_polygon((1.5, 0.5), polygon)
    1523 
    1524         # Try point on borders
    1525         assert inside_polygon((1., 0.5), polygon, closed=True)
    1526         assert inside_polygon((0.5, 1), polygon, closed=True)
    1527         assert inside_polygon((0., 0.5), polygon, closed=True)
    1528         assert inside_polygon((0.5, 0.), polygon, closed=True)
    1529 
    1530         assert not inside_polygon((0.5, 1), polygon, closed=False)
    1531         assert not inside_polygon((0., 0.5), polygon, closed=False)
    1532         assert not inside_polygon((0.5, 0.), polygon, closed=False)
    1533         assert not inside_polygon((1., 0.5), polygon, closed=False)
    1534 
     1522    def test_inside_polygon_main(self):
    15351523        # From real example (that failed)
    15361524        polygon = [[20,20], [40,20], [40,40], [20,40]]
     
    15461534
    15471535    def test_polygon_area(self):
     1536        """ Test getting the area of a polygon. """
    15481537        # Simplest case: Polygon is the unit square
    15491538        polygon = [[0,0], [1,0], [1,1], [0,1]]
     
    16111600        # Another case
    16121601        polygon3 = [[1,5], [10,1], [100,10], [50,10], [3,6]]
    1613         v = plot_polygons([polygon2,polygon3], figname='test2')
     1602        plot_polygons([polygon2, polygon3], figname='test2')
    16141603
    16151604        for file in ['test1.png', 'test2.png']:
     
    16191608
    16201609    def test_inside_polygon_geospatial(self):
     1610        """ Test geospatial coords inside poly. """
    16211611        #Simplest case: Polygon is the unit square
    1622         polygon_absolute = [[0,0], [1,0], [1,1], [0,1]]
     1612        polygon_absolute = [[0, 0], [1, 0], [1, 1], [0, 1]]
    16231613        poly_geo_ref = Geo_reference(57, 100, 100)
    16241614        polygon = poly_geo_ref.change_points_geo_ref(polygon_absolute)
     
    16391629        assert is_inside_polygon(points_absolute, polygon_absolute)
    16401630
    1641     def NOtest_decimate_polygon(self):
     1631    def test_decimate_polygon(self):
     1632        from polygon import decimate_polygon
    16421633        polygon = [[0,0], [10,10], [15,5], [20, 10],
    16431634                   [25,0], [30,10], [40,-10], [35, -5]]
     
    16451636        dpoly = decimate_polygon(polygon, factor=2)
    16461637
    1647         print dpoly
    1648 
    16491638        assert len(dpoly)*2==len(polygon)
    16501639
    1651         minx = maxx = polygon[0][0]
    1652         miny = maxy = polygon[0][1]
    1653         for point in polygon[1:]:
    1654             x, y = point
    1655 
    1656             if x < minx: minx = x
    1657             if x > maxx: maxx = x
    1658             if y < miny: miny = y
    1659             if y > maxy: maxy = y
    1660 
    1661         assert [minx, miny] in polygon
    1662         print minx, maxy
    1663         assert [minx, maxy] in polygon
    1664         assert [maxx, miny] in polygon
    1665         assert [maxx, maxy] in polygon
    16661640
    16671641    def test_interpolate_polyline(self):
     
    17561730
    17571731    def test_is_inside_triangle_more(self):
    1758 
     1732        """ Test if points inside triangles are detected correctly. """
    17591733        res = is_inside_triangle([0.5, 0.5], [[ 0.5,  0. ],
    17601734                                              [ 0.5,  0.5],
     
    18021776       
    18031777    def test_is_polygon_complex(self):
    1804         """Test a concave and a complex poly with is_complex, to make sure it can detect
    1805            self-intersection.
     1778        """ Test a concave and a complex poly with is_complex, to make
     1779            sure it can detect self-intersection.
    18061780        """
    18071781        concave_poly = [[0, 0], [10, 0], [5, 5], [10, 10], [0, 10]]
    1808         complex_poly = [[0, 0], [10, 0], [5, 5], [4, 15], [5, 7], [10, 10], [0, 10]]
     1782        complex_poly = [[0, 0], [10, 0], [5, 5], [4, 15], [5, 7], [10, 10], \
     1783                            [0, 10]]
    18091784
    18101785        assert not is_complex(concave_poly)
     
    18121787
    18131788    def test_is_polygon_complex2(self):
    1814         """Test a concave and a complex poly with is_complex, to make sure it can detect
    1815            self-intersection. This test uses more complicated polygons.
     1789        """ Test a concave and a complex poly with is_complex, to make sure it
     1790            can detect self-intersection. This test uses more complicated
     1791            polygons.
    18161792        """   
    1817         concave_poly = [[0, 0], [10, 0], [11,0], [5, 5], [7,6], [10, 10], [1,5], [0, 10]]
    1818         complex_poly = [[0, 0], [12,12], [10, 0], [5, 5], [3,18], [4, 15], [5, 7], [10, 10], [0, 10], [16, 12]]       
     1793        concave_poly = [[0, 0], [10, 0], [11,0], [5, 5], [7, 6], [10, 10], \
     1794                        [1, 5], [0, 10]]
     1795        complex_poly = [[0, 0], [12, 12], [10, 0], [5, 5], [3,18], [4, 15], \
     1796                        [5, 7], [10, 10], [0, 10], [16, 12]]       
    18191797
    18201798        assert not is_complex(concave_poly)
Note: See TracChangeset for help on using the changeset viewer.