wangzhengquan
2020-09-17 a4d90ebc6a31b9948ecee74189fe1423589e1f4c
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
45
46
47
48
49
50
#include "usg_common.h" 
#include "graph.h" 
using namespace std;
 
const double epsilon = numeric_limits<float>().epsilon();
const numeric_limits<double> DOUBLE;
const double MIN = DOUBLE.min();
const double MAX = DOUBLE.max();
 
 
Figure::Figure(){}
//Figure::Figure(const initializer_list<Edge> & _edges): edges(_edges) {}
Figure::Figure(const std::vector<Edge> & _edges): edges(_edges) {}
 
 
Figure & Figure::operator=(Figure && f)       // move assignment
{
    //std::cout << "move assignment operator called:\n";
    if (this == &f)
        return *this;
    edges = std::move(f.edges);
 
    return *this;
}
 
// bool Figure::contains(const Point& p) const
// {
//     auto c = 0;
//     for (auto e : edges) if (e.isCorss(p)) c++;
//     return c % 2 != 0;
// }
 
bool Figure::contains(const Point& p) const
{
    return true;
}
 
/**
 * 是否相交
*/
bool Edge::isCorss(const Point& p) const
{
    if (a.y > b.y) return Edge{ b, a }.isCorss(p);
    if (p.y == a.y || p.y == b.y) return isCorss({ p.x, p.y + epsilon });
    if (p.y > b.y || p.y < a.y || p.x > max(a.x, b.x)) return false;
    if (p.x < min(a.x, b.x)) return true;
    auto blue = abs(a.x - p.x) > MIN ? (p.y - a.y) / (p.x - a.x) : MAX;
    auto red = abs(a.x - b.x) > MIN ? (b.y - a.y) / (b.x - a.x) : MAX;
    return blue >= red;
}