Changeset 5933


Ignore:
Timestamp:
Nov 10, 2008, 5:52:32 PM (15 years ago)
Author:
rwilson
Message:

Added test cases to exercise changes in polygon.py.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/utilities/test_polygon.py

    r5897 r5933  
    651651        assert allclose(value, [1.0, 1.0])       
    652652       
     653
     654    # This function is a helper function for the test_intersection_bug_20081110_?()
     655    # set of tests.
     656    # This function should never be run directly by the unittest code.
     657    def helper_test_parallel_intersection_code(self, P1, P2, P3, P4):
     658        # lines in same direction, no overlap
     659        # 0:         ---->----
     660        # 1:                     --------->-----------
     661        line0 = [P1,P2]
     662        line1 = [P3,P4]
     663        status, value = intersection(line0, line1)
     664        self.failIf(status!=3, 'Expected status 3, got status=%s, value=%s' %
     665                               (str(status), str(value)))
     666        self.failUnless(value is None, 'Expected value of None, got %s' %
     667                                       str(value))
     668
     669        # lines in same direction, no overlap
     670        # 0:         ----<----
     671        # 1:                     ---------<-----------
     672        line0 = [P2,P1]
     673        line1 = [P4,P3]
     674        status, value = intersection(line0, line1)
     675        self.failIf(status!=3, 'Expected status 3, got status=%s, value=%s' %
     676                               (str(status), str(value)))
     677        self.failUnless(value is None, 'Expected value of None, got %s' %
     678                                       str(value))
     679
     680        # lines in opposite direction, no overlap
     681        # 0:         ----<----
     682        # 1:                     --------->-----------
     683        line0 = [P2,P1]
     684        line1 = [P3,P4]
     685        status, value = intersection(line0, line1)
     686        self.failIf(status!=3, 'Expected status 3, got status=%s, value=%s' %
     687                               (str(status), str(value)))
     688        self.failUnless(value is None, 'Expected value of None, got %s' %
     689                                       str(value))
     690
     691        # lines in opposite direction, no overlap
     692        # 0:         ---->----
     693        # 1:                     ---------<-----------
     694        line0 = [P1,P2]
     695        line1 = [P4,P3]
     696        status, value = intersection(line0, line1)
     697        self.failIf(status!=3, 'Expected status 3, got status=%s, value=%s' %
     698                               (str(status), str(value)))
     699        self.failUnless(value is None, 'Expected value of None, got %s' %
     700                                       str(value))
     701
     702        # line0 fully within line1, same direction
     703        # 0:         ---->----
     704        # 1:    --------->-----------
     705        # value should be line0:
     706        #            ---->----
     707        line0 = [P2,P3]
     708        line1 = [P1,P4]
     709        status, value = intersection(line0, line1)
     710        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
     711                               (str(status), str(value)))
     712        self.failUnless(numpy.allclose(value, line0))
     713
     714        # line0 fully within line1, same direction
     715        # 0:         ----<----
     716        # 1:    ---------<-----------
     717        # value should be line0:
     718        #            ----<----
     719        line0 = [P3,P2]
     720        line1 = [P4,P1]
     721        status, value = intersection(line0, line1)
     722        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
     723                               (str(status), str(value)))
     724        self.failUnless(numpy.allclose(value, line0))
     725
     726        # line0 fully within line1, opposite direction
     727        # 0:         ----<----
     728        # 1:    --------->-----------
     729        # value should be line0:
     730        #            ----<----
     731        line0 = [P3,P2]
     732        line1 = [P1,P4]
     733        status, value = intersection(line0, line1)
     734        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
     735                               (str(status), str(value)))
     736        self.failUnless(numpy.allclose(value, line0))
     737
     738        # line0 fully within line1, opposite direction
     739        # 0:         ---->----
     740        # 1:    ---------<-----------
     741        # value should be line0:
     742        #            ---->----
     743        line0 = [P2,P3]
     744        line1 = [P4,P1]
     745        status, value = intersection(line0, line1)
     746        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
     747                               (str(status), str(value)))
     748        self.failUnless(numpy.allclose(value, line0))
     749
     750        # line1 fully within line0, same direction
     751        # 0:    --------->-----------
     752        # 1:         ---->----
     753        # value should be line1:
     754        #            ---->----
     755        line0 = [P1,P4]
     756        line1 = [P2,P3]
     757        status, value = intersection(line0, line1)
     758        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
     759                               (str(status), str(value)))
     760        self.failUnless(numpy.allclose(value, line1))
     761
     762        # line1 fully within line0, same direction
     763        # 0:    ---------<-----------
     764        # 1:         ----<----
     765        # value should be line1:
     766        #            ----<----
     767        line0 = [P4,P1]
     768        line1 = [P3,P2]
     769        status, value = intersection(line0, line1)
     770        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
     771                               (str(status), str(value)))
     772        self.failUnless(numpy.allclose(value, line1))
     773
     774        # line1 fully within line0, opposite direction
     775        # 0:    ---------<-----------
     776        # 1:         ---->----
     777        # value should be line1:
     778        #            ---->----
     779        line0 = [P4,P1]
     780        line1 = [P2,P3]
     781        status, value = intersection(line0, line1)
     782        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
     783                               (str(status), str(value)))
     784        self.failUnless(numpy.allclose(value, line1))
     785
     786        # line1 fully within line0, opposite direction
     787        # 0:    --------->-----------
     788        # 1:         ----<----
     789        # value should be line1:
     790        #            ----<----
     791        line0 = [P1,P4]
     792        line1 = [P3,P2]
     793        status, value = intersection(line0, line1)
     794        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
     795                               (str(status), str(value)))
     796        self.failUnless(numpy.allclose(value, line1))
     797
     798        # line in same direction, partial overlap
     799        # 0:    ----->-----
     800        # 1:       ------->--------
     801        # value should be segment line1_start->line0_end:
     802        #          --->----
     803        line0 = [P1,P3]
     804        line1 = [P2,P4]
     805        status, value = intersection(line0, line1)
     806        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
     807                               (str(status), str(value)))
     808        self.failUnless(numpy.allclose(value, [line1[0],line0[1]]))
     809
     810        # line in same direction, partial overlap
     811        # 0:    -----<-----
     812        # 1:       -------<--------
     813        # value should be segment line0_start->line1_end:
     814        #          ---<----
     815        line0 = [P3,P1]
     816        line1 = [P4,P2]
     817        status, value = intersection(line0, line1)
     818        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
     819                               (str(status), str(value)))
     820        self.failUnless(numpy.allclose(value, [line0[0],line1[1]]))
     821
     822        # line in opposite direction, partial overlap
     823        # 0:    -----<-----
     824        # 1:       ------->--------
     825        # value should be segment line0_start->line1_start:
     826        #          ---<----
     827        line0 = [P3,P1]
     828        line1 = [P2,P4]
     829        status, value = intersection(line0, line1)
     830        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
     831                               (str(status), str(value)))
     832        self.failUnless(numpy.allclose(value, [line0[0],line1[0]]))
     833
     834        # line in opposite direction, partial overlap
     835        # 0:    ----->-----
     836        # 1:       -------<--------
     837        # value should be segment line1_end->line0_end:
     838        #          --->----
     839        line0 = [P1,P3]
     840        line1 = [P4,P2]
     841        status, value = intersection(line0, line1)
     842        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
     843                               (str(status), str(value)))
     844        self.failUnless(numpy.allclose(value, [line1[1],line0[1]]))
     845
     846        # line in same direction, partial overlap
     847        # 0:       ------>------
     848        # 1:    ------>------
     849        # value should be segment line0_start->line1_end:
     850        #          --->----
     851        line0 = [P2,P4]
     852        line1 = [P1,P3]
     853        status, value = intersection(line0, line1)
     854        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
     855                               (str(status), str(value)))
     856        self.failUnless(numpy.allclose(value, [line0[0],line1[1]]))
     857
     858        # line in same direction, partial overlap
     859        # 0:       ------<------
     860        # 1:    ------<------
     861        # value should be segment line1_start->line0_end:
     862        #          ----<-----
     863        line0 = [P4,P2]
     864        line1 = [P3,P1]
     865        status, value = intersection(line0, line1)
     866        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
     867                               (str(status), str(value)))
     868        self.failUnless(numpy.allclose(value, [line1[0],line0[1]]))
     869
     870        # line in opposite direction, partial overlap
     871        # 0:       ------<------
     872        # 1:    ----->------
     873        # value should be segment line1_end->line0_end:
     874        #          --->----
     875        line0 = [P4,P2]
     876        line1 = [P1,P3]
     877        status, value = intersection(line0, line1)
     878        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
     879                               (str(status), str(value)))
     880        self.failUnless(numpy.allclose(value, [line1[1],line0[1]]))
     881
     882        # line in opposite direction, partial overlap
     883        # 0:       ------>------
     884        # 1:    -----<------
     885        # value should be segment line0_start->line1_start:
     886        #          ---<----
     887        line0 = [P2,P4]
     888        line1 = [P3,P1]
     889        status, value = intersection(line0, line1)
     890        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
     891                               (str(status), str(value)))
     892        self.failUnless(numpy.allclose(value, [line0[0],line1[0]]))
     893
     894       
     895    def test_intersection_bug_20081110_1(self):
     896        """test_intersection_bug_20081110(self)
     897
     898        Run through all possible cases of parallel lines.
     899        """
     900
     901        # define 4 collinear points
     902        #    P1---P2---P3---P4
     903        P1 = [1.0, 0.0]
     904        P2 = [2.0, 0.0]
     905        P3 = [3.0, 0.0]
     906        P4 = [4.0, 0.0]
     907       
     908        self.helper_test_parallel_intersection_code(P1, P2, P3, P4)       
     909
     910
     911    def test_intersection_bug_20081110_2(self):
     912        """test_intersection_bug_20081110(self)
     913
     914        Run through all possible cases of parallel lines.
     915        """
     916
     917        # define 4 *almost* collinear points
     918        #    P1---P2---P3---P4
     919        P1 = [1.0, 1.0e-9]
     920        P2 = [2.0, 0.0]
     921        P3 = [3.0, 0.0]
     922        P4 = [4.0, 0.0]
     923
     924        self.helper_test_parallel_intersection_code(P1, P2, P3, P4)       
     925
     926
     927    def test_intersection_bug_20081110_3(self):
     928        """test_intersection_bug_20081110(self)
     929
     930        Run through all possible cases of parallel lines.
     931        """
     932
     933        # define 4 *almost* collinear points
     934        #    P1---P2---P3---P4
     935        P1 = [1.0, 0.0]
     936        P2 = [2.0, 1.0e-9]
     937        P3 = [3.0, 0.0]
     938        P4 = [4.0, 0.0]
     939
     940        self.helper_test_parallel_intersection_code(P1, P2, P3, P4)       
     941
     942
     943    def test_intersection_bug_20081110_4(self):
     944        """test_intersection_bug_20081110(self)
     945
     946        Run through all possible cases of parallel lines.
     947        """
     948
     949        # define 4 *almost* collinear points
     950        #    P1---P2---P3---P4
     951        P1 = [1.0, 0.0]
     952        P2 = [2.0, 0.0]
     953        P3 = [3.0, 1.0e-9]
     954        P4 = [4.0, 0.0]
     955
     956        self.helper_test_parallel_intersection_code(P1, P2, P3, P4)       
     957
     958
     959    def test_intersection_bug_20081110_5(self):
     960        """test_intersection_bug_20081110(self)
     961
     962        Run through all possible cases of parallel lines.
     963        """
     964
     965        # define 4 *almost* collinear points
     966        #    P1---P2---P3---P4
     967        P1 = [1.0, 0.0]
     968        P2 = [2.0, 0.0]
     969        P3 = [3.0, 0.0]
     970        P4 = [4.0, 1.0e-9]
     971
     972        self.helper_test_parallel_intersection_code(P1, P2, P3, P4)       
     973
    653974
    654975    def test_intersection_direction_invariance(self):
Note: See TracChangeset for help on using the changeset viewer.