Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/rustgis-mobile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ Rust calls Java and never the other way: each frame the app collects what happen
A phone starts in the touch interface: the map, a bar of four large buttons under it (Layers, Add
Data, Capture, More) and sheets that rise over the map. The Layers sheet shows and hides layers,
zooms to one and makes one the active layer; the More sheet has Full Extent, the project, undo
and redo, and **Use the Desktop Interface**, which brings back the ribbon and panes until the app
is started again.
and redo, and **Use the Desktop Interface**, which brings back the ribbon and panes; **Touch
Interface**, on the View tab (or Use the Touch Interface in Command Search), returns to the phone's
interface.

**Capture** adds a feature to one of the map's point, line or polygon layers. A cross marks the
middle of the map: the map is moved under it, and the sheet's fields are filled in (one for each
Expand Down
12 changes: 6 additions & 6 deletions apps/rustgis/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,11 +931,11 @@ mod tests {
}
assert!(!ctx.has_requested_repaint(), "clean preferences keep the window idle");
// A full disk: said once, not for every setting that follows.
prefs::saved(Err("could not save preferences: no space left".into()));
prefs::saved(Err("could not save preferences: no space left".into()));
prefs::saved(Err("no space left".into()));
prefs::saved(Err("no space left".into()));
frame();
assert!(ctx.has_requested_repaint(), "the pending failure requests its delivery frame");
assert_eq!(prefs::take_notices(), [Notice::NotSaved("could not save preferences: no space left".into())]);
assert_eq!(prefs::take_notices(), [Notice::NotSaved("no space left".into())]);
for _ in 0..4 {
frame();
}
Expand All @@ -949,8 +949,8 @@ mod tests {
assert!(prefs::take_notices().is_empty(), "equivalent recovery outcomes stay quiet");
// Once a save works, the next failure is news again.
prefs::saved(Ok(None));
prefs::saved(Err("could not save preferences: read-only".into()));
assert_eq!(prefs::take_notices(), [Notice::NotSaved("could not save preferences: read-only".into())]);
prefs::saved(Err("read-only".into()));
assert_eq!(prefs::take_notices(), [Notice::NotSaved("read-only".into())]);
prefs::saved(Ok(None));
// A malformed file set aside says where it went.
let bad = std::path::PathBuf::from("prefs.json.bad");
Expand All @@ -959,7 +959,7 @@ mod tests {
let text = prefs::text(&Notice::SetAside(bad));
assert!(text.contains("prefs.json.bad"), "{text}");
// Both a failed replacement and an unconfirmed final flush give an accurate notice.
for error in ["could not save preferences: read-only", "preferences were replaced, but their durability could not be confirmed"] {
for error in ["read-only", "preferences were replaced, but their durability could not be confirmed"] {
let text = prefs::text(&Notice::NotSaved(error.into()));
assert!(text.contains("Settings could not be saved reliably") && text.contains(error), "{text}");
assert!(!text.contains("changes last only until"), "{text}");
Expand Down
4 changes: 2 additions & 2 deletions crates/analysis/src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5511,8 +5511,8 @@ fn ground_area_perimeter(g: &Geometry) -> (f64, f64) {
for c in &mut ring.0 {
let step = c.x - previous;
previous = c.x;
// Within 1e-4° of a full turn, as `wgs84_ring_perimeter_area_m2` takes it.
if step.abs() >= 360.0 - 1e-4 && step.is_finite() {
// A full turn as `wgs84_ring_perimeter_area_m2` takes it.
if rustgis_geom::is_full_turn_step(step) {
longitude += step;
full_turn = true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/data/src/raster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ impl Raster {
if self.georeferenced {
Ok(())
} else {
Err(format!("{} has no coordinates: georeference it first (raster.georeference)", self.name))
Err(format!("{} has no coordinates: georeference it first (raster.georeference, with the Imagery extension on)", self.name))
}
}

Expand Down
9 changes: 2 additions & 7 deletions crates/engine/src/cmd/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,13 @@ pub(crate) fn drawn(
}
}
if written.is_ok() {
let listed = |v: &[String]| {
let more = v.len().saturating_sub(10);
let shown = v.iter().take(10).cloned().collect::<Vec<_>>().join("; ");
if more > 0 { format!("{shown}; and {more} more") } else { shown }
};
let warn = rustgis_data::diagnostics::Severity::Warning;
if unplaced > 0 {
notices.push((
warn,
format!(
"{path}: {unplaced} feature(s) have a place that can't be given in longitude/latitude, drawn without it ({})",
listed(&partly)
crate::listed(&partly)
),
));
}
Expand All @@ -200,7 +195,7 @@ pub(crate) fn drawn(
format!(
"{path}: {} layer(s) aren't drawn, as their system can't be given in longitude/latitude: {}",
undrawn.len(),
listed(&undrawn)
crate::listed(&undrawn)
),
));
}
Expand Down
8 changes: 4 additions & 4 deletions crates/engine/src/cmd/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ fn fetch_registry(s: &mut Session, url: &str) -> Result<Vec<rustgis_plugins::reg
Err(_) => Ok(Vec::new()),
};
match applied {
Ok(pulled) if !pulled.is_empty() => s.notify(
format!("{} plugin(s) were withdrawn from the plugin registry and turned off: {}", pulled.len(), pulled.join(", ")),
true,
),
// A warning, not an error: the list was read and the withdrawal applied as asked.
Ok(pulled) if !pulled.is_empty() => {
s.warn(format!("{} plugin(s) were withdrawn from the plugin registry and turned off: {}", pulled.len(), pulled.join(", ")))
}
Ok(_) => {}
Err(e) => s.warn(format!("{blocklist}: {e}; the last blocklist read, if any, stays in force")),
}
Expand Down
12 changes: 7 additions & 5 deletions crates/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@ fn clip(s: &str, n: usize) -> String {
/// stays well within what a notice keeps.
const NAMES_SAID: usize = 5;

/// The first ten of `v` for a notice, separated by `; `, then how many more.
pub(crate) fn listed(v: &[String]) -> String {
let more = v.len().saturating_sub(10);
let shown = v.iter().take(10).cloned().collect::<Vec<_>>().join("; ");
if more > 0 { format!("{shown}; and {more} more") } else { shown }
}

/// Layer names for a notice: the first [`NAMES_SAID`], each clipped, and how many more.
fn names_said(names: &[String]) -> String {
let shown: Vec<String> = names.iter().take(NAMES_SAID).map(|n| clip(n, 80)).collect();
Expand Down Expand Up @@ -3229,11 +3236,6 @@ impl Session {
}
// Layers gone are forgotten, so the map stays as small as the project.
self.unplaced_checked.retain(|id, _| seen.contains(id));
let listed = |v: &[String]| {
let more = v.len().saturating_sub(10);
let shown = v.iter().take(10).cloned().collect::<Vec<_>>().join("; ");
if more > 0 { format!("{shown}; and {more} more") } else { shown }
};
if features > 0 {
let text = format!(
"{features} feature(s) have a place that can't be given in longitude/latitude: the map and the globe draw them without it, and labels' lines, block diagrams and terrain water leave them out ({})",
Expand Down
6 changes: 5 additions & 1 deletion crates/engine/src/policy/downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ use std::{
},
};

/// The keys of a window the app reads off the frame (`"window"`, #1330): the app copies these
/// from the request, and a landed window holding any other key is refused.
pub const WINDOW_KEYS: [&str; 3] = ["bbox", "cellSize", "cog"];

/// What a window the app read off the frame says it read (`"window"`, #1330) is what its request
/// asked for: a box, and its cell size and `"cog"` if the request gave them, nothing else.
fn asked_window(asked: &Value, window: &Value) -> bool {
const KEYS: [&str; 3] = ["bbox", "cellSize", "cog"];
const KEYS: [&str; 3] = WINDOW_KEYS;
let given = |k: &str| asked.get(k).filter(|v| !v.is_null());
given("bbox").is_some()
&& window.as_object().is_some_and(|w| w.keys().all(|k| KEYS.contains(&k.as_str())) && KEYS.iter().all(|k| given(k) == w.get(*k)))
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/policy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
mod decide;
mod dispatch;
pub(crate) mod downloads;
pub use downloads::WINDOW_KEYS;
mod effects;
pub mod handler;
mod plan;
Expand Down
21 changes: 9 additions & 12 deletions crates/engine/src/prefs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,13 @@ fn write_at_with_bytes(
map.insert(key.to_string(), Value::String(value.to_string()));
let text = serde_json::to_vec(&map).map_err(|_| "could not serialize preferences")?;
let dir = path.parent().ok_or("the settings folder isn't available")?;
std::fs::create_dir_all(dir).and_then(|_| rustgis_data::io::replace_atomic(path, &text)).map_err(|error| match &set_aside {
Some(backup) => format!("could not save preferences: {error}; malformed preferences were kept at {}", backup.display()),
None => format!("could not save preferences: {error}"),
})?;
sync(path).map_err(|error| match &set_aside {
Some(backup) => format!(
"preferences were replaced, but their durability could not be confirmed: {error}; malformed preferences were kept at {}",
backup.display()
),
None => format!("preferences were replaced, but their durability could not be confirmed: {error}"),
})?;
// The app wraps these in "Settings could not be saved reliably (…)", so they don't repeat it.
let kept = |message: String| match &set_aside {
Some(backup) => format!("{message}; malformed preferences were kept at {}", backup.display()),
None => message,
};
std::fs::create_dir_all(dir).and_then(|_| rustgis_data::io::replace_atomic(path, &text)).map_err(|error| kept(error.to_string()))?;
sync(path).map_err(|error| kept(format!("preferences were replaced, but their durability could not be confirmed: {error}")))?;
Ok(set_aside)
}

Expand Down Expand Up @@ -181,7 +177,8 @@ fn sync_directory(path: &Path) -> std::io::Result<()> {
}

/// Returns the open copy when its bytes match, so the caller can confirm its durability.
/// Symlink paths and read errors do not establish a match; sync failures remain distinct.
/// Symlink paths and read errors do not establish a match. This doesn't sync: the caller confirms
/// durability on the returned file.
fn same_contents(source: &[u8], target: &Path) -> std::io::Result<Option<std::fs::File>> {
if !std::fs::symlink_metadata(target)?.file_type().is_file() {
return Ok(None);
Expand Down
6 changes: 4 additions & 2 deletions crates/engine/src/service_logins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ pub const CHOOSE_CONNECTION: &str = "Several saved connections match this addres
pub const NO_SUCH_CONNECTION: &str = "No saved web-service connection with this id.";
/// A request's `connection` that isn't text.
pub const CONNECTION_TEXT: &str = "connection must be a saved web-service connection id (text)";
/// A form-test probe given an unusable connection definition.
pub const BAD_DEFINITION: &str = "The service test requires a valid web-service connection and login.";
/// A form-test probe given an address that isn't plain and at the connection's origin.
pub const BAD_ADDRESS: &str = "The service test requires a credential-free HTTP or HTTPS address at the connection's origin.";
/// The commands that add layers from a service, and so may record the connection they came from
/// (their `connection` parameter, or the connection whose login their address is read with).
pub const ADD_COMMANDS: &[&str] = &[
Expand Down Expand Up @@ -323,8 +327,6 @@ impl Drop for TemporaryProbe {
/// `url` is the address returned by the existing anonymous `connection.test` probe. Only a
/// plain, credential-free address at the cleaned definition's exact origin may carry it.
pub fn temporary_probe(c: &Connection, secret: &str, insecure: bool, url: &str) -> Result<(String, TemporaryProbe), String> {
const BAD_DEFINITION: &str = "The service test requires a valid web-service connection and login.";
const BAD_ADDRESS: &str = "The service test requires a credential-free HTTP or HTTPS address at the connection's origin.";
if !c.id.is_empty() || !is_service(c) {
return Err(BAD_DEFINITION.into());
}
Expand Down
16 changes: 12 additions & 4 deletions crates/geom/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,19 +478,19 @@ pub fn ring_area_is_ambiguous(ring: &[Coord]) -> bool {
}

/// How many times a lon/lat ring that never reaches a pole winds around one: each step of
/// longitude taken the short way round (within ±180°; an edge of exactly a whole turn as [`ring_lon_steps`]
/// reads it), summed, in whole turns. A ring cut at ±180° and closed along the pole, the form
/// longitude taken the short way round (within ±180°; an edge of a whole turn, within [`NEAR_DEG`]
/// (about 11 m), as [`ring_lon_steps`] reads it), summed, in whole turns. A ring cut at ±180° and closed along the pole, the form
/// RustGIS takes for a polygon around a pole, reaches the pole and gives 0; so does any ring whose
/// steps cancel. A loop such as a parallel written all the way round (`[0, 80]`, `[30, 80]`, …,
/// `[330, 80]`) gives ±1, and the analysis plane, which reads longitude and latitude as x and y,
/// sees it as a line with no area. 0 for a ring with fewer than three vertices, a coordinate that
/// isn't finite or lies past ±90° of latitude, or a vertex at a pole.
/// isn't finite or lies past ±90° of latitude, or a vertex at a pole (within [`NEAR_DEG`]).
///
/// Only the coordinates are read, as longitude and latitude, as the analysis tools that read areas
/// in the plane take a layer's (a layer with a coordinate system is read into them): a ring whose x
/// and y were never degrees (a layer with no coordinate system, in small units, taken for degrees)
/// can wind too, but only with an edge more than 180 long in x, and the steps decide it, taken the
/// short way but for an edge of exactly 360, which may be a full turn as above (`[0, 0]`,
/// short way but for an edge of 360 (within [`NEAR_DEG`]), which may be a full turn as above (`[0, 0]`,
/// `[360, 0]`, `[360, 10]`, `[240, 10]`, `[120, 10]`, `[0, 10]` keeps its first edge as one, and
/// gives 0).
/// The triangle `[0, 0]`, `[300, 0]`, `[150, 80]` steps -60°, -150° and -150°, so it gives -1
Expand Down Expand Up @@ -592,6 +592,14 @@ fn wgs84_parallel_m(lat_deg: f64, dlon_deg: f64) -> f64 {
/// decimals or more keeps its full turns.
const NEAR_DEG: f64 = 1e-4;

/// Whether a step of longitude (degrees) is a full turn, within [`NEAR_DEG`]: an edge along a
/// parallel or the pole written from -180° to 180°, which the area and winding measures here keep
/// as written. Code that unwraps longitudes must agree with them, so it asks this.
#[must_use]
pub fn is_full_turn_step(step: f64) -> bool {
step.is_finite() && step.abs() >= 360.0 - NEAR_DEG
}

/// Whether a latitude is at a pole, within [`NEAR_DEG`].
fn at_pole(lat: f64) -> bool {
lat.is_finite() && lat.abs() >= 90.0 - NEAR_DEG
Expand Down
2 changes: 1 addition & 1 deletion crates/plugins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ fn call_with_timeout(
) -> Result<Value, String> {
// A command's settings requests are answered here, by this plugin's own id, however it runs.
// A tool gets none: it runs off the UI thread, in models and on copies, and its output must
// not depend on what was saved (it makes no host requests).
// not depend on what was saved (its settings requests are refused).
let mut scoped;
let host: &mut dyn Host = if tool {
host
Expand Down
3 changes: 2 additions & 1 deletion crates/plugins/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ fn no_params() -> String {
"{}".into()
}

/// A tool parameter: the Tools pane turns its kind into a widget.
/// A tool parameter, or a field of a command's dialog (`commands[].form`): the Tools pane and the
/// dialog turn its kind into a widget.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ParamDecl {
Expand Down
Loading
Loading