Diff
Not logged in

Differences From Artifact [bec880bc3280bac9]:

To Artifact [d88a2122970afda1]:


18 } 18 } 19 19 20 20 21 // intersection of two line segments. 21 // intersection of two line segments. 22 bool cross(CMP p1, CMP p2, CMP P1, CMP P2) { 22 bool cross(CMP p1, CMP p2, CMP P1, CMP P2) { 23 return ccw(p1,p2,P1)*ccw(p1,p2,P2)<=0 && ccw(P1,P2,p1)*ccw(P1,P2,p2)<=0; 23 return ccw(p1,p2,P1)*ccw(p1,p2,P2)<=0 && ccw(P1,P2,p1)*ccw(P1,P2,p2)<=0; 24 } 24 } > 25 > 26 > 27 // Intersection of two line segments, by p1+(*pos)(p2-p1) where 0<=*pos<=1. > 28 // only tested by local simple unittest. be careful. > 29 template<typename T> > 30 bool cross(const std::complex<T>& p1, const std::complex<T>& p2, > 31 const std::complex<T>& P1, const std::complex<T>& P2, T* pos) { > 32 if( ccw(p1,p2,P1)*ccw(p1,p2,P2)<=0 && ccw(P1,P2,p1)*ccw(P1,P2,p2)<=0 ) { > 33 if(outer_prod(p2-p1, P2-P1) == 0) > 34 return false; // parallel > 35 *pos = outer_prod(P1-p1, P2-P1) / outer_prod(p2-p1, P2-P1); > 36 return true; > 37 } > 38 return false; > 39 }