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
56 changes: 56 additions & 0 deletions crates/analysis/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,62 @@ mod tests {
assert!(within(&ds, &[0], center, 100_000.0).is_empty());
}

/// Bounding-box culling in `route_on` matches unculled snapping bit for bit and preserves the
/// distinct error messages for an empty network versus an endpoint beyond `snap_m`.
#[test]
fn route_on_culls_by_snap_window_with_identical_results_and_errors() {
let n = 25usize;
let step = 0.001;
let (x0, y0) = (-84.0, 35.9);
let mut ds = Dataset::new("roads", GeometryType::Polyline, vec![]);
for r in 0..n {
for c in 0..(n - 1) {
let a = Coord::new(x0 + c as f64 * step, y0 + r as f64 * step);
let b = Coord::new(x0 + (c + 1) as f64 * step, y0 + r as f64 * step);
ds.push(Some(Geometry::Line(vec![vec![a, b]])), vec![]);
}
}
for r in 0..(n - 1) {
for c in 0..n {
let a = Coord::new(x0 + c as f64 * step, y0 + r as f64 * step);
let b = Coord::new(x0 + c as f64 * step, y0 + (r + 1) as f64 * step);
ds.push(Some(Geometry::Line(vec![vec![a, b]])), vec![]);
}
}
let rows: Vec<usize> = (0..ds.features.len()).collect();
let graph = Network::build(&ds, &rows, None).unwrap();
let stops: Vec<Coord> = (0..10)
.map(|i| {
let c = (i * 5 + 2) % (n - 1);
let r = (i * 7 + 1) % (n - 1);
Coord::new(x0 + (c as f64 + 0.5) * step, y0 + r as f64 * step + 0.0001)
})
.collect();
for &p in &stops {
let unculled = nearest_segment(&graph.segs, &graph.nodes, p, None).unwrap().unwrap();
let culled = nearest_segment(&graph.segs, &graph.nodes, p, Some(50.0)).unwrap().unwrap();
assert_eq!(unculled.0, culled.0);
assert_eq!(unculled.1.to_bits(), culled.1.to_bits());
assert_eq!(unculled.2.x.to_bits(), culled.2.x.to_bits());
assert_eq!(unculled.2.y.to_bits(), culled.2.y.to_bits());
assert_eq!(unculled.3.to_bits(), culled.3.to_bits());
}
for w in stops.windows(2) {
let r = route_on(&graph, &ds, w[0], w[1], 50.0).unwrap();
assert!(!r.rows.is_empty() && r.length_m > 0.0);
}
// Culled to None on a non-empty network still reports a distance error, not an empty layer.
let far = route_on(&graph, &ds, Coord::new(x0 - 1.0, y0), stops[0], 50.0).unwrap_err();
assert!(far.contains("from the network"), "{far}");
let neg = route_on(&graph, &ds, stops[0], stops[1], -1.0).unwrap_err();
assert!(neg.contains("from the network"), "{neg}");
// An actually empty network still reports having no lines.
let empty_ds = Dataset::new("empty", GeometryType::Polyline, vec![]);
let empty_graph = Network::build(&empty_ds, &[], None).unwrap();
let empty_err = route_on(&empty_graph, &empty_ds, stops[0], stops[1], 50.0).unwrap_err();
assert!(empty_err.contains("the layer has no lines"), "{empty_err}");
}

#[test]
fn route_overlay_handles_empty_far_same_segment_and_endpoint_snaps() {
let cache = Mutex::new(None);
Expand Down
2 changes: 2 additions & 0 deletions crates/ui-egui/src/readjob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ fn run_presented(
preview: Option<rustgis_engine::data::Dataset>,
) -> Result<Value, String> {
if !app.reads_off_frame {
// Release any preview snapshot before running inline so it does not pin the rows' `Arc`.
drop(preview);
Comment thread
giswqs marked this conversation as resolved.
Resolved
// Read here and now: what its file holds now is what it reads.
if matches!(command, "layer.reloadData" | "map.reloadTiles") {
crate::diskwatch::reading(app, command, &p);
Expand Down
Loading
Loading