13 inline double is_left(
const VEC2& P0,
const VEC2& P1,
const VEC2& P2){
14 return ( (P1.v0() - P0.v0()) * (P2.v1() - P0.v1())
15 - (P2.v0() - P0.v0()) * (P1.v1() - P0.v1()) );
19 inline bool is_inside(
const VEC2& a_P,
const std::vector<VEC2>& a_V) {
31 size_t n = a_V.size()-1;
36 for (
size_t i=0; i<n; i++) {
37 if (a_V[i].v1() <= a_P.v1()) {
38 if (a_V[i+1].v1() > a_P.v1())
39 if (
is_left( a_V[i], a_V[i+1], a_P) > 0)
42 if (a_V[i+1].v1() <= a_P.v1())
43 if (
is_left( a_V[i], a_V[i+1], a_P) < 0)
48 return ((wn!=0)?
true:
false);
54 inline double is_left(
const std::pair<T,T>& P0,
const std::pair<T,T>& P1,
const std::pair<T,T>& P2){
55 return ( (P1.first - P0.first) * (P2.second - P0.second)
56 - (P2.first - P0.first) * (P1.second - P0.second) );
60 inline bool inside(
const std::pair<T,T>& a_P,
const std::vector< std::pair<T,T> >& a_V) {
72 size_t n = a_V.size()-1;
77 for (
size_t i=0; i<n; i++) {
78 if (a_V[i].second <= a_P.second) {
79 if (a_V[i+1].second > a_P.second)
80 if (
is_left( a_V[i], a_V[i+1], a_P) > 0)
83 if (a_V[i+1].second <= a_P.second)
84 if (
is_left( a_V[i], a_V[i+1], a_P) < 0)
89 return ((wn!=0)?
true:
false);
93 inline bool intersect(
const VEC2& P1,
const VEC2& Q1,
const VEC2& P2,
const VEC2& Q2,VEC2& a_out) {
108 typedef typename VEC2::elem_t T;
121 if(det==T())
return false;