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
10 changes: 3 additions & 7 deletions crates/engine/src/cmd/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,9 @@ fn reset(s: &mut Session, p: Project) {
.collect();
// A block cut to polygons (#2318) whose layer is missing or picks no polygon with an area
// isn't drawn: said, and kept, so a polygon layer of that name, or an edit, brings it back.
// One whose outline was simplified to stay under 65 535 sides, or whose polygons have holes
// (not cut), is said as `map.terrain` says it. Each outline is read once.
let (mut uncut, mut simplified, mut holed) = (Vec::new(), Vec::new(), Vec::new());
// One whose outline was simplified to stay under 65 535 sides is said as `map.terrain` says
// it. Each outline is read once.
let (mut uncut, mut simplified) = (Vec::new(), Vec::new());
for m in &s.project.maps {
let Some(rustgis_map::view::BlockShape::Polygon { layer, filter }) =
m.view.terrain.as_ref().and_then(|t| t.block.as_ref()).map(|b| &b.shape)
Expand All @@ -427,7 +427,6 @@ fn reset(s: &mut Session, p: Project) {
continue;
};
simplified.extend(super::view::outline_simplified(layer, &o).map(|said| format!("{}: {said}", m.name)));
holed.extend(super::view::outline_holes(layer, &o).map(|said| format!("{}: {said}", m.name)));
}
match simplified.as_slice() {
[] => {}
Expand All @@ -437,9 +436,6 @@ fn reset(s: &mut Session, p: Project) {
false,
),
}
if !holed.is_empty() {
s.notify(holed.join("; "), false);
}
if !uncut.is_empty() {
s.notify(
format!(
Expand Down
39 changes: 17 additions & 22 deletions crates/engine/src/cmd/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn commands() -> Vec<C> {
}).roles(&[]).effects(crate::policy::Effects::NONE)
.params(r#"{"mode": "none"|"distance", "distance"?: metres from the view's centre}"#),
C::new("map.terrain", "Terrain", "View › Scene", terrain).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Network)).params(
r##"{"layer"?: a DEM raster layer (heights in metres; without layer or tiles, and no terrain yet, the active layer when it is a raster) | "tiles"?: elevation tile URL with {z}/{x}/{y}, "encoding"?: "terrarium"|"mapbox" (tiles; default terrarium), "exaggeration"?: 0 to 20 (default 1, or the terrain's), "block"?: a block diagram {"extent"?: "layer" (the DEM's extent, default) | [xmin, ymin, xmax, ymax] in map units (needed over tiles), "depth"?: metres from the lowest ground to the base (default half the relief, at least 100), "walls"?: "#RRGGBB" (default #C8B89A) | {"color"?: "#RRGGBB" (default #C8B89A), "layer"?: a polygon layer that holds all its features (not one read a view at a time; it may be hidden): its symbology colours the walls where its polygons meet the block's edge, and the walls are color off its polygons}, "shape"?: "box" (default) | "circle" (the largest circle in the box, its walls round it) | {"layer": a polygon layer, "where"?: sql (picks its polygons, as a definition query)} (the ground inside the polygons' outer rings, holes not cut, the box round them: no extent), "radius"?: a circle's radius in map units (default: the largest in the box), "water"?: the terrain's water shown in the walls' section {"depth"?: metres from the level to the floor, "field"?: a numeric field of the water layer holding each one's depth} (one of them needed), or false}, keys left out stay as the block had them and null puts one back to its default (a new block takes the defaults), and the block's "water" is given whole each time, replacing the old, or false to take it off (default: as it was), "water"?: water bodies drawn flat at their level {"layer": a polygon layer, "level"?: a numeric field of levels in metres (default: each polygon's lowest height along its shore), "glint"?: 0 to 1, how brightly a tilted view's water shines where it reflects the sun toward the eye (default 0.3; 0: none), "shore"?: 0 to 1, how dark the band along the water's shore is at the outline, fading a few pixels inside it (default 0.35; 0: none)}, or false to take it off (default: as it was), "off"?: true}"##,
r##"{"layer"?: a DEM raster layer (heights in metres; without layer or tiles, and no terrain yet, the active layer when it is a raster) | "tiles"?: elevation tile URL with {z}/{x}/{y}, "encoding"?: "terrarium"|"mapbox" (tiles; default terrarium), "exaggeration"?: 0 to 20 (default 1, or the terrain's), "block"?: a block diagram {"extent"?: "layer" (the DEM's extent, default) | [xmin, ymin, xmax, ymax] in map units (needed over tiles), "depth"?: metres from the lowest ground to the base (default half the relief, at least 100), "walls"?: "#RRGGBB" (default #C8B89A) | {"color"?: "#RRGGBB" (default #C8B89A), "layer"?: a polygon layer that holds all its features (not one read a view at a time; it may be hidden): its symbology colours the walls where its polygons meet the block's edge, and the walls are color off its polygons}, "shape"?: "box" (default) | "circle" (the largest circle in the box, its walls round it) | {"layer": a polygon layer, "where"?: sql (picks its polygons, as a definition query)} (the ground inside the polygons, each hole a well with its own walls and its floor at the base, the box round them: no extent), "radius"?: a circle's radius in map units (default: the largest in the box), "water"?: the terrain's water shown in the walls' section {"depth"?: metres from the level to the floor, "field"?: a numeric field of the water layer holding each one's depth} (one of them needed), or false}, keys left out stay as the block had them and null puts one back to its default (a new block takes the defaults), and the block's "water" is given whole each time, replacing the old, or false to take it off (default: as it was), "water"?: water bodies drawn flat at their level {"layer": a polygon layer, "level"?: a numeric field of levels in metres (default: each polygon's lowest height along its shore), "glint"?: 0 to 1, how brightly a tilted view's water shines where it reflects the sun toward the eye (default 0.3; 0: none), "shore"?: 0 to 1, how dark the band along the water's shore is at the outline, fading a few pixels inside it (default 0.35; 0: none)}, or false to take it off (default: as it was), "off"?: true}"##,
),
C::new("map.exportOrbit", "Export Orbit", "View › Scene", |s, p| super::exports::write_here(s, p, "map.exportOrbit")).inputs(orbit_inputs).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files))
.view()
Expand Down Expand Up @@ -458,31 +458,26 @@ fn block_polygons(s: &Session, o: &serde_json::Map<String, Value>) -> Result<rus

