Clean up rd_grid.cpp some#1118
Conversation
c24ee35 to
55be67f
Compare
There was a problem hiding this comment.
Pull request overview
Adds unit tests around rd_grid utility/file I/O behavior and modernizes several trivial loop patterns in rd_grid.cpp (mostly scoping loop variables).
Changes:
- Added broad unit tests for regular rectangular grids covering indexing, geometry, keyword allocation, export helpers, and basic file I/O.
- Modernized a number of
forloops inrd_grid.cpp(scoped loop indices and some range-based loops). - Removed a couple of declarations from the public
rd_grid.hppheader.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| lib/tests/test_rd_grid.cpp | Adds extensive Catch2 coverage for many rd_grid APIs plus some smoke tests for grid file writing/loading. |
| lib/resdata/rd_grid.cpp | Refactors multiple loops to modern C++ style (scoped indices / range-based), with no intended behavior change. |
| lib/include/resdata/rd_grid.hpp | Removes two function declarations from the public header (potential API surface change). |
Comments suppressed due to low confidence (1)
lib/resdata/rd_grid.cpp:951
- The range-based loop variable can be
const auto &psincepis not modified. This better communicates intent and prevents accidental mutation ofcorner_listelements.
for (auto &p : cell->corner_list) {
if ((p.x == 0) && (p.y == 0)) {
SET_CELL_FLAG(cell, CELL_FLAG_TAINTED);
break;
}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f5245ad to
076cc2d
Compare
| int coords_size, int **coords, float **corners, const float *mapaxes) { | ||
| if (dualp_flag != FILEHEAD_SINGLE_POROSITY) | ||
| nz = nz / 2; | ||
| { |
There was a problem hiding this comment.
I'm not familiar with C++, what is the purpose of these outer curly braces wrapping the whole loop expressions? Is this some old convention?
There was a problem hiding this comment.
It creates a scope for the variables inside it. Its still useful for setting when an object is destructed when using RAII in c++
076cc2d to
9c26bd2
Compare
Add tests for rd_grid.cpp and modernize the for loops that are trivial.
I added tests for all functions that could be added tests for, which was cut short because of #1117 and that there is no simple way of dealing with coarse cells.
Then I very carefully replaced the for loop patterns that could trivially be replaced.