Check-in [cb4efc4fe0]
Not logged in
Overview
SHA1 Hash:cb4efc4fe0e776d96a9a249fc66a04ebd4258474
Date: 2016-06-15 13:50:54
User: kinaba
Comment:ccw
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Modified lib/geo/ccw.cpp from [bec880bc3280bac9] to [d88a2122970afda1].

18 18 } 19 19 20 20 21 21 // intersection of two line segments. 22 22 bool cross(CMP p1, CMP p2, CMP P1, CMP P2) { 23 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 +}