-
Notifications
You must be signed in to change notification settings - Fork 0
/
pip200644.cpp
44 lines (36 loc) · 1.05 KB
/
pip200644.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <gmpxx.h>
#include "pip200644.h"
namespace N200644 {
template <typename InputIterator>
Polygon<InputIterator>::Polygon(InputIterator first, InputIterator last){
Point first_elem = *first;
for(first; first != last; ++first)
points.push_back(*first);
points.push_back(first_elem);
}
inline mpf_class checkSide( const Point q, const Point head, const Point tail){
return ( (head.x()-tail.x())*(q.y()-tail.y()) - (q.x()-tail.x())*(head.y()-tail.y()) );
}
template <typename InputIterator>
bool Polygon<InputIterator>::contains( const Point q ){
iterator v = begin();
iterator _end = end();
int wn = 0;
for( v; v != _end; ++v){
if ((*v).y() <= q.y()) {
if ((*(v+1)).y() > q.y())
if ( checkSide(q, *v, *(v+1)) > 0 )
++wn;
}
else {
if ((*(v+1)).y() <= q.y())
if ( checkSide(q, *v, *(v+1)) < 0 )
--wn;
}
}
return ( wn != 0 );
}
}