Ignore:
Timestamp:
Mar 9, 2006, 12:25:31 PM (19 years ago)
Author:
ole
Message:

First step towards moving util_ext.h out from pyvolution as per ticket:31

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/pyvolution/util.py

    r2314 r2508  
    4848
    4949from utilities.polygon import Polygon_function #No warning
     50from utilities.numerical_tools import gradient, gradient2, gradient_python #No warning
     51
    5052
    5153
     
    547549
    548550
    549 ####################################################################
    550 #Python versions of function that are also implemented in util_gateway.c
    551 #
    552 
    553 def gradient_python(x0, y0, x1, y1, x2, y2, q0, q1, q2):
    554     """
    555     """
    556 
    557     det = (y2-y0)*(x1-x0) - (y1-y0)*(x2-x0)
    558     a = (y2-y0)*(q1-q0) - (y1-y0)*(q2-q0)
    559     a /= det
    560 
    561     b = (x1-x0)*(q2-q0) - (x2-x0)*(q1-q0)
    562     b /= det
    563 
    564     return a, b
    565 
    566 
    567 def gradient2_python(x0, y0, x1, y1, q0, q1):
    568     """Compute radient based on two points and enforce zero gradient
    569     in the direction orthogonal to (x1-x0), (y1-y0)
    570     """
    571 
    572     #Old code
    573     #det = x0*y1 - x1*y0
    574     #if det != 0.0:
    575     #    a = (y1*q0 - y0*q1)/det
    576     #    b = (x0*q1 - x1*q0)/det
    577 
    578     #Correct code (ON)
    579     det = (x1-x0)**2 + (y1-y0)**2
    580     if det != 0.0:
    581         a = (x1-x0)*(q1-q0)/det
    582         b = (y1-y0)*(q1-q0)/det
    583        
    584     return a, b       
    585 
    586 
    587 ##############################################
    588 #Initialise module
    589 
    590 from utilities import compile
    591 if compile.can_use_C_extension('util_ext.c'):
    592     from util_ext import gradient, gradient2#, point_on_line
    593     #separate_points_by_polygon = separate_points_by_polygon_c
    594 else:
    595     gradient = gradient_python
    596     gradient2 = gradient2_python   
    597 
    598 
    599 if __name__ == "__main__":
    600     pass
    601 
    602 
    603 
    604 
     551
     552
     553
Note: See TracChangeset for help on using the changeset viewer.