Changeset 5932
- Timestamp:
- Nov 10, 2008, 5:21:16 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/polygon.py
r5897 r5932 18 18 19 19 20 def point_on_line(point, line, rtol= 0.0, atol=0.0):20 def point_on_line(point, line, rtol=1.0e-5, atol=1.0e-8): 21 21 """Determine whether a point is on a line segment 22 22 … … 31 31 """ 32 32 33 # FIXME(Ole): Perhaps make defaults as in allclose: rtol=1.0e-5, atol=1.0e-834 35 33 point = ensure_numeric(point) 36 34 line = ensure_numeric(line) … … 47 45 48 46 49 def intersection(line0, line1 ):47 def intersection(line0, line1, rtol=1.0e-5, atol=1.0e-8): 50 48 """Returns intersecting point between two line segments or None 51 49 (if parallel or no intersection is found). … … 89 87 u1 = (x2-x0)*(y1-y0) - (y2-y0)*(x1-x0) 90 88 91 if allclose(denom, 0.0 ):89 if allclose(denom, 0.0, rtol=rtol, atol=atol): 92 90 # Lines are parallel - check if they coincide on a shared a segment 93 91 94 if allclose( [u0, u1], 0.0 ):92 if allclose( [u0, u1], 0.0, rtol=rtol, atol=atol ): 95 93 # We now know that the lines if continued coincide 96 94 # The remaining check will establish if the finite lines share a segment … … 99 97 line1_starts_on_line0 = line1_ends_on_line0 = False 100 98 101 if point_on_line([x0, y0], line1 ):99 if point_on_line([x0, y0], line1, rtol=rtol, atol=atol): 102 100 line0_starts_on_line1 = True 103 101 104 if point_on_line([x1, y1], line1 ):102 if point_on_line([x1, y1], line1, rtol=rtol, atol=atol): 105 103 line0_ends_on_line1 = True 106 104 107 if point_on_line([x2, y2], line0 ):105 if point_on_line([x2, y2], line0, rtol=rtol, atol=atol): 108 106 line1_starts_on_line0 = True 109 107 110 if point_on_line([x3, y3], line0 ):108 if point_on_line([x3, y3], line0, rtol=rtol, atol=atol): 111 109 line1_ends_on_line0 = True 112 110 … … 161 159 162 160 # Sanity check - can be removed to speed up if needed 163 assert allclose(x, x2 + u1*(x3-x2) )164 assert allclose(y, y2 + u1*(y3-y2) )161 assert allclose(x, x2 + u1*(x3-x2), rtol=rtol, atol=atol) 162 assert allclose(y, y2 + u1*(y3-y2), rtol=rtol, atol=atol) 165 163 166 164 # Check if point found lies within given line segments
Note: See TracChangeset
for help on using the changeset viewer.