-
Notifications
You must be signed in to change notification settings - Fork 2
/
Polygon.cpp
143 lines (117 loc) · 3.3 KB
/
Polygon.cpp
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
//
// Created by Ryan.Zurrin001 on 12/16/2021.
//
#include "Polygon.h"
#include "GeoUtils.h"
using namespace rez;
// Namespace classes and functions.
rez::Polygon::Polygon()
{
}
// Polygon class function
Polygon::Polygon(std::vector<Point3d> _point_list)
{
for (Point3d& _point : _point_list)
{
vertex_list.push_back(Vertex(_point));
}
const unsigned int size = vertex_list.size();
for (size_t i = 0; i < size; i++)
{
vertex_list[i].next = &vertex_list[(i + 1) % size];
if (i != 0)
vertex_list[i].prev = &vertex_list[i - 1];
else
vertex_list[i].prev = &vertex_list[size - 1];
}
}
void rez::Polygon::Insert(Point3d& _point)
{
vertex_list.push_back(Vertex(_point));
int size = vertex_list.size();
if (size > 1)
{
vertex_list[size - 1].next = vertex_list[size - 2].next;
vertex_list[size - 2].next = &vertex_list[size - 1];
vertex_list[size - 1].prev = &vertex_list[size - 2];
vertex_list[size - 1].next->prev = &vertex_list[size - 1];
}
}
// Polygon class function
std::vector<Point3d> Polygon::getPoints()
{
std::vector<Point3d> point_list;
for (const Vertex& vertex : vertex_list)
{
point_list.push_back(vertex.point);
}
return point_list;
}
rez::Polygon2dSimple::Polygon2dSimple()
{
}
rez::Polygon2dSimple::Polygon2dSimple(std::vector<Point2d> _point_list)
{
for (Point2d& _point : _point_list)
{
vertex_list.push_back(new Vertex2dSimple(_point));
}
const unsigned int size = vertex_list.size();
for (size_t i = 0; i < size; i++)
{
vertex_list[i]->next = vertex_list[(i + 1) % size];
if (i != 0)
vertex_list[i]->prev = vertex_list[i - 1];
else
vertex_list[i]->prev = vertex_list[size - 1];
}
}
rez::Polygon2dSimple::Polygon2dSimple(Vertex2dSimple* root_vertex)
{
vertex_list.push_back(root_vertex);
auto temp = root_vertex->next;
while (temp != root_vertex) {
vertex_list.push_back(temp);
temp = temp->next;
}
}
void rez::Polygon2dSimple::Insert(Point2d& _point)
{
vertex_list.push_back(new Vertex2dSimple(_point));
int size = vertex_list.size();
if (size > 1)
{
vertex_list[size - 1]->next = vertex_list[size - 2]->next;
vertex_list[size - 2]->next = vertex_list[size - 1];
vertex_list[size - 1]->prev = vertex_list[size - 2];
vertex_list[size - 1]->next->prev = vertex_list[size - 1];
}
}
void rez::Polygon2dSimple::RemoveVertex(Vertex2dSimple* _vert)
{
auto itr = std::find(vertex_list.begin(), vertex_list.end(), _vert);
if (itr != vertex_list.end())
{
vertex_list.erase(itr);
}
}
std::vector<Point2d> rez::Polygon2dSimple::getPoints()
{
std::vector<Point2d> point_list;
for (const Vertex2dSimple* vertex : vertex_list)
{
point_list.push_back(vertex->point);
}
return point_list;
}
int rez::Polygon2dSimple::size()
{
return vertex_list.size();
}
std::vector<Vertex2dSimple*> rez::Polygon2dSimple::getVertcies()
{
return this->vertex_list;
}
void rez::merge(Polygon& poly1, Polygon& poly2, Polygon& final_poly)
{
}