From 02b21fe102b7ec0ba577f42b7d58ecf80f25f34f Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Wed, 20 Jul 2016 15:13:42 -0400 Subject: [PATCH] Use C++11 initializers --- src/FileModule.cc | 2 +- src/GeometryEvaluator.cc | 2 +- src/Reindexer.h | 2 +- src/ThrownTogetherRenderer.cc | 2 +- src/cgalutils-applyops.cc | 6 ++++-- src/color.cc | 3 --- src/colornode.h | 2 +- src/grid.h | 10 +++++----- src/surface.cc | 28 ++++++++++++++-------------- 9 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/FileModule.cc b/src/FileModule.cc index b342c84a..9607047c 100644 --- a/src/FileModule.cc +++ b/src/FileModule.cc @@ -120,7 +120,7 @@ bool FileModule::handleDependencies() wasmissing = true; fs::path fullpath = find_valid_path(this->path, filename); if (!fullpath.empty()) { - updates.push_back(std::make_pair(filename, fullpath.generic_string())); + updates.push_back({filename, fullpath.generic_string()}); filename = fullpath.generic_string(); } else { diff --git a/src/GeometryEvaluator.cc b/src/GeometryEvaluator.cc index 84c0e97a..05b6f3ec 100644 --- a/src/GeometryEvaluator.cc +++ b/src/GeometryEvaluator.cc @@ -355,7 +355,7 @@ void GeometryEvaluator::addToParent(const State &state, { this->visitedchildren.erase(node.index()); if (state.parent()) { - this->visitedchildren[state.parent()->index()].push_back(std::make_pair(&node, geom)); + this->visitedchildren[state.parent()->index()].push_back({&node, geom}); } else { // Root node diff --git a/src/Reindexer.h b/src/Reindexer.h index f9ad6bc6..f50250b4 100644 --- a/src/Reindexer.h +++ b/src/Reindexer.h @@ -24,7 +24,7 @@ public: typename std::unordered_map::const_iterator iter = this->map.find(val); if (iter != this->map.end()) return iter->second; else { - this->map.insert(std::make_pair(val, this->map.size())); + this->map[val] = this->map.size(); return this->map.size() - 1; } } diff --git a/src/ThrownTogetherRenderer.cc b/src/ThrownTogetherRenderer.cc index 6339135a..0720713f 100644 --- a/src/ThrownTogetherRenderer.cc +++ b/src/ThrownTogetherRenderer.cc @@ -58,7 +58,7 @@ void ThrownTogetherRenderer::draw(bool /*showfaces*/, bool showedges) const void ThrownTogetherRenderer::renderChainObject(const CSGChainObject &csgobj, bool highlight_mode, bool background_mode, bool showedges, bool fberror, OpenSCADOperator type) const { - if (this->geomVisitMark[std::make_pair(csgobj.leaf->geom.get(), &csgobj.leaf->matrix)]++ > 0) return; + if (this->geomVisitMark[{csgobj.leaf->geom.get(), &csgobj.leaf->matrix}]++ > 0) return; const Color4f &c = csgobj.leaf->color; csgmode_e csgmode = csgmode_e( (highlight_mode ? diff --git a/src/cgalutils-applyops.cc b/src/cgalutils-applyops.cc index 34bf92cd..46914f6d 100644 --- a/src/cgalutils-applyops.cc +++ b/src/cgalutils-applyops.cc @@ -379,8 +379,10 @@ namespace CGALUtils { for (std::list>::iterator i = result_parts.begin(); i != result_parts.end(); ++i) { PolySet ps(3,true); createPolySetFromPolyhedron(*i, ps); - fake_children.push_back(std::make_pair((const AbstractNode*)NULL, - shared_ptr(createNefPolyhedronFromGeometry(ps)))); + fake_children.push_back({ + (const AbstractNode*)NULL, + shared_ptr(createNefPolyhedronFromGeometry(ps)) + }); } CGAL_Nef_polyhedron *N = CGALUtils::applyOperator(fake_children, OPENSCAD_UNION); // FIXME: This hould really never throw. diff --git a/src/color.cc b/src/color.cc index e421eb10..b3dffb7e 100644 --- a/src/color.cc +++ b/src/color.cc @@ -216,9 +216,6 @@ AbstractNode *ColorModule::instantiate(const Context *ctx, const ModuleInstantia { ColorNode *node = new ColorNode(inst); - node->color[0] = node->color[1] = node->color[2] = -1.0; - node->color[3] = 1.0; - AssignmentList args; args += Assignment("c"), Assignment("alpha"); diff --git a/src/colornode.h b/src/colornode.h index d66f8cb2..fe48fe59 100644 --- a/src/colornode.h +++ b/src/colornode.h @@ -7,7 +7,7 @@ class ColorNode : public AbstractNode { public: VISITABLE(); - ColorNode(const ModuleInstantiation *mi) : AbstractNode(mi) { } + ColorNode(const ModuleInstantiation *mi) : AbstractNode(mi), color(-1.0f, -1.0f, -1.0f, 1.0f) { } virtual std::string toString() const; virtual std::string name() const; diff --git a/src/grid.h b/src/grid.h index 05119498..c2a6f1de 100644 --- a/src/grid.h +++ b/src/grid.h @@ -37,11 +37,11 @@ public: T &align(double &x, double &y) { int64_t ix = (int64_t)std::round(x / res); int64_t iy = (int64_t)std::round(y / res); - if (db.find(std::make_pair(ix, iy)) == db.end()) { + if (db.find({ix, iy}) == db.end()) { int dist = 10; for (int64_t jx = ix - 1; jx <= ix + 1; jx++) { for (int64_t jy = iy - 1; jy <= iy + 1; jy++) { - if (db.find(std::make_pair(jx, jy)) == db.end()) + if (db.find({jx, jy}) == db.end()) continue; int d = abs(int(ix-jx)) + abs(int(iy-jy)); if (d < dist) { @@ -53,17 +53,17 @@ public: } } x = ix * res, y = iy * res; - return db[std::make_pair(ix, iy)]; + return db[{ix, iy}]; } bool has(double x, double y) const { int64_t ix = (int64_t)std::round(x / res); int64_t iy = (int64_t)std::round(y / res); - if (db.find(std::make_pair(ix, iy)) != db.end()) + if (db.find({ix, iy}) != db.end()) return true; for (int64_t jx = ix - 1; jx <= ix + 1; jx++) for (int64_t jy = iy - 1; jy <= iy + 1; jy++) { - if (db.find(std::make_pair(jx, jy)) != db.end()) + if (db.find({jx, jy}) != db.end()) return true; } return false; diff --git a/src/surface.cc b/src/surface.cc index 24d0b740..958ca872 100644 --- a/src/surface.cc +++ b/src/surface.cc @@ -119,7 +119,7 @@ void SurfaceNode::convert_image(img_data_t &data, std::vector &im long idx = 4 * (y * width + x); double pixel = 0.2126 * img[idx] + 0.7152 * img[idx + 1] + 0.0722 * img[idx + 2]; double z = 100.0/255 * (invert ? 1 - pixel : pixel); - data[std::make_pair(height - 1 - y, x)] = z; + data[{height - 1 - y, x}] = z; } } } @@ -192,7 +192,7 @@ img_data_t SurfaceNode::read_dat(std::string filename) const try { for(const auto &token : tokens) { double v = boost::lexical_cast(token); - data[std::make_pair(lines, col++)] = v; + data[{lines, col++}] = v; if (col > columns) columns = col; min_val = std::min(v-1, min_val); } @@ -231,10 +231,10 @@ const Geometry *SurfaceNode::createGeometry() const for (int i = 1; i < lines; i++) for (int j = 1; j < columns; j++) { - double v1 = data[std::make_pair(i-1, j-1)]; - double v2 = data[std::make_pair(i-1, j)]; - double v3 = data[std::make_pair(i, j-1)]; - double v4 = data[std::make_pair(i, j)]; + double v1 = data[{i-1, j-1}]; + double v2 = data[{i-1, j}]; + double v3 = data[{i, j-1}]; + double v4 = data[{i, j}]; double vx = (v1 + v2 + v3 + v4) / 4; p->append_poly(); @@ -262,14 +262,14 @@ const Geometry *SurfaceNode::createGeometry() const { p->append_poly(); p->append_vertex(ox + 0, oy + i-1, min_val); - p->append_vertex(ox + 0, oy + i-1, data[std::make_pair(i-1, 0)]); - p->append_vertex(ox + 0, oy + i, data[std::make_pair(i, 0)]); + p->append_vertex(ox + 0, oy + i-1, data[{i-1, 0}]); + p->append_vertex(ox + 0, oy + i, data[{i, 0}]); p->append_vertex(ox + 0, oy + i, min_val); p->append_poly(); p->insert_vertex(ox + columns-1, oy + i-1, min_val); - p->insert_vertex(ox + columns-1, oy + i-1, data[std::make_pair(i-1, columns-1)]); - p->insert_vertex(ox + columns-1, oy + i, data[std::make_pair(i, columns-1)]); + p->insert_vertex(ox + columns-1, oy + i-1, data[{i-1, columns-1}]); + p->insert_vertex(ox + columns-1, oy + i, data[{i, columns-1}]); p->insert_vertex(ox + columns-1, oy + i, min_val); } @@ -277,14 +277,14 @@ const Geometry *SurfaceNode::createGeometry() const { p->append_poly(); p->insert_vertex(ox + i-1, oy + 0, min_val); - p->insert_vertex(ox + i-1, oy + 0, data[std::make_pair(0, i-1)]); - p->insert_vertex(ox + i, oy + 0, data[std::make_pair(0, i)]); + p->insert_vertex(ox + i-1, oy + 0, data[{0, i-1}]); + p->insert_vertex(ox + i, oy + 0, data[{0, i}]); p->insert_vertex(ox + i, oy + 0, min_val); p->append_poly(); p->append_vertex(ox + i-1, oy + lines-1, min_val); - p->append_vertex(ox + i-1, oy + lines-1, data[std::make_pair(lines-1, i-1)]); - p->append_vertex(ox + i, oy + lines-1, data[std::make_pair(lines-1, i)]); + p->append_vertex(ox + i-1, oy + lines-1, data[{lines-1, i-1}]); + p->append_vertex(ox + i, oy + lines-1, data[{lines-1, i}]); p->append_vertex(ox + i, oy + lines-1, min_val); }