From 580dd67769e5c5e2d75c172f5c92c2e436a14aaf Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 22 Mar 2021 02:16:33 +0000 Subject: [PATCH] shapelib: Support occultation by back Signed-off-by: Ian Jackson --- src/shapelib-toml.rs | 3 +++ src/shapelib.rs | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/shapelib-toml.rs b/src/shapelib-toml.rs index dde24de8..d36e2b05 100644 --- a/src/shapelib-toml.rs +++ b/src/shapelib-toml.rs @@ -174,6 +174,9 @@ pub enum OccultationMethod { ByColour { colour: String, }, + ByBack { + ilk: OccultIlkName, + }, } /// An entry in the `colours` table, specifying one recolouring. diff --git a/src/shapelib.rs b/src/shapelib.rs index 747a372d..d3e0222c 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -54,6 +54,7 @@ struct ItemData { enum OccData { None, Internal(Arc), + Back(OccultIlkName), } #[allow(non_camel_case_types)] @@ -85,6 +86,8 @@ pub enum LibraryLoadError { #[error("{:?}",&self)] OccultationColourMissing(String), #[error("{:?}",&self)] + BackMissingForOccultation, + #[error("{:?}",&self)] ExpectedTable(String), #[error("{:?}",&self)] ExpectedString(String), @@ -381,7 +384,7 @@ impl Contents { .map_err(|e| SpE::InternalError(format!("reckoning transform: {}",&e)))?; let mut face = ItemFace { svg, desc, xform }; let mut faces = index_vec![ face ]; - let mut back = None; + let mut back = None::>; if idata.group.d.flip { face.xform.scale[0] *= -1.; faces.push(face); @@ -394,6 +397,12 @@ impl Contents { let occultable = match &idata.occ { OccData::None => None, + OccData::Back(ilk) => { + let back = if let Some(back) = &back { back } + else { throw!(internal_error_bydebug(&self)) }; + let back = back.clone(); + Some((ilk.clone(), back)) + }, OccData::Internal(occ) => { let name = occ.item_name.clone(); let svgd = { @@ -589,6 +598,12 @@ fn load_catalogue(libname: &str, dirname: &str, toml_path: &str) -> Contents { svgd: default(), })) }, + Some(OccultationMethod::ByBack { ilk }) => { + if group.d.back.is_none() { + throw!(LLE::BackMissingForOccultation) + } + OccData::Back(ilk.clone()) + }, }; let mut add1 = |item_name: &str, desc: Html| { -- 2.30.2