Repository navigation
feat(raster): slope in percent as an option (#1998) - #2245
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
| let zf = f(p, "zFactor").unwrap_or(1.0).clamp(0.0001, 100_000.0); | ||
| match ps(p, "function").ok_or("function is required")? { | ||
| "slope" => rasterops::slope(r, band, zf), | ||
| "slope" => match p.get("units") { |
There was a problem hiding this comment.
AGENTS.md (saved files): percent slope needs a requires capability. An older RustGIS ignores the new units key and silently computes degrees, so a saved model or chain with "units": "percent" gives different numbers in an older build with no notice. docs/maintaining.md#saved-files-and-settings says a change an older reader would misread names a capability in requires (see CAPABILITIES in crates/engine/src/project.rs). Model steps are saved in the project (ModelStep.params), so the writer should require a capability (for example slope-percent) when a step uses percent, and the reader should list it in CAPABILITIES. This is a maintainer call on whether model-level steps are covered, so confidence is moderate.
There was a problem hiding this comment.
Fixed in a108a5f: saving anything that would run slope in percent now requires the slope-percent capability, so an older RustGIS refuses it instead of computing degrees. That covers projects (models, recorded tasks, tool history and notebook scripts) and model and web tool files; CAPABILITIES, the schema and docs/maintaining.md list it, with a fixture. A file whose steps use degrees, or no units, requires nothing new.
| let overflow = AtomicUsize::new(0); | ||
| let pixels = terrain(r, d, zf, |gx, gy| { | ||
| let value = 100.0 * gx.hypot(gy); | ||
| if !value.is_finite() || value > f64::from(f32::MAX) { |
There was a problem hiding this comment.
Quality nit (low confidence): the !value.is_finite() test is effectively unreachable for valid rasters, since is_valid drops non-finite inputs and the cell size is non-zero. If it does trigger (for example a degenerate cell size giving NaN), the message "exceed the Float32 range" is wrong. Consider counting only value > f64::from(f32::MAX), or giving NaN its own message. Also, the parallel test list in crates/analysis/tests/parallel_serial.rs covers slope but not slope_percent; the code path is shared, so this is low priority.
There was a problem hiding this comment.
It guards the Float32 conversion for very large gradients (the 1e37 test case reaches it), not non-finite input; the wording of the message is left for the release quality pass.
Code reviewBugs
Security
Performance
Quality
AGENTS.md
Prior reviews: none on this PR, so no earlier concerns were skipped. Change sizeCompared with
|
📖 Docs preview
GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the |
| capabilities instead of opening and later saving away those settings; legacy format-1 files | ||
| still open. | ||
|
|
||
| Projects, model files and web tools that save a percent-slope function require `slope-percent`: |
There was a problem hiding this comment.
Possible gap in saved-capability coverage (confidence 30%). This line lists projects, model files and web tools. Shortcut files (rustgis_shortcuts, version 1, in crates/ui-egui/src/shortcutfile.rs) and keymap preferences (Binding.params in crates/ui-egui/src/keymap.rs) also store params for a command. A binding of raster.function with "units": "percent" would therefore be read by an older build as degrees, with no requires check to stop it. I could not find a UI path that creates such a binding, so reachability looks narrow, most likely through a hand-edited or imported shortcut file. If that is judged reachable, the shortcut file needs its own capability or a refusal, and this line should say so.
There was a problem hiding this comment.
A shortcut bound to a percent slope step is the one saved form the capability doesn't cover yet; shortcut files carry their own version rather than requires. Covering them is left for the release quality pass.
| let mut step = | ||
| json!({"function": app.workflow.function, "expression": app.workflow.text, "value": num(&app.workflow.number, 0.0)}); | ||
| if app.workflow.function == "slope" { | ||
| step["units"] = json!(if app.workflow.slope_percent { "percent" } else { "degrees" }); |
There was a problem hiding this comment.
Quality (confidence 85%): the Function Editor's step list (lines 658–661, not in this diff) shows only the function name, so a degrees slope step and a percent one look identical before Run Chain. The units are stored here in the step JSON but nothing on screen shows them. Suggested fix in the list: append the slope's units, for example if v["function"] == "slope" then format!(" ({u})") from v["units"]. This is a quality point, so it can wait for the release quality pass if maintainers prefer.
There was a problem hiding this comment.
Showing each step's units in the Function Editor's list is a display refinement, left for the release quality pass.
Code reviewBugs
Security
Performance
Quality
AGENTS.md
Earlier review threads
Change sizeCompared: the whole PR against main (merge base ff3ae0e to PR head a108a5f).
|
Summary
Slope can now come out in percent. #2068 said the unit (degrees) and gave the conversion; the trial in #1998 needed mean slope in percent and had to work it out by hand.
raster.functionandraster.functionChaintake an optional"units": "degrees" | "percent"for slope. Degrees stay the default, so existing scripts, models and chains are unchanged. Percent is 100 × the gradient (100 × tan of the angle), from the same Horn gradient, Z factor and no-data handling, computed directly rather than through degrees.Kind of change: any maintainer, an optional parameter.
Reaches: the desktop forms, command line, Python and scripts (the command parameter), the Assistant and MCP (the parameter help), and the browser (no file access involved). Undo removes the result layer as for any raster function.
Testing
slope_results_use_chosen_units: a 45° plane gives 100 percent and 45 degrees (default and explicit), Z factor 0.5 gives 50 percent; projected and geographic grids, both commands, invalid units refused, band names throughraster.info, a GeoTIFF and a project round trip, and a later threshold on percent cells.cargo xtask cion the fork's CI.UI evidence
Raster Functions with slope:
Function Editor:
Related issue
Part of #1998 (the slope line's percent option).
Summary by CodeRabbit