#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;
|
}
|