p3he/lines.py

21 lines
770 B
Python

from numba import jit
@jit(cache=True)
def LineIntersection(rX1,rY1,rX2,rY2,rX3,rY3,rX4,rY4):
rX = ( (rX1*rY2-rY1*rX2)*(rX3-rX4)-(rX1-rX2)*(rX3*rY4-rY3*rX4) ) / ( (rX1-rX2)*(rY3-rY4)-(rY1-rY2)*(rX3-rX4) )
rY = ( (rX1*rY2-rY1*rX2)*(rY3-rY4)-(rY1-rY2)*(rX3*rY4-rY3*rX4) ) / ( (rX1-rX2)*(rY3-rY4)-(rY1-rY2)*(rX3-rX4) )
return (rX, rY)
@jit(cache=True)
def cLineIntersection(cA0, cA1, cB0, cB1):
rX, rY = LineIntersection(cA0.real, cA0.imag, cA1.real, cA1.imag, cB0.real, cB0.imag, cB1.real, cB1.imag)
return complex(rX, rY)
@jit(cache=True)
def Between(rA,rB,rN):
return (rA <= rN and rN <= rB) or (rB <= rN and rN <= rA)
@jit(cache=True)
def cBetween(cA,cB,cN):
return Between(cA.real,cB.real,cN.real) and Between(cA.imag,cB.imag,cN.imag)