-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPolygon.h
93 lines (69 loc) · 2.34 KB
/
Polygon.h
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
//
// Created by Ryan.Zurrin001 on 12/16/2021.
//
#ifndef PHYSICSFORMULA_POLYGON_H
#define PHYSICSFORMULA_POLYGON_H
#pragma once
#include <vector>
#include <algorithm>
#include "Point.h"
namespace rez {
struct Vertex
{
Point3d point;
Vertex* next = nullptr;
Vertex* prev = nullptr;
int id = 0;
friend class Polygon;
public:
explicit Vertex(Point3d& _point, Vertex* _next = nullptr, Vertex* _prev = nullptr) : point(_point), next(_next), prev(_prev) {}
};
struct Vertex2dSimple {
Point2d point;
Vertex2dSimple* next = nullptr;
Vertex2dSimple* prev = nullptr;
bool is_ear = false;
bool is_processed = false;
friend class Polygon2dSimple;
public:
explicit Vertex2dSimple(Point2d& _point, Vertex2dSimple* _next = nullptr, Vertex2dSimple* _prev = nullptr) : point(_point), next(_next), prev(_prev) {}
};
struct Edge2dSimple {
Point2d p1;
Point2d p2;
Point2d fp1;
Point2d fp2;
public:
Edge2dSimple() {}
Edge2dSimple(Point2d _p1, Point2d _p2) :p1(_p1), p2(_p2)
{}
};
class Polygon
{
std::vector<Vertex> vertex_list;
public:
Polygon();
// Construct the Polyhon with given point set
explicit Polygon(std::vector<Point3d> _point_list);
void Insert(Point3d&);
// Return the points list of underline vertices
std::vector<Point3d> getPoints();
};
class Polygon2dSimple {
std::vector<Vertex2dSimple*> vertex_list;
public:
Polygon2dSimple();
// Construct the Polyhon with given point set
explicit Polygon2dSimple(std::vector<Point2d> _point_list);
explicit Polygon2dSimple(Vertex2dSimple* root_vertex);
void Insert(Point2d&);
// If vert exist in the polygon, update the neighbour pointer accoidingly and remove the vertex.
void RemoveVertex(Vertex2dSimple* vert);
std::vector<Vertex2dSimple*> getVertcies();
// Return the points list of underline vertices
std::vector<Point2d> getPoints();
int size();
};
void merge(Polygon& poly1, Polygon& poly2, Polygon& final_poly);
}
#endif //PHYSICSFORMULA_POLYGON_H