Skip to content

Commit

Permalink
Replace Vector push_back() vs emplace_back(); see issue AngusJohnson#175
Browse files Browse the repository at this point in the history
  • Loading branch information
aismann committed Aug 31, 2022
1 parent c222df1 commit 93f346f
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 70 deletions.
18 changes: 9 additions & 9 deletions CPP/Clipper2Lib/clipper.core.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ inline Path<T1> ScalePath(const Path<T2>& path, double scale)
result.reserve(path.size());
#ifdef USINGZ
for (const Point<T2>& pt : path)
result.push_back(Point<T1>(pt.x * scale, pt.y * scale, pt.z));
result.emplace_back(Point<T1>(pt.x * scale, pt.y * scale, pt.z));
#else
for (const Point<T2>& pt : path)
result.push_back(Point<T1>(pt.x * scale, pt.y * scale));
result.emplace_back(Point<T1>(pt.x * scale, pt.y * scale));
#endif
return result;
}
Expand All @@ -190,7 +190,7 @@ inline Paths<T1> ScalePaths(const Paths<T2>& paths, double scale)
Paths<T1> result;
result.reserve(paths.size());
for (const Path<T2>& path : paths)
result.push_back(ScalePath<T1, T2>(path, scale));
result.emplace_back(ScalePath<T1, T2>(path, scale));
return result;
}

