PLaSK library
Loading...
Searching...
No Matches
polygon.hpp
Go to the documentation of this file.
1
/*
2
* This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3
* Copyright (c) 2024 Lodz University of Technology
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, version 3.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*/
14
#ifndef PLASK_GEOMETRY_POLYGON_HPP
15
#define PLASK_GEOMETRY_POLYGON_HPP
16
21
#include "
leaf.hpp
"
22
23
namespace
plask
{
24
25
struct
PLASK_API
Polygon
:
public
GeometryObjectLeaf
<2> {
26
protected
:
27
std::vector<Vec<2>>
vertices
;
28
29
friend
shared_ptr<GeometryObject>
readPolygon
(
GeometryReader
& reader);
30
31
public
:
32
typedef
GeometryObjectLeaf<2>
BaseClass
;
33
35
typedef
typename
BaseClass::DVec
DVec
;
36
38
typedef
typename
BaseClass::Box
Box
;
39
40
static
const
char
*
NAME
;
41
42
std::string getTypeName()
const override
;
43
47
Polygon
() =
default
;
48
54
explicit
Polygon
(
const
std::vector<
Vec<2>
>& vertices,
const
shared_ptr<Material>
& material =
shared_ptr<Material>
());
55
61
explicit
Polygon
(std::vector<
Vec<2>
>&& vertices,
const
shared_ptr<Material>
&& material =
shared_ptr<Material>
());
62
68
explicit
Polygon
(std::initializer_list<
Vec<2>
> vertices,
const
shared_ptr<Material>
& material =
shared_ptr<Material>
());
69
75
explicit
Polygon
(
const
std::vector<
Vec<2>
>& vertices,
shared_ptr<MaterialsDB::MixedCompositionFactory>
materialTopBottom
);
76
82
explicit
Polygon
(std::vector<
Vec<2>
>&& vertices,
shared_ptr<MaterialsDB::MixedCompositionFactory>
materialTopBottom
);
83
89
explicit
Polygon
(std::initializer_list<
Vec<2>
> vertices,
shared_ptr<MaterialsDB::MixedCompositionFactory>
materialTopBottom
);
90
94
explicit
Polygon
(
const
Polygon
& src) :
BaseClass
(src), vertices(src.vertices) {}
95
100
const
std::vector<Vec<2>>&
getVertices
()
const
{
return
vertices; }
101
106
std::vector<Vec<2>>&
getVertices
() {
return
vertices; }
107
112
void
setVertices
(
const
std::vector<
Vec<2>
>& vertices) {
113
this->vertices = vertices;
114
this->fireChanged(
GeometryObject::Event::EVENT_RESIZE
);
115
}
116
121
void
setVertices
(std::vector<
Vec<2>
>&& vertices) {
122
this->vertices = std::move(vertices);
123
this->fireChanged(
GeometryObject::Event::EVENT_RESIZE
);
124
}
125
131
void
setVertex
(
unsigned
index,
const
Vec<2>
&
vertex
) {
132
vertices.at(index) =
vertex
;
133
this->fireChanged(
GeometryObject::Event::EVENT_RESIZE
);
134
}
135
141
void
insertVertex
(
unsigned
index,
const
Vec<2>
&
vertex
) {
142
vertices.insert(vertices.begin() + index,
vertex
);
143
this->fireChanged(
GeometryObject::Event::EVENT_RESIZE
);
144
}
145
150
void
addVertex
(
const
Vec<2>
&
vertex
) {
151
vertices.push_back(
vertex
);
152
this->fireChanged(
GeometryObject::Event::EVENT_RESIZE
);
153
}
154
159
void
removeVertex
(
unsigned
index) {
160
vertices.erase(vertices.begin() + index);
161
this->fireChanged(
GeometryObject::Event::EVENT_RESIZE
);
162
}
163
167
void
clearVertices
() {
168
vertices.clear();
169
this->fireChanged(
GeometryObject::Event::EVENT_RESIZE
);
170
}
171
176
unsigned
getVertexCount
()
const
{
return
vertices.size(); }
177
183
const
Vec<2>
&
getVertex
(
unsigned
index)
const
{
return
vertices.at(index); }
184
185
// /// Validate the polygon: check if the lines between vertices do not intersect.
186
// bool checkSegments() const;
187
188
void
validate()
const override
;
189
190
Box getBoundingBox()
const override
;
191
192
bool
contains(
const
DVec& p)
const override
;
193
194
shared_ptr<GeometryObject>
shallowCopy
()
const override
{
return
make_shared<Polygon>
(*
this
); }
195
196
void
addPointsAlongToSet(std::set<double>& points,
197
Primitive<3>::Direction
direction,
198
unsigned
max_steps,
199
double
min_step_size)
const override
;
200
201
void
addLineSegmentsToSet(std::set<
typename
GeometryObjectD<2>::LineSegment
>& segments,
202
unsigned
max_steps,
203
double
min_step_size)
const override
;
204
205
void
writeXMLAttr(
XMLWriter::Element
&
dest_xml_object
,
const
AxisNames
& axes)
const override
;
206
};
207
208
}
// namespace plask
209
210
#endif
plask
geometry
polygon.hpp
Generated by
1.9.8