// polygon_offset.h
#ifndef POLYGON_OFFSET_H
#define POLYGON_OFFSET_H
#include <vector>
struct Point {
double x, y;
Point();
Point(double x, double y);
friend bool operator<(const Point& a, const Point& b);
friend bool operator==(const Point& a, const Point& other) ;
};
// 重载运算符(必须在头文件中声明,以便被所有包含它的编译单元看到)
Point operator+(const Point& a, const Point& b);
Point operator-(const Point& a, const Point& b);
Point operator*(const Point& a, double t);
Point operator*(double t, const Point& a); // 支持 t * Point
Point operator/(const Point& a, double t);
// 向量运算函数声明
double dot(const Point& a, const Point& b);
double cross(const Point& a, const Point& b);
double norm(const Point& a);
Point normalize(const Point& a);
Point normal(const Point& v);
bool isClockwise(const std::vector<Point>& poly);
struct Segment {
Point p1, p2;
int index;
Segment(Point a, Point b, int idx);
double getYAt(double x) const;
bool operator<(const Segment& other) const;
};
bool isSelfIntersectingRobust(const std::vector<Point>& polygon, double epsilon= 1e-10);
//bool isSelfIntersecting(const std::vector<Point>& polygon);
// 线段相交检测函数声明
bool segmentsIntersect(const Point& a, const Point& b, const Point& c, const Point& d);
// 注意:operator* 不支持 Point * Point(无意义)
std::vector<Point> miterOffsetPolygon(const std::vector<Point>& points, double offset_distance, double miter_limit=0.25);
std::vector<Point> miterOffsetPolygonRobust(const std::vector<Point>& points, double offset_distance, double miter_limit = 0.25);
#endif // POLYGON_OFFSET_H