Fix broken arrange

This commit is contained in:
tamasmeszaros 2019-03-28 11:01:41 +01:00
parent 440e54181b
commit 50c351e0f4
6 changed files with 23 additions and 17 deletions

View File

@ -150,9 +150,10 @@ template<> inline void offset(PolygonImpl& sh, TCoord<PointImpl> distance)
// but throwing would be an overkill. Instead, we should warn the
// caller about the inability to create correct geometries
if(!found_the_contour) {
sh.Contour = r;
sh.Contour = std::move(r);
ClipperLib::ReversePath(sh.Contour);
sh.Contour.push_back(sh.Contour.front());
auto front_p = sh.Contour.front();
sh.Contour.emplace_back(std::move(front_p));
found_the_contour = true;
} else {
dout() << "Warning: offsetting result is invalid!";
@ -162,9 +163,10 @@ template<> inline void offset(PolygonImpl& sh, TCoord<PointImpl> distance)
// TODO If there are multiple contours we can't be sure which hole
// belongs to the first contour. (But in this case the situation is
// bad enough to let it go...)
sh.Holes.push_back(r);
sh.Holes.emplace_back(std::move(r));
ClipperLib::ReversePath(sh.Holes.back());
sh.Holes.back().push_back(sh.Holes.back().front());
auto front_p = sh.Holes.back().front();
sh.Holes.back().emplace_back(std::move(front_p));
}
}
}
@ -328,16 +330,18 @@ inline std::vector<PolygonImpl> clipper_execute(
std::function<void(ClipperLib::PolyNode*, PolygonImpl&)> processHole;
auto processPoly = [&retv, &processHole](ClipperLib::PolyNode *pptr) {
PolygonImpl poly(pptr->Contour);
poly.Contour.push_back(poly.Contour.front());
PolygonImpl poly;
poly.Contour.swap(pptr->Contour); auto front_p = poly.Contour.front();
poly.Contour.emplace_back(std::move(front_p));
for(auto h : pptr->Childs) { processHole(h, poly); }
retv.push_back(poly);
};
processHole = [&processPoly](ClipperLib::PolyNode *pptr, PolygonImpl& poly)
{
poly.Holes.push_back(pptr->Contour);
poly.Holes.back().push_back(poly.Holes.back().front());
poly.Holes.emplace_back(std::move(pptr->Contour));
auto front_p = poly.Holes.back().front();
poly.Holes.back().emplace_back(std::move(front_p));
for(auto c : pptr->Childs) processPoly(c);
};
@ -365,7 +369,9 @@ merge(const std::vector<PolygonImpl>& shapes)
for(auto& path : shapes) {
valid &= clipper.AddPath(path.Contour, ClipperLib::ptSubject, closed);
valid &= clipper.AddPaths(path.Holes, ClipperLib::ptSubject, closed);
for(auto& h : path.Holes)
valid &= clipper.AddPath(h, ClipperLib::ptSubject, closed);
}
if(!valid) throw GeometryException(GeomErr::MERGE);

View File

@ -966,7 +966,7 @@ private:
for(size_t i = 0; i < pckgrp.size(); i++) {
auto items = pckgrp[i];
pg.push_back({});
pg.emplace_back();
pg[i].reserve(items.size());
for(Item& itemA : items) {

View File

@ -261,7 +261,7 @@ template<class RawShape> class EdgeCache {
while(next != endit) {
contour_.emap.emplace_back(*(first++), *(next++));
contour_.full_distance += contour_.emap.back().length();
contour_.distances.push_back(contour_.full_distance);
contour_.distances.emplace_back(contour_.full_distance);
}
}
@ -276,10 +276,10 @@ template<class RawShape> class EdgeCache {
while(next != endit) {
hc.emap.emplace_back(*(first++), *(next++));
hc.full_distance += hc.emap.back().length();
hc.distances.push_back(hc.full_distance);
hc.distances.emplace_back(hc.full_distance);
}
holes_.push_back(hc);
holes_.emplace_back(std::move(hc));
}
}

View File

@ -63,7 +63,7 @@ public:
bool pack(Item& item, const Range& rem = Range()) {
auto&& r = static_cast<Subclass*>(this)->trypack(item, rem);
if(r) {
items_.push_back(*(r.item_ptr_));
items_.emplace_back(*(r.item_ptr_));
farea_valid_ = false;
}
return r;
@ -78,7 +78,7 @@ public:
if(r) {
r.item_ptr_->translation(r.move_);
r.item_ptr_->rotation(r.rot_);
items_.push_back(*(r.item_ptr_));
items_.emplace_back(*(r.item_ptr_));
farea_valid_ = false;
}
}

View File

@ -667,7 +667,7 @@ public:
addBin();
ItemList& not_packed = not_packeds[b];
for(unsigned idx = b; idx < store_.size(); idx+=bincount_guess) {
not_packed.push_back(store_[idx]);
not_packed.emplace_back(store_[idx]);
}
}

View File

@ -463,7 +463,7 @@ template<> inline std::string serialize<libnest2d::Formats::SVG>(
auto& v = *it;
hf.emplace_back(getX(v)*scale, getY(v)*scale);
};
holes.push_back(hf);
holes.emplace_back(std::move(hf));
}
Polygonf poly;