#ifndef __USG_GRAPH_H__
|
#define __USG_GRAPH_H__
|
|
#include "usg_common.h"
|
|
struct Point {
|
//public:
|
double x;
|
double y;
|
|
//Point(const double _x =0, const double _y =0) : x(_x), y(_y) {}
|
};
|
|
//平面向量
|
struct Vector2
|
{
|
double x;
|
double y;
|
|
};
|
|
|
class Edge {
|
public:
|
const Point a, b;
|
/**
|
* 是否相交
|
*/
|
bool isCorss(const Point& p) const;
|
};
|
|
|
|
|
class Figure {
|
//const string name;
|
std::vector<Edge> edges;
|
|
public:
|
Figure();
|
//Figure(const std::initializer_list<Edge> & _edges);
|
Figure(const std::vector<Edge> & _edges);
|
Figure & operator=(Figure && f); // move assignment
|
bool contains(const Point& p) const;
|
|
};
|
|
|
|
|
// 返回两个向量夹角的cos值, cos小于0即两个向量的夹角大于90度
|
static inline double getVector2Angle(const Vector2 & a, const Vector2 & b) {
|
double doc_product = a.x * b.x + a.y * b.y;
|
double ma = sqrt(a.x * a.x + a.y * a.y);
|
double mb = sqrt(b.x * b.x + b.y * b.y);
|
double cos = doc_product / (ma * mb);
|
return cos;
|
}
|
|
// 计算a指向b的向量
|
static inline Vector2 getVecor2(const Point &a, const Point &b) {
|
return {b.x - a.x, b.y - a.y};
|
}
|
|
#endif
|