Changeset 5942
- Timestamp:
- Nov 12, 2008, 10:55:39 AM (16 years ago)
- Location:
- anuga_core/source/anuga/utilities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/polygon.py
r5932 r5942 42 42 43 43 44 45 44 ###### 45 # Result functions used in intersection() below for collinear lines. 46 # (p0,p1) defines line 0, (p2,p3) defines line 1. 47 ###### 48 49 # result functions for possible states 50 def lines_dont_coincide(p0,p1,p2,p3): return (3, None) 51 def lines_0_fully_included_in_1(p0,p1,p2,p3): return (2, array([p0,p1])) 52 def lines_1_fully_included_in_0(p0,p1,p2,p3): return (2, array([p2,p3])) 53 def lines_overlap_same_direction(p0,p1,p2,p3): return (2, array([p0,p3])) 54 def lines_overlap_same_direction2(p0,p1,p2,p3): return (2, array([p2,p1])) 55 def lines_overlap_opposite_direction(p0,p1,p2,p3): return (2, array([p0,p2])) 56 def lines_overlap_opposite_direction2(p0,p1,p2,p3): return (2, array([p3,p1])) 57 58 # this function called when an impossible state is found 59 def lines_error(p1, p2, p3, p4): raise RuntimeError, "INTERNAL ERROR" 60 61 # 0s1 0e1 1s0 1e0 # line 0 starts on 1, 0 ends 1, 1 starts 0, 1 ends 0 62 collinear_result = { (False, False, False, False): lines_dont_coincide, 63 (False, False, False, True ): lines_error, 64 (False, False, True, False): lines_error, 65 (False, False, True, True ): lines_1_fully_included_in_0, 66 (False, True, False, False): lines_error, 67 (False, True, False, True ): lines_overlap_opposite_direction2, 68 (False, True, True, False): lines_overlap_same_direction2, 69 (False, True, True, True ): lines_1_fully_included_in_0, 70 (True, False, False, False): lines_error, 71 (True, False, False, True ): lines_overlap_same_direction, 72 (True, False, True, False): lines_overlap_opposite_direction, 73 (True, False, True, True ): lines_1_fully_included_in_0, 74 (True, True, False, False): lines_0_fully_included_in_1, 75 (True, True, False, True ): lines_0_fully_included_in_1, 76 (True, True, True, False): lines_0_fully_included_in_1, 77 (True, True, True, True ): lines_0_fully_included_in_1 78 } 46 79 47 80 def intersection(line0, line1, rtol=1.0e-5, atol=1.0e-8): … … 55 88 Inputs: 56 89 line0, line1: Each defined by two end points as in: [[x0, y0], [x1, y1]] 57 A line can also be a 2x2 num ericarray with each row90 A line can also be a 2x2 numpy array with each row 58 91 corresponding to a point. 59 92 … … 62 95 status, value 63 96 64 where status is interpreted as follows97 where status and value is interpreted as follows 65 98 66 status == 0: no intersection with value set to None67 status == 1: One intersection point found and returned in value as [x,y]68 status == 2: Co inciding line segment found. Value taks the form [[x0,y0], [x1,y1]]69 status == 3: Lines would coincide but only if extended. Value set to None99 status == 0: no intersection, value set to None. 100 status == 1: intersection point found and returned in value as [x,y]. 101 status == 2: Collinear overlapping lines found. Value takes the form [[x0,y0], [x1,y1]]. 102 status == 3: Collinear non-overlapping lines. Value set to None. 70 103 status == 4: Lines are parallel with a fixed distance apart. Value set to None. 71 104 … … 88 121 89 122 if allclose(denom, 0.0, rtol=rtol, atol=atol): 90 # Lines are parallel - check if they coincide on a shared a segment 91 92 if allclose( [u0, u1], 0.0, rtol=rtol, atol=atol ): 93 # We now know that the lines if continued coincide 94 # The remaining check will establish if the finite lines share a segment 95 96 line0_starts_on_line1 = line0_ends_on_line1 =\ 97 line1_starts_on_line0 = line1_ends_on_line0 = False 98 99 if point_on_line([x0, y0], line1, rtol=rtol, atol=atol): 100 line0_starts_on_line1 = True 101 102 if point_on_line([x1, y1], line1, rtol=rtol, atol=atol): 103 line0_ends_on_line1 = True 104 105 if point_on_line([x2, y2], line0, rtol=rtol, atol=atol): 106 line1_starts_on_line0 = True 107 108 if point_on_line([x3, y3], line0, rtol=rtol, atol=atol): 109 line1_ends_on_line0 = True 110 111 if not(line0_starts_on_line1 or line0_ends_on_line1\ 112 or line1_starts_on_line0 or line1_ends_on_line0): 113 # Lines are parallel and would coincide if extended, but not as they are. 114 return 3, None 115 116 117 # One line fully included in the other. Use direction of included line 118 if line0_starts_on_line1 and line0_ends_on_line1: 119 # Shared segment is line0 fully included in line1 120 segment = array([[x0, y0], [x1, y1]]) 121 122 if line1_starts_on_line0 and line1_ends_on_line0: 123 # Shared segment is line1 fully included in line0 124 segment = array([[x2, y2], [x3, y3]]) 125 126 127 # Overlap with lines are oriented the same way 128 if line0_starts_on_line1 and line1_ends_on_line0: 129 # Shared segment from line0 start to line 1 end 130 segment = array([[x0, y0], [x3, y3]]) 131 132 if line1_starts_on_line0 and line0_ends_on_line1: 133 # Shared segment from line1 start to line 0 end 134 segment = array([[x2, y2], [x1, y1]]) 135 136 137 # Overlap in opposite directions - use direction of line0 138 if line0_starts_on_line1 and line1_starts_on_line0: 139 # Shared segment from line0 start to line 1 end 140 segment = array([[x0, y0], [x2, y2]]) 141 142 if line0_ends_on_line1 and line1_ends_on_line0: 143 # Shared segment from line0 start to line 1 end 144 segment = array([[x3, y3], [x1, y1]]) 145 146 147 return 2, segment 123 # Lines are parallel - check if they are collinear 124 if allclose([u0, u1], 0.0, rtol=rtol, atol=atol): 125 # We now know that the lines are collinear 126 state_tuple = (point_on_line([x0, y0], line1, rtol=rtol, atol=atol), 127 point_on_line([x1, y1], line1, rtol=rtol, atol=atol), 128 point_on_line([x2, y2], line0, rtol=rtol, atol=atol), 129 point_on_line([x3, y3], line0, rtol=rtol, atol=atol)) 130 131 return collinear_result[state_tuple]([x0,y0],[x1,y1],[x2,y2],[x3,y3]) 148 132 else: 149 # Lines are parallel but they don't coincide133 # Lines are parallel but aren't collinear 150 134 return 4, None #FIXME (Ole): Add distance here instead of None 151 152 135 else: 153 # Lines are not parallel or coinciding136 # Lines are not parallel, check if they intersect 154 137 u0 = u0/denom 155 138 u1 = u1/denom … … 165 148 if 0.0 <= u0 <= 1.0 and 0.0 <= u1 <= 1.0: 166 149 # We have intersection 167 168 150 return 1, array([x, y]) 169 151 else: -
anuga_core/source/anuga/utilities/test_polygon.py
r5940 r5942 650 650 assert status == 1 651 651 assert allclose(value, [1.0, 1.0]) 652 653 654 # This function is a helper function for the test_intersection_bug_20081110_?() 655 # set of tests. 652 653 654 # This function is a helper function for 655 # the test_intersection_bug_20081110_?() set of tests. 656 # This function tests all parallel line cases for 4 collinear points. 656 657 # This function should never be run directly by the unittest code. 657 658 def helper_test_parallel_intersection_code(self, P1, P2, P3, P4): … … 700 701 str(value)) 701 702 703 #---------------------------------------------------------------------- 704 702 705 # line0 fully within line1, same direction 703 706 # 0: ---->---- … … 748 751 self.failUnless(allclose(value, line0)) 749 752 753 #---------------------------------------------------------------------- 754 750 755 # line1 fully within line0, same direction 751 756 # 0: --------->----------- … … 796 801 self.failUnless(allclose(value, line1)) 797 802 803 #---------------------------------------------------------------------- 804 798 805 # line in same direction, partial overlap 799 806 # 0: ----->----- … … 844 851 self.failUnless(allclose(value, [line1[1],line0[1]])) 845 852 853 #---------------------------------------------------------------------- 854 846 855 # line in same direction, partial overlap 847 856 # 0: ------>------ … … 892 901 self.failUnless(allclose(value, [line0[0],line1[0]])) 893 902 894 895 def test_intersection_bug_20081110_1(self): 903 #---------------------------------------------------------------------- 904 905 # line in same direction, same left point, line1 longer 906 # 0: ----->------ 907 # 1: ------->-------- 908 # value should be line0: 909 # ----->------ 910 line0 = [P1,P3] 911 line1 = [P1,P4] 912 status, value = intersection(line0, line1) 913 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 914 (str(status), str(value))) 915 self.failUnless(allclose(value, line0)) 916 917 # line in same direction, same left point, line1 longer 918 # 0: -----<------ 919 # 1: -------<-------- 920 # value should be line0: 921 # -----<------ 922 line0 = [P3,P1] 923 line1 = [P4,P1] 924 status, value = intersection(line0, line1) 925 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 926 (str(status), str(value))) 927 self.failUnless(allclose(value, line0)) 928 929 # line in opposite direction, same left point, line1 longer 930 # 0: ----->------ 931 # 1: -------<-------- 932 # value should be line0: 933 # ----->------ 934 line0 = [P1,P3] 935 line1 = [P4,P1] 936 status, value = intersection(line0, line1) 937 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 938 (str(status), str(value))) 939 self.failUnless(allclose(value, line0)) 940 941 # line in opposite direction, same start point, line1 longer 942 # 0: -----<------ 943 # 1: ------->-------- 944 # value should be line0: 945 # -----<------ 946 line0 = [P3,P1] 947 line1 = [P1,P4] 948 status, value = intersection(line0, line1) 949 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 950 (str(status), str(value))) 951 self.failUnless(allclose(value, line0)) 952 953 #---------------------------------------------------------------------- 954 955 # line in same direction, same left point, same right point 956 # 0: ------->-------- 957 # 1: ------->-------- 958 # value should be line0 or line1: 959 # ------->-------- 960 line0 = [P1,P3] 961 line1 = [P1,P3] 962 status, value = intersection(line0, line1) 963 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 964 (str(status), str(value))) 965 self.failUnless(allclose(value, line0)) 966 967 # line in same direction, same left point, same right point 968 # 0: -------<-------- 969 # 1: -------<-------- 970 # value should be line0 (or line1): 971 # -------<-------- 972 line0 = [P3,P1] 973 line1 = [P3,P1] 974 status, value = intersection(line0, line1) 975 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 976 (str(status), str(value))) 977 self.failUnless(allclose(value, line0)) 978 979 # line in opposite direction, same left point, same right point 980 # 0: ------->-------- 981 # 1: -------<-------- 982 # value should be line0: 983 # ------->-------- 984 line0 = [P1,P3] 985 line1 = [P3,P1] 986 status, value = intersection(line0, line1) 987 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 988 (str(status), str(value))) 989 self.failUnless(allclose(value, line0)) 990 991 # line in opposite direction, same left point, same right point 992 # 0: -------<-------- 993 # 1: ------->-------- 994 # value should be line0: 995 # -------<-------- 996 line0 = [P3,P1] 997 line1 = [P1,P3] 998 status, value = intersection(line0, line1) 999 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 1000 (str(status), str(value))) 1001 self.failUnless(allclose(value, line0)) 1002 1003 #---------------------------------------------------------------------- 1004 1005 # line in same direction, same right point, line1 longer 1006 # 0: ----->------ 1007 # 1: ------->-------- 1008 # value should be line0: 1009 # ----->------ 1010 line0 = [P2,P4] 1011 line1 = [P1,P4] 1012 status, value = intersection(line0, line1) 1013 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 1014 (str(status), str(value))) 1015 self.failUnless(allclose(value, line0)) 1016 1017 # line in same direction, same right point, line1 longer 1018 # 0: -----<------ 1019 # 1: -------<-------- 1020 # value should be line0: 1021 # -----<------ 1022 line0 = [P4,P2] 1023 line1 = [P4,P1] 1024 status, value = intersection(line0, line1) 1025 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 1026 (str(status), str(value))) 1027 self.failUnless(allclose(value, line0)) 1028 1029 # line in opposite direction, same right point, line1 longer 1030 # 0: ----->------ 1031 # 1: -------<-------- 1032 # value should be line0: 1033 # ----->------ 1034 line0 = [P2,P4] 1035 line1 = [P4,P1] 1036 status, value = intersection(line0, line1) 1037 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 1038 (str(status), str(value))) 1039 self.failUnless(allclose(value, line0)) 1040 1041 # line in opposite direction, same right point, line1 longer 1042 # 0: -----<------ 1043 # 1: ------->-------- 1044 # value should be line0: 1045 # -----<------ 1046 line0 = [P4,P2] 1047 line1 = [P1,P4] 1048 status, value = intersection(line0, line1) 1049 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 1050 (str(status), str(value))) 1051 self.failUnless(allclose(value, line0)) 1052 1053 #---------------------------------------------------------------------- 1054 1055 # line in same direction, same left point, line0 longer 1056 # 0: ------->-------- 1057 # 1: ----->------ 1058 # value should be line1: 1059 # ----->------ 1060 line0 = [P1,P4] 1061 line1 = [P1,P3] 1062 status, value = intersection(line0, line1) 1063 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 1064 (str(status), str(value))) 1065 self.failUnless(allclose(value, line1)) 1066 1067 # line in same direction, same left point, line0 longer 1068 # 0: -------<-------- 1069 # 1: -----<------ 1070 # value should be line1: 1071 # -----<------ 1072 line0 = [P4,P1] 1073 line1 = [P3,P1] 1074 status, value = intersection(line0, line1) 1075 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 1076 (str(status), str(value))) 1077 self.failUnless(allclose(value, line1)) 1078 1079 # line in opposite direction, same left point, line0 longer 1080 # 0: ------->-------- 1081 # 1: -----<------ 1082 # value should be line1: 1083 # -----<------ 1084 line0 = [P1,P4] 1085 line1 = [P3,P1] 1086 status, value = intersection(line0, line1) 1087 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 1088 (str(status), str(value))) 1089 self.failUnless(allclose(value, line1)) 1090 1091 # line in opposite direction, same left point, line0 longer 1092 # 0: -------<-------- 1093 # 1: ----->------ 1094 # value should be line1: 1095 # ----->------ 1096 line0 = [P4,P1] 1097 line1 = [P1,P3] 1098 status, value = intersection(line0, line1) 1099 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 1100 (str(status), str(value))) 1101 self.failUnless(allclose(value, line1)) 1102 1103 #---------------------------------------------------------------------- 1104 1105 # line in same direction, same right point, line0 longer 1106 # 0: ------->-------- 1107 # 1: ----->------ 1108 # value should be line1: 1109 # ----->------ 1110 line0 = [P1,P4] 1111 line1 = [P2,P4] 1112 status, value = intersection(line0, line1) 1113 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 1114 (str(status), str(value))) 1115 self.failUnless(allclose(value, line1)) 1116 1117 # line in same direction, same right point, line0 longer 1118 # 0: -------<-------- 1119 # 1: -----<------ 1120 # value should be line1: 1121 # -----<------ 1122 line0 = [P4,P1] 1123 line1 = [P4,P2] 1124 status, value = intersection(line0, line1) 1125 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 1126 (str(status), str(value))) 1127 self.failUnless(allclose(value, line1)) 1128 1129 # line in opposite direction, same right point, line0 longer 1130 # 0: ------->-------- 1131 # 1: -----<------ 1132 # value should be line1: 1133 # -----<------ 1134 line0 = [P1,P4] 1135 line1 = [P4,P2] 1136 status, value = intersection(line0, line1) 1137 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 1138 (str(status), str(value))) 1139 self.failUnless(allclose(value, line1)) 1140 1141 # line in opposite direction, same right point, line0 longer 1142 # 0: -------<-------- 1143 # 1: ----->------ 1144 # value should be line1: 1145 # ----->------ 1146 line0 = [P4,P1] 1147 line1 = [P2,P4] 1148 status, value = intersection(line0, line1) 1149 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 1150 (str(status), str(value))) 1151 self.failUnless(allclose(value, line1)) 1152 1153 1154 def test_intersection_bug_20081110_TR(self): 896 1155 """test_intersection_bug_20081110(self) 897 1156 898 Run through all possible cases of parallel lines.1157 Test all cases in top-right quadrant 899 1158 """ 900 1159 901 # define 4 collinear points 1160 # define 4 collinear points in top-right quadrant 902 1161 # 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 1162 P1 = [1.0, 1.0] 1163 P2 = [2.0, 2.0] 1164 P3 = [3.0, 3.0] 1165 P4 = [4.0, 4.0] 1166 1167 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1168 P1 = [1.0, 1.0+1.0e-9] 908 1169 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 909 910 911 def test_intersection_bug_20081110_2(self): 1170 P1 = [1.0, 1.0] 1171 P2 = [2.0, 2.0+1.0e-9] 1172 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1173 P2 = [2.0, 2.0] 1174 P3 = [3.0, 3.0+1.0e-9] 1175 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1176 P3 = [3.0, 3.0] 1177 P4 = [4.0, 4.0+1.0e-9] 1178 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1179 1180 def test_intersection_bug_20081110_TL(self): 912 1181 """test_intersection_bug_20081110(self) 913 1182 914 Run through all possible cases of parallel lines.1183 Test all cases in top-left quadrant 915 1184 """ 916 1185 917 # define 4 *almost* collinear points1186 # define 4 collinear points in top-left quadrant 918 1187 # 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 1188 P1 = [-1.0, 1.0] 1189 P2 = [-2.0, 2.0] 1190 P3 = [-3.0, 3.0] 1191 P4 = [-4.0, 4.0] 1192 1193 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1194 P1 = [-1.0, 1.0+1.0e-9] 924 1195 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 925 926 927 def test_intersection_bug_20081110_3(self): 1196 P1 = [-1.0, 1.0] 1197 P2 = [-2.0, 2.0+1.0e-9] 1198 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1199 P2 = [-2.0, 2.0] 1200 P3 = [-3.0, 3.0+1.0e-9] 1201 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1202 P3 = [-3.0, 3.0] 1203 P4 = [-4.0, 4.0+1.0e-9] 1204 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1205 1206 def test_intersection_bug_20081110_BL(self): 928 1207 """test_intersection_bug_20081110(self) 929 1208 930 Run through all possible cases of parallel lines.1209 Test all cases in bottom-left quadrant 931 1210 """ 932 1211 933 # define 4 *almost* collinear points1212 # define 4 collinear points in bottom-left quadrant 934 1213 # 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 1214 P1 = [-1.0, -1.0] 1215 P2 = [-2.0, -2.0] 1216 P3 = [-3.0, -3.0] 1217 P4 = [-4.0, -4.0] 1218 1219 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1220 P1 = [-1.0, -1.0+1.0e-9] 940 1221 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 941 942 943 def test_intersection_bug_20081110_4(self): 1222 P1 = [-1.0, -1.0] 1223 P2 = [-2.0, -2.0+1.0e-9] 1224 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1225 P2 = [-2.0, -2.0] 1226 P3 = [-3.0, -3.0+1.0e-9] 1227 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1228 P3 = [-3.0, -3.0] 1229 P4 = [-4.0, -4.0+1.0e-9] 1230 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1231 1232 def test_intersection_bug_20081110_BR(self): 944 1233 """test_intersection_bug_20081110(self) 945 1234 946 Run through all possible cases of parallel lines.1235 Test all cases in bottom-right quadrant 947 1236 """ 948 1237 949 # define 4 *almost* collinear points1238 # define 4 collinear points in bottom-right quadrant 950 1239 # 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 1240 P1 = [1.0, -1.0] 1241 P2 = [2.0, -2.0] 1242 P3 = [3.0, -3.0] 1243 P4 = [4.0, -4.0] 1244 1245 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1246 P1 = [1.0, -1.0+1.0e-9] 956 1247 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 957 958 959 def test_intersection_bug_20081110_5(self): 1248 P1 = [1.0, -1.0] 1249 P2 = [2.0, -2.0+1.0e-9] 1250 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1251 P2 = [2.0, -2.0] 1252 P3 = [3.0, -3.0+1.0e-9] 1253 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1254 P3 = [3.0, -3.0] 1255 P4 = [4.0, -4.0+1.0e-9] 1256 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1257 1258 def test_intersection_bug_20081110_TR_TL(self): 960 1259 """test_intersection_bug_20081110(self) 961 1260 962 Run through all possible cases of parallel lines.1261 Test all cases in top-right & top-left quadrant 963 1262 """ 964 1263 965 # define 4 *almost* collinear points1264 # define 4 collinear points, 1 in TL, 3 in TR 966 1265 # 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 974 975 def test_intersection_bug_20081111(self): 976 """test_intersection_bug_20081111(self) 977 978 Case from Rajaraman that is failing still. 1266 P1 = [-3.0, 1.0] 1267 P2 = [ 1.0, 5.0] 1268 P3 = [ 2.0, 6.0] 1269 P4 = [ 3.0, 7.0] 1270 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1271 1272 # define 4 collinear points, 2 in TL, 2 in TR 1273 # P1---P2---P3---P4 1274 P1 = [-3.0, 1.0] 1275 P2 = [-2.0, 2.0] 1276 P3 = [ 2.0, 6.0] 1277 P4 = [ 3.0, 7.0] 1278 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1279 1280 # define 4 collinear points, 2 in TL, 1 in TR 1281 # P1---P2---P3---P4 1282 P1 = [-3.0, 1.0] 1283 P2 = [-2.0, 2.0] 1284 P3 = [-1.0, 3.0] 1285 P4 = [ 3.0, 7.0] 1286 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1287 1288 def test_intersection_bug_20081110_TR_BL(self): 1289 """test_intersection_bug_20081110(self) 1290 1291 Test all cases in top-right & bottom-left quadrant 979 1292 """ 980 1293 981 # define 4 collinear points 982 # 983 # Y 984 # ^ 985 # | x (2,2) 986 # | / 987 # | / 988 # | / 989 # | / 990 # | x (1,1) 991 # | / 992 # | / 993 # | / 994 # |/ 995 # x------------>X 996 997 line0 = [[2.0, 2.0],[0.0,0.0]] 998 line1 = [[1.0, 1.0],[0.0,0.0]] 999 1000 status, value = intersection(line0, line1) 1001 print 'status=%s, value=%s' % (str(status), str(value)) 1002 1003 self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' % 1004 (str(status), str(value))) 1005 self.failUnless(allclose(value, [line0[0],line1[1]])) 1294 # define 4 collinear points, 1 in BL, 3 in TR 1295 # P1---P2---P3---P4 1296 P1 = [-4.0, -3.0] 1297 P2 = [ 1.0, 2.0] 1298 P3 = [ 2.0, 3.0] 1299 P4 = [ 3.0, 4.0] 1300 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1301 1302 # define 4 collinear points, 2 in TL, 2 in TR 1303 # P1---P2---P3---P4 1304 P1 = [-4.0, -3.0] 1305 P2 = [-3.0, -2.0] 1306 P3 = [ 2.0, 3.0] 1307 P4 = [ 3.0, 4.0] 1308 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1309 1310 # define 4 collinear points, 3 in TL, 1 in TR 1311 # P1---P2---P3---P4 1312 P1 = [-4.0, -3.0] 1313 P2 = [-3.0, -2.0] 1314 P3 = [-2.0, -1.0] 1315 P4 = [ 3.0, 4.0] 1316 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1317 1318 def test_intersection_bug_20081110_TR_BR(self): 1319 """test_intersection_bug_20081110(self) 1320 1321 Test all cases in top-right & bottom-right quadrant 1322 """ 1323 1324 # define 4 collinear points, 1 in BR, 3 in TR 1325 # P1---P2---P3---P4 1326 P1 = [ 1.0, -3.0] 1327 P2 = [ 5.0, 1.0] 1328 P3 = [ 6.0, 2.0] 1329 P4 = [ 7.0, 3.0] 1330 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1331 1332 # define 4 collinear points, 2 in BR, 2 in TR 1333 # P1---P2---P3---P4 1334 P1 = [ 1.0, -3.0] 1335 P2 = [ 2.0, -2.0] 1336 P3 = [ 6.0, 2.0] 1337 P4 = [ 7.0, 3.0] 1338 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1339 1340 # define 4 collinear points, 3 in BR, 1 in TR 1341 # P1---P2---P3---P4 1342 P1 = [ 1.0, -3.0] 1343 P2 = [ 2.0, -2.0] 1344 P3 = [ 3.0, -1.0] 1345 P4 = [ 7.0, 3.0] 1346 self.helper_test_parallel_intersection_code(P1, P2, P3, P4) 1006 1347 1007 1348 … … 1344 1685 if __name__ == "__main__": 1345 1686 suite = unittest.makeSuite(Test_Polygon,'test') 1346 #suite = unittest.makeSuite(Test_Polygon,'test_inside_polygon_geo_ref')1687 # suite = unittest.makeSuite(Test_Polygon,'test_intersection_bug_20081111') 1347 1688 runner = unittest.TextTestRunner() 1348 1689 runner.run(suite)
Note: See TracChangeset
for help on using the changeset viewer.