/// What simplifying a polygon block's outline lost: rings narrower than the spacing, and corners
/// past a third of the finest mesh cell or its smallest rings, to stay under 65 535 sides (said
/// when it is set and when a project opens).
/// when it is set and when a project opens), and holes left out as they lay outside their own
/// polygon.
pub(crate) fn outline_simplified(layer: &str, o: &rustgis_render::terrain::Outline) -> Option<String> {
let (spacing, coarsened) = o.spacing();
// Rings narrower than the spacing, with no area left once thinned (#2318).
let narrow =
(o.narrow() > 0).then(|| format!("{} ring(s) of '{layer}' narrower than {spacing:.0} m were left out of the block", o.narrow()));
let left = match o.dropped() {
0 if !coarsened => return narrow,
0 => String::new(),
n => format!(", and its {n} smallest ring(s) were left out"),
let stray = (o.stray() > 0)
.then(|| format!("{} hole(s) of '{layer}' lying outside their own polygon's outer ring were left out (not cut)", o.stray()));
let merged = match o.dropped() {
0 if !coarsened => None,
n => {
let left = if n == 0 { String::new() } else { format!(", and its {n} smallest ring(s) were left out") };
Some(format!(
"the outline of '{layer}' the block is cut to has too many corners: corners up to {spacing:.0} m apart were merged (less in smaller rings){left}, to stay under 65535 sides"
))
}
};
let said = format!(
"the outline of '{layer}' the block is cut to has too many corners: corners up to {spacing:.0} m apart were merged (less in smaller rings){left}, to stay under 65535 sides"
);
Some(match narrow {
Some(n) => format!("{said}; {n}"),
None => said,
})
}

/// The holes of a polygon block's polygons, which aren't cut: the ground inside them is drawn
/// (said when it is set and when a project opens).
pub(crate) fn outline_holes(layer: &str, o: &rustgis_render::terrain::Outline) -> Option<String> {
let n = o.holes();
(n > 0).then(|| format!("{n} hole(s) in the polygons of '{layer}' the block is cut to aren't cut: the ground inside them is drawn"))
let said: Vec<String> = [merged, narrow, stray].into_iter().flatten().collect();
(!said.is_empty()).then(|| said.join("; "))
}

/// The name of the polygon layer `name` for `what` (water, a block's walls), checked: a polygon
Expand Down Expand Up @@ -753,7 +748,7 @@ fn terrain(s: &mut Session, p: &Value) -> CmdResult {
// A polygon block's outline as drawn: its sides and how near its corners were let lie.
if let Some((_, o)) = &outline {
let (spacing, coarsened) = o.spacing();
out["block"]["outline"] = json!({"sides": o.side_count(), "spacing": spacing, "coarsened": coarsened, "dropped": o.dropped(), "holes": o.holes(), "narrow": o.narrow()});
out["block"]["outline"] = json!({"sides": o.side_count(), "spacing": spacing, "coarsened": coarsened, "dropped": o.dropped(), "holes": o.holes(), "stray": o.stray(), "narrow": o.narrow()});
}
if matches!(t.source, TerrainSource::Layer(_)) && t.block.is_some() && dem_box.is_none() {
out["block"]["pendingDem"] = json!(true);
Expand Down Expand Up @@ -839,7 +834,7 @@ fn terrain(s: &mut Session, p: &Value) -> CmdResult {
m.view.terrain = Some(t);
// A polygon block's outline simplified past a third of the finest mesh cell, or short of its
// smallest rings, to stay under 65 535 sides: said, with how far.
for said in outline.iter().flat_map(|(layer, o)| [outline_simplified(layer, o), outline_holes(layer, o)]).flatten() {
for said in outline.iter().flat_map(|(layer, o)| outline_simplified(layer, o)) {
s.notify(format!("Terrain: {said}"), false);
}
if block_cut {
Expand Down
18 changes: 12 additions & 6 deletions crates/engine/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15586,6 +15586,10 @@ fn terrain_block_cut_to_polygons() {
[[10.005, 45.005], [10.015, 45.005], [10.015, 45.015], [10.005, 45.015], [10.005, 45.005]],
[[10.008, 45.008], [10.012, 45.008], [10.012, 45.012], [10.008, 45.012], [10.008, 45.008]],
]}},
{"type": "Feature", "properties": {"nome": "e"}, "geometry": {"type": "Polygon", "coordinates": [
[[10.005, 45.005], [10.015, 45.005], [10.015, 45.015], [10.005, 45.015], [10.005, 45.005]],
[[10.018, 45.008], [10.019, 45.008], [10.019, 45.009], [10.018, 45.009], [10.018, 45.008]],
]}},
]});
let data = base64::engine::general_purpose::STANDARD.encode(areas.to_string().as_bytes());
s.run("layer.addDataBytes", &json!({"fileName": "areas.geojson", "data": data})).unwrap();
Expand Down Expand Up @@ -15624,18 +15628,20 @@ fn terrain_block_cut_to_polygons() {
let mut opened = Session::new(Project::default());
crate::cmd::project::reset_to(&mut opened, s.project.clone());
assert!(!simplified(&s) && !simplified(&opened), "{:?}", opened.notices);
// Nor holes, which a polygon with one gives: said once as it is set and as it opens.
let holes = |s: &Session| s.notices.iter().filter(|n| n.text.contains("hole(s) in the polygons")).count();
assert_eq!((holes(&s), holes(&opened)), (0, 0), "{:?}", opened.notices);
// A polygon with a hole is cut with a well there (reported), which leaves nothing to say.
let mut holed = Session::new(Project::default());
crate::cmd::project::reset_to(&mut holed, s.project.clone());
let v = holed.run("map.terrain", &json!({"layer": dem, "block": {"shape": {"layer": "bacias", "where": "nome = 'd'"}}})).unwrap();
assert_eq!(v["block"]["outline"]["holes"], json!(1));
assert_eq!(holes(&holed), 1, "{:?}", holed.notices);
assert_eq!(v["block"]["outline"]["sides"], json!(8));
let mut opened = Session::new(Project::default());
crate::cmd::project::reset_to(&mut opened, holed.project.clone());
assert_eq!(holes(&opened), 1, "{:?}", opened.notices);
assert!(opened.notices.iter().any(|n| n.text.contains("1 hole(s) in the polygons of 'bacias'")), "{:?}", opened.notices);
assert!(!holed.notices.iter().chain(&opened.notices).any(|n| n.text.contains("hole")), "{:?}", opened.notices);
// A hole lying outside its own outer ring cuts nothing: left out, and said.
let v = holed.run("map.terrain", &json!({"layer": dem, "block": {"shape": {"layer": "bacias", "where": "nome = 'e'"}}})).unwrap();
assert_eq!((&v["block"]["outline"]["holes"], &v["block"]["outline"]["stray"]), (&json!(0), &json!(1)));
let stray = "1 hole(s) of 'bacias' lying outside their own polygon's outer ring were left out";
assert!(holed.notices.iter().any(|n| n.text.contains(stray)), "{:?}", holed.notices);
// A saved block cut to a polygon off the DEM is kept as the project opens, and said.
let mut far = s.project.clone();
if let Some(b) = far.maps[0].view.terrain.as_mut().and_then(|t| t.block.as_mut()) {
Expand Down
4 changes: 2 additions & 2 deletions crates/map/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ pub enum BlockShape {
radius: Option<f64>,
},
/// The polygons of `layer` (by name, as the terrain's DEM) that `filter` picks among the rows
/// its definition query keeps (all of them without one): the ground inside their outer rings,
/// their holes not cut, the box being the one round them.
/// its definition query keeps (all of them without one): the ground inside them, each hole a
/// well, the box being the one round them.
Polygon {
layer: String,
#[serde(rename = "where", default, skip_serializing_if = "Option::is_none")]
Expand Down
Loading
Loading