yy1717
2024-02-28 27fc91fbe8f88b6885356e68828cfe1ce1db7601
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//
// Created by YY on 2019/4/30.
//
 
#ifndef GUI_GEOMETRY_H
#define GUI_GEOMETRY_H
 
#include <stdint.h>
#include <initializer_list>
#include <vector>
 
typedef enum
{
    GM_None,
    GM_Tangent,
    GM_Intersection,
    GM_Containment
} relation_t;
 
typedef struct {
    double X;
    double Y;
} PointF;
 
/*typedef struct {
    double X1;
    double Y1;
    double X2;
    double Y2;
} Line;*/
 
typedef struct {
    PointF p1;
    PointF p2;
} Line;
 
typedef struct {
    int num = 0;
    PointF *point = nullptr;
} Polygon;
 
typedef struct {
    PointF centre;
    double radius;
} Circle;
 
//#define MAKE_LINE(a, b, c)    { a.X1=b.X; a.Y1=b.Y; a.X2=c.X; a.Y2=c.Y; }
void MAKE_LINE(Line &a, PointF &b, PointF &c);
 
double toRadians(double degree);
double toDegree(double radians);
bool isEqual(double a, double b);
bool isEqual2(double a, double b);
 
class MakePolygon {
public:
    MakePolygon(std::initializer_list<PointF> points) {
        polygon.num = 0;
        if (points.size() > 0) {
         polygon.point = new PointF[points.size()];
         int n = 0;
         for (auto ptr: points) {
          polygon.point[n++] = ptr;
         }
         polygon.num = n;
        }
    }
    MakePolygon(int pre_num) {
        polygon.num = 0;
        polygon.point = new PointF[pre_num];
    }
 
    ~MakePolygon() {
        if (polygon.point != nullptr) {
            delete []polygon.point;
        }
    }
 
    void AddPoints(std::initializer_list<PointF> points) {
        if (polygon.point != nullptr) {
            delete []polygon.point;
        }
        polygon.num = 0;
        if (points.size() > 0) {
            int n = 0;
            polygon.point = new PointF[points.size()];
            for (auto p: points) {
                polygon.point[n++] = p;
            }
            polygon.num = n;
        }
    }
 
    void AddPoint(PointF &point) {
        polygon.point[polygon.num] = point;
        polygon.num++;
    }
 
    Polygon *GetPolygon(void) {
        return &polygon;
    }
 
private:
    Polygon polygon;
};
 
//void MakePolygon(Polygon *polygon, std::initializer_list<PointF> point_set);
void CleanPolygon(Polygon *polygon);
void MakeHidePoint(PointF *point, const PointF *bp, const Line *bl);
 
relation_t IntersectionOf(const Polygon *polygon1, const Polygon *polygon2);
relation_t IntersectionOf(Line line, const Polygon *polygon);
relation_t IntersectionOf(PointF point, const Polygon *polygon);
relation_t IntersectionOf(PointF point, Line line);
relation_t IntersectionOf(Line line1, Line line2);
double DistanceOf(PointF point1, PointF point2);
double DistanceOf(PointF point, Line line);
double YawOf(PointF p1, PointF p2);
double YawOf(Line &line);
double AngleOf(PointF p1, PointF p2, PointF p3);
double AngleOfTowLine(Line base, Line dest);
double DeltaYaw(double yaw1, double yaw2);
double CalculateAngle(Line base, Line dest);
PointF rotatePoint(PointF oldPoint, PointF centre, double degree);
PointF centerOfTwoPoint(PointF p1, PointF p2);
bool InsidePolygon(const Polygon *t1, const Polygon *t2);
bool PartInsidePolygon(const Polygon *t1, const Polygon *t2);
bool OutsidePolygon(const Polygon *t1, const Polygon *t2);
 
typedef enum {
    REL_POS_ON,
    REL_POS_LEFT,
    REL_POS_RIGHT,
    REL_POS_FRONT,
    REL_POS_REAR
} relational_position_t;
 
relational_position_t IntersectionOfLine(PointF p1, PointF p2, PointF p3);
relational_position_t IntersectionOfLine(PointF p, Line line);
PointF GetVerticalPoint(PointF p1, PointF p2, PointF p3);
bool VerticalPointOnLine(PointF point, Line line);
bool VerticalPointOnLine(PointF point, Line line, PointF &vp);
PointF Calc3Point(PointF p1, PointF p2, double length, char dir);
PointF PointExtend(PointF ori, double length, double yaw);
bool IsSamePoint(PointF p1, PointF p2);
double AvgYaw(std::vector<double> &angles);
bool Calc3PointCircle(PointF p1, PointF p2, PointF p3, Circle &circle);
 
#endif //GUI_GEOMETRY_H