Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dynamic
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MostafaMollaali
dynamic
Commits
efa7c635
Commit
efa7c635
authored
9 years ago
by
Tom Fischer
Browse files
Options
Downloads
Patches
Plain Diff
[GL] Fix mem leak in Polygon.
parent
9f35e628
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
GeoLib/Polygon.cpp
+24
-14
24 additions, 14 deletions
GeoLib/Polygon.cpp
with
24 additions
and
14 deletions
GeoLib/Polygon.cpp
+
24
−
14
View file @
efa7c635
...
@@ -28,13 +28,20 @@ Polygon::Polygon(const Polyline &ply, bool init) :
...
@@ -28,13 +28,20 @@ Polygon::Polygon(const Polyline &ply, bool init) :
{
{
if
(
init
)
if
(
init
)
initialise
();
initialise
();
_simple_polygon_list
.
push_back
(
this
);
}
}
Polygon
::
Polygon
(
Polygon
const
&
other
)
Polygon
::
Polygon
(
Polygon
const
&
other
)
:
Polyline
(
other
),
_aabb
(
other
.
_aabb
)
:
Polyline
(
other
),
_aabb
(
other
.
_aabb
)
{
{
for
(
auto
const
*
sub_polygon
:
other
.
_simple_polygon_list
)
{
_simple_polygon_list
.
push_back
(
this
);
_simple_polygon_list
.
emplace_back
(
new
Polygon
(
*
sub_polygon
));
auto
sub_polygon_it
(
other
.
_simple_polygon_list
.
begin
());
for
(
sub_polygon_it
++
;
// the first entry is the polygon itself, skip the
// entry
sub_polygon_it
!=
other
.
_simple_polygon_list
.
end
();
++
sub_polygon_it
)
{
_simple_polygon_list
.
emplace_back
(
new
Polygon
(
*
(
*
sub_polygon_it
)));
}
}
}
}
...
@@ -71,7 +78,7 @@ bool Polygon::isPntInPolygon (GeoLib::Point const & pnt) const
...
@@ -71,7 +78,7 @@ bool Polygon::isPntInPolygon (GeoLib::Point const & pnt) const
std
::
size_t
n_intersections
(
0
);
std
::
size_t
n_intersections
(
0
);
GeoLib
::
Point
s
;
GeoLib
::
Point
s
;
if
(
_simple_polygon_list
.
empty
()
)
{
if
(
_simple_polygon_list
.
size
()
==
1
)
{
const
std
::
size_t
n_nodes
(
getNumberOfPoints
()
-
1
);
const
std
::
size_t
n_nodes
(
getNumberOfPoints
()
-
1
);
for
(
std
::
size_t
k
(
0
);
k
<
n_nodes
;
k
++
)
{
for
(
std
::
size_t
k
(
0
);
k
<
n_nodes
;
k
++
)
{
if
(((
*
(
getPoint
(
k
)))[
1
]
<=
pnt
[
1
]
&&
pnt
[
1
]
<=
(
*
(
getPoint
(
k
+
1
)))[
1
])
||
if
(((
*
(
getPoint
(
k
)))[
1
]
<=
pnt
[
1
]
&&
pnt
[
1
]
<=
(
*
(
getPoint
(
k
+
1
)))[
1
])
||
...
@@ -94,8 +101,11 @@ bool Polygon::isPntInPolygon (GeoLib::Point const & pnt) const
...
@@ -94,8 +101,11 @@ bool Polygon::isPntInPolygon (GeoLib::Point const & pnt) const
if
(
n_intersections
%
2
==
1
)
if
(
n_intersections
%
2
==
1
)
return
true
;
return
true
;
}
else
{
}
else
{
for
(
std
::
list
<
Polygon
*>::
const_iterator
it
(
_simple_polygon_list
.
begin
());
for
(
std
::
list
<
Polygon
*>::
const_iterator
it
(
it
!=
_simple_polygon_list
.
end
();
++
it
)
{
_simple_polygon_list
.
begin
()
++
);
it
!=
_simple_polygon_list
.
end
();
++
it
)
{
if
((
*
it
)
->
isPntInPolygon
(
pnt
))
if
((
*
it
)
->
isPntInPolygon
(
pnt
))
return
true
;
return
true
;
}
}
...
@@ -217,7 +227,7 @@ bool Polygon::getNextIntersectionPointPolygonLine(
...
@@ -217,7 +227,7 @@ bool Polygon::getNextIntersectionPointPolygonLine(
GeoLib
::
LineSegment
const
&
seg
,
GeoLib
::
Point
&
intersection
,
GeoLib
::
LineSegment
const
&
seg
,
GeoLib
::
Point
&
intersection
,
std
::
size_t
&
seg_num
)
const
std
::
size_t
&
seg_num
)
const
{
{
if
(
_simple_polygon_list
.
empty
()
)
{
if
(
_simple_polygon_list
.
size
()
==
1
)
{
for
(
auto
seg_it
(
begin
()
+
seg_num
);
seg_it
!=
end
();
++
seg_it
)
{
for
(
auto
seg_it
(
begin
()
+
seg_num
);
seg_it
!=
end
();
++
seg_it
)
{
if
(
GeoLib
::
lineSegmentIntersect
(
*
seg_it
,
seg
,
intersection
))
{
if
(
GeoLib
::
lineSegmentIntersect
(
*
seg_it
,
seg
,
intersection
))
{
seg_num
=
seg_it
.
getSegmentNumber
();
seg_num
=
seg_it
.
getSegmentNumber
();
...
@@ -244,17 +254,11 @@ bool Polygon::getNextIntersectionPointPolygonLine(
...
@@ -244,17 +254,11 @@ bool Polygon::getNextIntersectionPointPolygonLine(
const
std
::
list
<
Polygon
*>&
Polygon
::
getListOfSimplePolygons
()
const
std
::
list
<
Polygon
*>&
Polygon
::
getListOfSimplePolygons
()
{
{
if
(
_simple_polygon_list
.
empty
())
_simple_polygon_list
.
push_back
(
this
);
return
_simple_polygon_list
;
return
_simple_polygon_list
;
}
}
void
Polygon
::
computeListOfSimplePolygons
()
void
Polygon
::
computeListOfSimplePolygons
()
{
{
if
(
!
_simple_polygon_list
.
empty
())
return
;
_simple_polygon_list
.
push_back
(
this
);
splitPolygonAtPoint
(
_simple_polygon_list
.
begin
());
splitPolygonAtPoint
(
_simple_polygon_list
.
begin
());
splitPolygonAtIntersection
(
_simple_polygon_list
.
begin
());
splitPolygonAtIntersection
(
_simple_polygon_list
.
begin
());
...
@@ -392,7 +396,10 @@ void Polygon::splitPolygonAtIntersection(
...
@@ -392,7 +396,10 @@ void Polygon::splitPolygonAtIntersection(
polyline1
.
addPoint
((
*
polygon_it
)
->
getPointID
(
k
));
polyline1
.
addPoint
((
*
polygon_it
)
->
getPointID
(
k
));
polyline1
.
addPoint
(
intersection_pnt_id
);
polyline1
.
addPoint
(
intersection_pnt_id
);
// remove original polyline and add two new polylines
// remove the polygon except the first
if
(
*
polygon_it
!=
this
)
delete
*
polygon_it
;
// erase polygon_it and add two new polylines
auto
polygon1_it
=
_simple_polygon_list
.
insert
(
auto
polygon1_it
=
_simple_polygon_list
.
insert
(
_simple_polygon_list
.
erase
(
polygon_it
),
new
GeoLib
::
Polygon
(
polyline1
));
_simple_polygon_list
.
erase
(
polygon_it
),
new
GeoLib
::
Polygon
(
polyline1
));
auto
polygon0_it
=
_simple_polygon_list
.
insert
(
auto
polygon0_it
=
_simple_polygon_list
.
insert
(
...
@@ -436,7 +443,10 @@ void Polygon::splitPolygonAtPoint (std::list<GeoLib::Polygon*>::iterator polygon
...
@@ -436,7 +443,10 @@ void Polygon::splitPolygonAtPoint (std::list<GeoLib::Polygon*>::iterator polygon
for
(
std
::
size_t
j
(
idx0
);
j
<=
idx1
;
j
++
)
for
(
std
::
size_t
j
(
idx0
);
j
<=
idx1
;
j
++
)
polyline1
.
addPoint
((
*
polygon_it
)
->
getPointID
(
j
));
polyline1
.
addPoint
((
*
polygon_it
)
->
getPointID
(
j
));
// remove original polygon and add two new polygons
// remove the polygon except the first
if
(
*
polygon_it
!=
this
)
delete
*
polygon_it
;
// erase polygon_it and add two new polygons
auto
polygon1_it
=
_simple_polygon_list
.
insert
(
auto
polygon1_it
=
_simple_polygon_list
.
insert
(
_simple_polygon_list
.
erase
(
polygon_it
),
new
Polygon
(
polyline1
));
_simple_polygon_list
.
erase
(
polygon_it
),
new
Polygon
(
polyline1
));
auto
polygon0_it
=
_simple_polygon_list
.
insert
(
auto
polygon0_it
=
_simple_polygon_list
.
insert
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment