use emplace_back instead of push_back where justified

This commit is contained in:
asapelkin
2019-10-25 00:57:12 +03:00
committed by wmayer
parent 079808b816
commit e951094af9
67 changed files with 239 additions and 241 deletions

View File

@@ -470,14 +470,14 @@ bool Line2CircleIntersect(const IntPoint &c, double radius, const IntPoint &p1,
if (clamp)
{
if (t1 >= 0.0 && t1 <= 1.0)
result.push_back(DoublePoint(p1.X + t1 * dx, p1.Y + t1 * dy));
result.emplace_back(p1.X + t1 * dx, p1.Y + t1 * dy);
if (t2 >= 0.0 && t2 <= 1.0)
result.push_back(DoublePoint(p1.X + t2 * dx, p1.Y + t2 * dy));
result.emplace_back(p1.X + t2 * dx, p1.Y + t2 * dy);
}
else
{
result.push_back(DoublePoint(p1.X + t2 * dx, p1.Y + t2 * dy));
result.push_back(DoublePoint(p1.X + t2 * dx, p1.Y + t2 * dy));
result.emplace_back(p1.X + t2 * dx, p1.Y + t2 * dy);
result.emplace_back(p1.X + t2 * dx, p1.Y + t2 * dy);
}
return result.size() > 0;
}
@@ -617,7 +617,7 @@ void SmoothPaths(Paths &paths, double stepSize, long pointCount, long iterations
{
if (points.empty())
{
points.push_back(pair<size_t /*path index*/, IntPoint>(i, pt));
points.emplace_back(i, pt);
continue;
}
const auto back=points.back();
@@ -629,7 +629,7 @@ void SmoothPaths(Paths &paths, double stepSize, long pointCount, long iterations
if (l < 0.5*stepScaled )
{
if(points.size()>1) points.pop_back();
points.push_back(pair<size_t /*path index*/, IntPoint>(i, pt));
points.emplace_back(i, pt);
continue;
}
size_t lastPathIndex = back.first;
@@ -649,9 +649,9 @@ void SmoothPaths(Paths &paths, double stepSize, long pointCount, long iterations
if(idx==0 && DistanceSqrd(back.second,ptx)<scale && points.size()>1) points.pop_back();
if (p < 0.5)
points.push_back(pair<size_t /*path index*/, IntPoint>(lastPathIndex, ptx));
points.emplace_back(lastPathIndex, ptx);
else
points.push_back(pair<size_t /*path index*/, IntPoint>(i, ptx));
points.emplace_back(i, ptx);
}
}
}
@@ -2137,7 +2137,7 @@ bool Adaptive2d::IsAllowedToCutTrough(const IntPoint &p1, const IntPoint &p2, Cl
bool Adaptive2d::ResolveLinkPath(const IntPoint &startPoint, const IntPoint &endPoint, ClearedArea &clearedArea, Path &output)
{
vector<pair<IntPoint, IntPoint>> queue;
queue.push_back(pair<IntPoint, IntPoint>(startPoint, endPoint));
queue.emplace_back(startPoint, endPoint);
Path checkPath;
double totalLength = 0;
double directDistance = sqrt(DistanceSqrd(startPoint, endPoint));
@@ -2262,8 +2262,8 @@ bool Adaptive2d::ResolveLinkPath(const IntPoint &startPoint, const IntPoint &end
checkPath.push_back(checkPoint1);
if (IsClearPath(checkPath, clearedArea, clearance + 1))
{ // check if point clear
queue.push_back(pair<IntPoint, IntPoint>(pointPair.first, checkPoint1));
queue.push_back(pair<IntPoint, IntPoint>(checkPoint1, pointPair.second));
queue.emplace_back(pointPair.first, checkPoint1);
queue.emplace_back(checkPoint1, pointPair.second);
break;
}
else
@@ -2273,8 +2273,8 @@ bool Adaptive2d::ResolveLinkPath(const IntPoint &startPoint, const IntPoint &end
checkPath.push_back(checkPoint2);
if (IsClearPath(checkPath, clearedArea, clearance + 1))
{
queue.push_back(pair<IntPoint, IntPoint>(pointPair.first, checkPoint2));
queue.push_back(pair<IntPoint, IntPoint>(checkPoint2, pointPair.second));
queue.emplace_back(pointPair.first, checkPoint2);
queue.emplace_back(checkPoint2, pointPair.second);
break;
}
}
@@ -2483,7 +2483,7 @@ void Adaptive2d::AppendToolPath(TPaths &progressPaths, AdaptiveOutput &output,
linkPath1.first = MotionType::mtCutting;
for (const auto &pt : leadOutPath)
{
linkPath1.second.push_back(DPoint(double(pt.X) / scaleFactor, double(pt.Y) / scaleFactor));
linkPath1.second.emplace_back(double(pt.X) / scaleFactor, double(pt.Y) / scaleFactor);
}
output.AdaptivePaths.push_back(linkPath1);
@@ -2492,7 +2492,7 @@ void Adaptive2d::AppendToolPath(TPaths &progressPaths, AdaptiveOutput &output,
linkPath2.first = linkType;
for (const auto &pt : linkPath)
{
linkPath2.second.push_back(DPoint(double(pt.X) / scaleFactor, double(pt.Y) / scaleFactor));
linkPath2.second.emplace_back(double(pt.X) / scaleFactor, double(pt.Y) / scaleFactor);
}
output.AdaptivePaths.push_back(linkPath2);
@@ -2501,7 +2501,7 @@ void Adaptive2d::AppendToolPath(TPaths &progressPaths, AdaptiveOutput &output,
linkPath3.first = MotionType::mtCutting;
for (const auto &pt : leadInPath)
{
linkPath3.second.push_back(DPoint(double(pt.X) / scaleFactor, double(pt.Y) / scaleFactor));
linkPath3.second.emplace_back(double(pt.X) / scaleFactor, double(pt.Y) / scaleFactor);
}
output.AdaptivePaths.push_back(linkPath3);
@@ -2527,8 +2527,8 @@ void Adaptive2d::AppendToolPath(TPaths &progressPaths, AdaptiveOutput &output,
TPath linkPath;
linkPath.first = mt;
linkPath.second.push_back(DPoint(double(startPoint.X) / scaleFactor, double(startPoint.Y) / scaleFactor));
linkPath.second.push_back(DPoint(double(endPoint.X) / scaleFactor, double(endPoint.Y) / scaleFactor));
linkPath.second.emplace_back(double(startPoint.X) / scaleFactor, double(startPoint.Y) / scaleFactor);
linkPath.second.emplace_back(double(endPoint.X) / scaleFactor, double(endPoint.Y) / scaleFactor);
output.AdaptivePaths.push_back(linkPath);
}
}
@@ -2580,8 +2580,8 @@ void Adaptive2d::AddPathsToProgress(TPaths &progressPaths, Paths paths, MotionTy
progressPaths.push_back(TPath());
progressPaths.back().first = mt;
for (const auto pt : pth)
progressPaths.back().second.push_back(DPoint(double(pt.X) / scaleFactor, double(pt.Y) / scaleFactor));
progressPaths.back().second.push_back(DPoint(double(pth.front().X) / scaleFactor, double(pth.front().Y) / scaleFactor));
progressPaths.back().second.emplace_back(double(pt.X) / scaleFactor, double(pt.Y) / scaleFactor);
progressPaths.back().second.emplace_back(double(pth.front().X) / scaleFactor, double(pth.front().Y) / scaleFactor);
}
}
}
@@ -2593,7 +2593,7 @@ void Adaptive2d::AddPathToProgress(TPaths &progressPaths, const Path pth, Motion
progressPaths.push_back(TPath());
progressPaths.back().first = mt;
for (const auto pt : pth)
progressPaths.back().second.push_back(DPoint(double(pt.X) / scaleFactor, double(pt.Y) / scaleFactor));
progressPaths.back().second.emplace_back(double(pt.X) / scaleFactor, double(pt.Y) / scaleFactor);
}
}
@@ -2922,7 +2922,7 @@ void Adaptive2d::ProcessPolyNode(Paths boundPaths, Paths toolBoundPaths)
// append to progress info paths
if (progressPaths.size() == 0)
progressPaths.push_back(TPath());
progressPaths.back().second.push_back(DPoint(double(newToolPos.X) / scaleFactor, double(newToolPos.Y) / scaleFactor));
progressPaths.back().second.emplace_back(double(newToolPos.X) / scaleFactor, double(newToolPos.Y) / scaleFactor);
// append gyro
gyro.push_back(newToolDir);
@@ -3069,7 +3069,7 @@ void Adaptive2d::ProcessPolyNode(Paths boundPaths, Paths toolBoundPaths)
// show in progress cb
for (auto &pt : finShiftedPath)
{
progressPaths.back().second.push_back(DPoint(double(pt.X) / scaleFactor, double(pt.Y) / scaleFactor));
progressPaths.back().second.emplace_back(double(pt.X) / scaleFactor, double(pt.Y) / scaleFactor);
}
if (!finShiftedPath.empty())

View File

@@ -392,7 +392,7 @@ static void make_zig_curve(const CCurve& input_curve, double y0, double y)
}
if(zig_finished)
zigzag_list_for_zigs.push_back(ZigZag(zig, zag));
zigzag_list_for_zigs.emplace_back(zig, zag);
}
void make_zig(const CArea &a, double y0, double y)
@@ -534,11 +534,11 @@ static void zigzag(const CArea &input_a)
Point p2(x1, y);
Point p3(x1, y0);
CCurve c;
c.m_vertices.push_back(CVertex(0, p0, null_point, 0));
c.m_vertices.push_back(CVertex(0, p1, null_point, 0));
c.m_vertices.push_back(CVertex(0, p2, null_point, 1));
c.m_vertices.push_back(CVertex(0, p3, null_point, 0));
c.m_vertices.push_back(CVertex(0, p0, null_point, 1));
c.m_vertices.emplace_back(0, p0, null_point, 0);
c.m_vertices.emplace_back(0, p1, null_point, 0);
c.m_vertices.emplace_back(0, p2, null_point, 1);
c.m_vertices.emplace_back(0, p3, null_point, 0);
c.m_vertices.emplace_back(0, p0, null_point, 1);
CArea a2;
a2.m_curves.push_back(c);
a2.Intersect(a);
@@ -635,7 +635,7 @@ void CArea::Split(std::list<CArea> &m_areas)const
for(std::list<CCurve>::const_iterator It = m_curves.begin(); It != m_curves.end(); It++)
{
const CCurve& curve = *It;
m_areas.push_back(CArea());
m_areas.emplace_back();
m_areas.back().m_curves.push_back(curve);
}
}
@@ -656,7 +656,7 @@ void CArea::Split(std::list<CArea> &m_areas)const
}
else
{
m_areas.push_back(CArea());
m_areas.emplace_back();
m_areas.back().m_curves.push_back(curve);
}
}
@@ -725,11 +725,11 @@ bool IsInside(const Point& p, const CArea& a)
{
CArea a2;
CCurve c;
c.m_vertices.push_back(CVertex(Point(p.x - 0.01, p.y - 0.01)));
c.m_vertices.push_back(CVertex(Point(p.x + 0.01, p.y - 0.01)));
c.m_vertices.push_back(CVertex(Point(p.x + 0.01, p.y + 0.01)));
c.m_vertices.push_back(CVertex(Point(p.x - 0.01, p.y + 0.01)));
c.m_vertices.push_back(CVertex(Point(p.x - 0.01, p.y - 0.01)));
c.m_vertices.emplace_back(Point(p.x - 0.01, p.y - 0.01));
c.m_vertices.emplace_back(Point(p.x + 0.01, p.y - 0.01));
c.m_vertices.emplace_back(Point(p.x + 0.01, p.y + 0.01));
c.m_vertices.emplace_back(Point(p.x - 0.01, p.y + 0.01));
c.m_vertices.emplace_back(Point(p.x - 0.01, p.y - 0.01));
a2.m_curves.push_back(c);
a2.Intersect(a);
if(fabs(a2.GetArea()) < 0.0004)return false;

View File

@@ -374,7 +374,7 @@ static void SetFromResult( CArea& area, TPolyPolygon& pp, bool reverse=true, boo
{
TPolygon& p = pp[i];
area.m_curves.push_back(CCurve());
area.m_curves.emplace_back();
CCurve &curve = area.m_curves.back();
SetFromResult(curve, p, reverse, is_closed);
}

View File

@@ -13,7 +13,7 @@ void AreaDxfRead::StartCurveIfNecessary(const double* s)
if((m_area->m_curves.size() == 0) || (m_area->m_curves.back().m_vertices.size() == 0) || (m_area->m_curves.back().m_vertices.back().m_p != ps))
{
// start a new curve
m_area->m_curves.push_back(CCurve());
m_area->m_curves.emplace_back();
m_area->m_curves.back().m_vertices.push_back(ps);
}
}
@@ -27,5 +27,5 @@ void AreaDxfRead::OnReadLine(const double* s, const double* e)
void AreaDxfRead::OnReadArc(const double* s, const double* e, const double* c, bool dir)
{
StartCurveIfNecessary(s);
m_area->m_curves.back().m_vertices.push_back(CVertex(dir?1:0, Point(e), Point(c)));
m_area->m_curves.back().m_vertices.emplace_back(dir?1:0, Point(e), Point(c));
}

View File

@@ -135,7 +135,7 @@ void GetCurveItem::GetCurve(CCurve& output)
std::list<CVertex>::iterator VIt = output.m_vertices.insert(this->EndIt, CVertex(inner.point_on_parent));
//inner.GetCurve(output);
GetCurveItem::to_do_list.push_back(GetCurveItem(&inner, VIt));
GetCurveItem::to_do_list.emplace_back(&inner, VIt);
}
if(back().m_p != vertex.m_p)output.m_vertices.insert(this->EndIt, vertex);
@@ -157,7 +157,7 @@ void GetCurveItem::GetCurve(CCurve& output)
std::list<CVertex>::iterator VIt = output.m_vertices.insert(this->EndIt, CVertex(inner.point_on_parent));
//inner.GetCurve(output);
GetCurveItem::to_do_list.push_back(GetCurveItem(&inner, VIt));
GetCurveItem::to_do_list.emplace_back(&inner, VIt);
}
}
@@ -243,7 +243,7 @@ void CurveTree::MakeOffsets2()
for(std::list<IslandAndOffset*>::const_iterator It2 = island_and_offset->touching_offsets.begin(); It2 != island_and_offset->touching_offsets.end(); It2++)
{
const IslandAndOffset* touching = *It2;
touching_list.push_back(IslandAndOffsetLink(touching, inners.back()));
touching_list.emplace_back(touching, inners.back());
added.insert(touching);
}
@@ -276,7 +276,7 @@ void CurveTree::MakeOffsets2()
{
if(added.find(*It2)==added.end() && ((*It2) != island_and_offset))
{
touching_list.push_back(IslandAndOffsetLink(*It2, touching.add_to->inners.back()));
touching_list.emplace_back(*It2, touching.add_to->inners.back());
added.insert(*It2);
}
}
@@ -501,10 +501,10 @@ void CArea::MakeOnePocketCurve(std::list<CCurve> &curve_list, const CAreaPocketP
if(CArea::m_please_abort)return;
CArea::m_processing_done = CArea::m_after_MakeOffsets_length;
curve_list.push_back(CCurve());
curve_list.emplace_back();
CCurve& output = curve_list.back();
GetCurveItem::to_do_list.push_back(GetCurveItem(&top_level, output.m_vertices.end()));
GetCurveItem::to_do_list.emplace_back(&top_level, output.m_vertices.end());
while(GetCurveItem::to_do_list.size() > 0)
{

View File

@@ -161,11 +161,11 @@ void CCurve::AddArcOrLines(bool check_for_arc, std::list<CVertex> &new_vertices,
{
if(arc.AlmostALine())
{
new_vertices.push_back(CVertex(arc.m_e, arc.m_user_data));
new_vertices.emplace_back(arc.m_e, arc.m_user_data);
}
else
{
new_vertices.push_back(CVertex(arc.m_dir ? 1:-1, arc.m_e, arc.m_c, arc.m_user_data));
new_vertices.emplace_back(arc.m_dir ? 1:-1, arc.m_e, arc.m_c, arc.m_user_data);
}
arc_added = true;
@@ -350,7 +350,7 @@ void CCurve::UnFitArcs()
double nx = vertex.m_c.x * CArea::m_units + radius * cos(phi-dphi);
double ny = vertex.m_c.y * CArea::m_units + radius * sin(phi-dphi);
new_pts.push_back(Point(nx, ny));
new_pts.emplace_back(nx, ny);
px = nx;
py = ny;
@@ -535,7 +535,7 @@ void CCurve::ChangeStart(const Point &p) {
}
else
{
new_curve.m_vertices.push_back(CVertex(p));
new_curve.m_vertices.emplace_back(p);
started = true;
start_span = span_index;
if(p != vertex.m_p)new_curve.m_vertices.push_back(vertex);
@@ -826,7 +826,7 @@ void CCurve::GetSpans(std::list<Span> &spans)const
const CVertex& vertex = *It;
if(prev_p)
{
spans.push_back(Span(*prev_p, vertex));
spans.emplace_back(*prev_p, vertex);
}
prev_p = &(vertex.m_p);
}
@@ -880,7 +880,7 @@ void CCurve::OffsetForward(double forwards_value, bool refit_arcs)
// add an arc to the start of the next span
int arc_type = ((sin_angle > 0) ? 1 : (-1));
Point centre = span.m_v.m_p - v * forwards_value;
m_vertices.push_back(CVertex(arc_type, next_span.m_p, centre));
m_vertices.emplace_back(arc_type, next_span.m_p, centre);
}
}
}
@@ -978,7 +978,7 @@ void CCurve::operator+=(const CCurve& curve)
{
if((m_vertices.size() == 0) || (It->m_p != m_vertices.back().m_p))
{
m_vertices.push_back(CVertex(It->m_p));
m_vertices.emplace_back(It->m_p);
}
}
else
@@ -1307,8 +1307,8 @@ void Span::Intersect(const Span& s, std::list<Point> &pts)const
geoff_geometry::Point pInt1, pInt2;
double t[4];
int num_int = MakeSpan(*this).Intof(MakeSpan(s), pInt1, pInt2, t);
if(num_int > 0)pts.push_back(Point(pInt1.x, pInt1.y));
if(num_int > 1)pts.push_back(Point(pInt2.x, pInt2.y));
if(num_int > 0)pts.emplace_back(pInt1.x, pInt1.y);
if(num_int > 1)pts.emplace_back(pInt2.x, pInt2.y);
}
void tangential_arc(const Point &p0, const Point &p1, const Point &v0, Point &c, int &dir)

View File

@@ -139,7 +139,7 @@ static CArea AreaFromDxf(const char* filepath)
static void append_point(CCurve& c, const Point& p)
{
c.m_vertices.push_back(CVertex(p));
c.m_vertices.emplace_back(p);
}
static boost::python::tuple nearest_point_to_curve(CCurve& c1, const CCurve& c2)

View File

@@ -3884,7 +3884,7 @@ void ClipperOffset::DoOffset(double delta)
if (node.m_endtype == etClosedLine || node.m_endtype == etClosedPolygon)
m_normals.push_back(GetUnitNormal(m_srcPoly[len - 1], m_srcPoly[0]));
else
m_normals.push_back(DoublePoint(m_normals[len - 2]));
m_normals.emplace_back(m_normals[len - 2]);
if (node.m_endtype == etClosedPolygon)
{