Changeset 5932


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

Make line intersection function accept rtol/atol values, and pass them through to all subsequent comparisons.

File:
1 edited

Legend:

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

    r5897 r5932  
    1818
    1919
    20 def point_on_line(point, line, rtol=0.0, atol=0.0):
     20def point_on_line(point, line, rtol=1.0e-5, atol=1.0e-8):
    2121    """Determine whether a point is on a line segment
    2222
     
    3131    """
    3232
    33     # FIXME(Ole): Perhaps make defaults as in allclose: rtol=1.0e-5, atol=1.0e-8
    34 
    3533    point = ensure_numeric(point)
    3634    line = ensure_numeric(line)
     
    4745
    4846
    49 def intersection(line0, line1):
     47def intersection(line0, line1, rtol=1.0e-5, atol=1.0e-8):
    5048    """Returns intersecting point between two line segments or None
    5149    (if parallel or no intersection is found).
     
    8987    u1 = (x2-x0)*(y1-y0) - (y2-y0)*(x1-x0)
    9088       
    91     if allclose(denom, 0.0):
     89    if allclose(denom, 0.0, rtol=rtol, atol=atol):
    9290        # Lines are parallel - check if they coincide on a shared a segment
    9391
    94         if allclose( [u0, u1], 0.0 ):
     92        if allclose( [u0, u1], 0.0, rtol=rtol, atol=atol ):
    9593            # We now know that the lines if continued coincide
    9694            # The remaining check will establish if the finite lines share a segment
     
    9997            line1_starts_on_line0 = line1_ends_on_line0 = False
    10098               
    101             if point_on_line([x0, y0], line1):
     99            if point_on_line([x0, y0], line1, rtol=rtol, atol=atol):
    102100                line0_starts_on_line1 = True
    103101
    104             if point_on_line([x1, y1], line1):
     102            if point_on_line([x1, y1], line1, rtol=rtol, atol=atol):
    105103                line0_ends_on_line1 = True
    106104 
    107             if point_on_line([x2, y2], line0):
     105            if point_on_line([x2, y2], line0, rtol=rtol, atol=atol):
    108106                line1_starts_on_line0 = True
    109107
    110             if point_on_line([x3, y3], line0):
     108            if point_on_line([x3, y3], line0, rtol=rtol, atol=atol):
    111109                line1_ends_on_line0 = True                               
    112110
     
    161159
    162160        # 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)       
    165163
    166164        # Check if point found lies within given line segments
Note: See TracChangeset for help on using the changeset viewer.