Expand Down Expand Up @@ -255,13 +255,13 @@ inline Path<T> StripNearEqual(const Path<T>& path,
result.reserve(path.size());
typename Path<T>::const_iterator path_iter = path.cbegin();
Point<T> first_pt = *path_iter++, last_pt = first_pt;
result.push_back(first_pt);
result.emplace_back(first_pt);
for (; path_iter != path.cend(); ++path_iter)
{
if (!NearEqual(*path_iter, last_pt, max_dist_sqrd))
{
last_pt = *path_iter;
result.push_back(last_pt);
result.emplace_back(last_pt);
}
}
if (!is_closed_path) return result;
Expand All @@ -279,7 +279,7 @@ inline Paths<T> StripNearEqual(const Paths<T>& paths,
for (typename Paths<T>::const_iterator paths_citer = paths.cbegin();
paths_citer != paths.cend(); ++paths_citer)
{
result.push_back(StripNearEqual(*paths_citer, max_dist_sqrd, is_closed_path));
result.emplace_back(StripNearEqual(*paths_citer, max_dist_sqrd, is_closed_path));
}
return result;
}
Expand All @@ -292,13 +292,13 @@ inline Path<T> StripDuplicates(const Path<T>& path, bool is_closed_path)
result.reserve(path.size());
typename Path<T>::const_iterator path_iter = path.cbegin();
Point<T> first_pt = *path_iter++, last_pt = first_pt;
result.push_back(first_pt);
result.emplace_back(first_pt);
for (; path_iter != path.cend(); ++path_iter)
{
if (*path_iter != last_pt)
{
last_pt = *path_iter;
result.push_back(last_pt);
result.emplace_back(last_pt);
}
}
if (!is_closed_path) return result;
Expand All @@ -314,7 +314,7 @@ inline Paths<T> StripDuplicates(const Paths<T>& paths, bool is_closed_path)
for (typename Paths<T>::const_iterator paths_citer = paths.cbegin();
paths_citer != paths.cend(); ++paths_citer)
{
result.push_back(StripDuplicates(*paths_citer, is_closed_path));
result.emplace_back(StripDuplicates(*paths_citer, is_closed_path));
}
return result;
}
Expand Down
24 changes: 12 additions & 12 deletions CPP/Clipper2Lib/clipper.engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ namespace Clipper2Lib {
void ClipperBase::AddPath(const Path64& path, PathType polytype, bool is_open)
{
Paths64 tmp;
tmp.push_back(path);
tmp.emplace_back(path);
AddPaths(tmp, polytype, is_open);
}

Expand Down Expand Up @@ -791,7 +791,7 @@ namespace Clipper2Lib {
if ((VertexFlags::LocalMin & vert.flags) != VertexFlags::None) return;

vert.flags = (vert.flags | VertexFlags::LocalMin);
minima_list_.push_back(new LocalMinima(&vert, polytype, is_open));
minima_list_.emplace_back(new LocalMinima(&vert, polytype, is_open));
}

bool ClipperBase::IsContributingClosed(const Active & e) const
Expand Down Expand Up @@ -1270,7 +1270,7 @@ namespace Clipper2Lib {
{
OutRec* outrec = new OutRec();
outrec->idx = (unsigned)outrec_list_.size();
outrec_list_.push_back(outrec);
outrec_list_.emplace_back(outrec);
outrec->pts = nullptr;
outrec->polypath = nullptr;
e1.outrec = outrec;
Expand Down Expand Up @@ -1544,7 +1544,7 @@ namespace Clipper2Lib {
{
OutRec* newOutRec = new OutRec();
newOutRec->idx = outrec_list_.size();
outrec_list_.push_back(newOutRec);
outrec_list_.emplace_back(newOutRec);
newOutRec->owner = prevOp->outrec->owner;
newOutRec->polypath = nullptr;
splitOp->outrec = newOutRec;
Expand Down Expand Up @@ -1642,13 +1642,13 @@ namespace Clipper2Lib {
{
OutRec* newOr = new OutRec();
newOr->idx = outrec_list_.size();
outrec_list_.push_back(newOr);
outrec_list_.emplace_back(newOr);
newOr->polypath = nullptr;

if (using_polytree_)
{
if (!outrec.splits) outrec.splits = new OutRecList();
outrec.splits->push_back(newOr);
outrec.splits->emplace_back(newOr);
}

if (std::abs(area1) >= std::abs(area2))
Expand Down Expand Up @@ -1677,7 +1677,7 @@ namespace Clipper2Lib {
{
OutRec* outrec = new OutRec();
outrec->idx = outrec_list_.size();
outrec_list_.push_back(outrec);
outrec_list_.emplace_back(outrec);
outrec->owner = nullptr;
outrec->is_open = true;
outrec->pts = nullptr;
Expand Down Expand Up @@ -2147,7 +2147,7 @@ namespace Clipper2Lib {
pt.x = e2.curr_x;
}

intersect_nodes_.push_back(IntersectNode(&e1, &e2, pt));
intersect_nodes_.emplace_back(IntersectNode(&e1, &e2, pt));
}


Expand Down Expand Up @@ -2929,7 +2929,7 @@ namespace Clipper2Lib {

Joiner* j = new Joiner(op1, op2, nullptr);
j->idx = static_cast<int>(joiner_list_.size());
joiner_list_.push_back(j);
joiner_list_.emplace_back(j);
}


Expand Down Expand Up @@ -3315,14 +3315,14 @@ namespace Clipper2Lib {
lastPt = op->pt;
op2 = op->next;
}
path.push_back(lastPt);
path.emplace_back(lastPt);

while (op2 != op)
{
if (op2->pt != lastPt)
{
lastPt = op2->pt;
path.push_back(lastPt);
path.emplace_back(lastPt);
}
if (reverse)
op2 = op2->prev;
Expand Down Expand Up @@ -3451,7 +3451,7 @@ namespace Clipper2Lib {
{
Path64 path;
if (BuildPath(outrec->pts, ReverseSolution, true, path))
open_paths.push_back(path);
open_paths.emplace_back(path);
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion CPP/Clipper2Lib/clipper.engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ namespace Clipper2Lib {

PolyPath<T>* AddChild(const Path<T>& path)
{
childs_.push_back(new PolyPath<T>(this, path));
childs_.emplace_back(new PolyPath<T>(this, path));
return childs_.back();
}

Expand Down
30 changes: 15 additions & 15 deletions CPP/Clipper2Lib/clipper.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace Clipper2Lib
Path64 result;
result.reserve(path.size());
for (const Point64& pt : path)
result.push_back(Point64(pt.x + dx, pt.y + dy));
result.emplace_back(Point64(pt.x + dx, pt.y + dy));
return result;
}

Expand All @@ -167,7 +167,7 @@ namespace Clipper2Lib
PathD result;
result.reserve(path.size());
for (const PointD& pt : path)
result.push_back(PointD(pt.x + dx, pt.y + dy));
result.emplace_back(PointD(pt.x + dx, pt.y + dy));
return result;
}

Expand All @@ -176,7 +176,7 @@ namespace Clipper2Lib
Paths64 result;
result.reserve(paths.size());
for (const Path64& path : paths)
result.push_back(TranslatePath(path, dx, dy));
result.emplace_back(TranslatePath(path, dx, dy));
return result;
}

Expand All @@ -185,7 +185,7 @@ namespace Clipper2Lib
PathsD result;
result.reserve(paths.size());
for (const PathD& path : paths)
result.push_back(TranslatePath(path, dx, dy));
result.emplace_back(TranslatePath(path, dx, dy));
return result;
}

Expand Down Expand Up @@ -253,7 +253,7 @@ namespace Clipper2Lib
template <typename T>
inline void InternalPolyNodeToPaths(const PolyPath<T>& polypath, Paths<T>& paths)
{
paths.push_back(polypath.Polygon());
paths.emplace_back(polypath.Polygon());
for (auto child : polypath)
InternalPolyNodeToPaths(*child, paths);
}
Expand Down Expand Up @@ -394,7 +394,7 @@ namespace Clipper2Lib
if (!details::GetInt(s_iter, s.cend(), x)) break;
details::SkipSpacesWithOptionalComma(s_iter, s.cend());
if (!details::GetInt(s_iter, s.cend(), y)) break;
result.push_back(Point64(x, y));
result.emplace_back(Point64(x, y));
if (user_defined_skip)
details::SkipUserDefinedChars(s_iter, s.cend(), skip_chars);
else
Expand All @@ -414,7 +414,7 @@ namespace Clipper2Lib
if (!details::GetFloat(s_iter, s.cend(), x)) break;
details::SkipSpacesWithOptionalComma(s_iter, s.cend());
if (!details::GetFloat(s_iter, s.cend(), y)) break;
result.push_back(PointD(x, y));
result.emplace_back(PointD(x, y));
details::SkipSpacesWithOptionalComma(s_iter, s.cend());
}
return result;
Expand Down Expand Up @@ -443,20 +443,20 @@ namespace Clipper2Lib
}

prevIt = srcIt++;
dst.push_back(*prevIt);
dst.emplace_back(*prevIt);
for (; srcIt != stop; ++srcIt)
{
if (CrossProduct(*prevIt, *srcIt, *(srcIt + 1)))
{
prevIt = srcIt;
dst.push_back(*prevIt);
dst.emplace_back(*prevIt);
}
}

if (is_open_path)
dst.push_back(*srcIt);
dst.emplace_back(*srcIt);
else if (CrossProduct(*prevIt, *stop, dst[0]))
dst.push_back(*stop);
dst.emplace_back(*stop);
else
{
while (dst.size() > 2 &&
Expand Down Expand Up @@ -526,10 +526,10 @@ namespace Clipper2Lib
double dx = co, dy = si;
Path<T> result;
result.reserve(steps);
result.push_back(Point<T>(center.x + radiusX, static_cast<double>(center.y)));
result.emplace_back(Point<T>(center.x + radiusX, static_cast<double>(center.y)));
for (int i = 1; i < steps; ++i)
{
result.push_back(Point<T>(center.x + radiusX * dx, center.y + radiusY * dy));
result.emplace_back(Point<T>(center.x + radiusX * dx, center.y + radiusY * dy));
double x = dx * co - dy * si;
dy = dy * co + dx * si;
dx = x;
Expand Down Expand Up @@ -583,7 +583,7 @@ namespace Clipper2Lib
result.reserve(len);
for (typename Path<T>::size_type i = 0; i < len; ++i)
if (flags[i])
result.push_back(path[i]);
result.emplace_back(path[i]);
return result;
}

Expand All @@ -593,7 +593,7 @@ namespace Clipper2Lib
Paths<T> result;
result.reserve(paths.size());
for (const Path<T>& path : paths)
result.push_back(RamerDouglasPeucker<T>(path, epsilon));
result.emplace_back(RamerDouglasPeucker<T>(path, epsilon));
return result;
}

Expand Down
14 changes: 7 additions & 7 deletions CPP/Clipper2Lib/clipper.minkowski.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Clipper2Lib
Path64 path2(pattern.size());
std::transform(pattern.cbegin(), pattern.cend(),
path2.begin(), [pt](const Point64& pt2) {return pt + pt2; });
tmp.push_back(path2);
tmp.emplace_back(path2);
}
}
else
Expand All @@ -46,7 +46,7 @@ namespace Clipper2Lib
Path64 path2(pattern.size());
std::transform(pattern.cbegin(), pattern.cend(),
path2.begin(), [pt](const Point64& pt2) {return pt - pt2; });
tmp.push_back(path2);
tmp.emplace_back(path2);
}
}

Expand All @@ -60,14 +60,14 @@ namespace Clipper2Lib
Path64 quad;
quad.reserve(4);
{
quad.push_back(tmp[g][h]);
quad.push_back(tmp[i][h]);
quad.push_back(tmp[i][j]);
quad.push_back(tmp[g][j]);
quad.emplace_back(tmp[g][h]);
quad.emplace_back(tmp[i][h]);
quad.emplace_back(tmp[i][j]);
quad.emplace_back(tmp[g][j]);
};
if (!IsPositive(quad))
std::reverse(quad.begin(), quad.end());
result.push_back(quad);
result.emplace_back(quad);
h = j;
}
g = i;
Expand Down
Loading

0 comments on commit 93f346f

Please sign in to comment.