From 4df0e41bdf1ed899d55ed6122acafeb2c76ba2fe Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 11 Apr 2022 10:03:27 +0100 Subject: [PATCH] Introduce "inert" terminology for images for occultation This is much less confusing. In particular, I'm trying to distinguish the occulted piece from the piece (or trait object) which the occulted piece provides (to the caller of `load`) for its occulted image. No functional change other than wording in an error message. Signed-off-by: Ian Jackson --- src/gamestate.rs | 11 ++++++----- src/hidden.rs | 2 +- src/occultilks.rs | 2 +- src/pcaliases.rs | 6 +++--- src/pcrender.rs | 2 +- src/shapelib.rs | 24 ++++++++++++------------ src/spec.rs | 2 +- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/gamestate.rs b/src/gamestate.rs index 8e8a78b5..fe167c47 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -236,7 +236,7 @@ pub trait PieceTrait: OutlineTrait + Send + Debug + 'static { } #[typetag::serde] -pub trait OccultedPieceTrait: OutlineTrait { +pub trait InertPieceTrait: OutlineTrait { fn svg(&self, f: &mut Html, id: VisiblePieceId) -> Result<(),IE>; fn describe_html(&self) -> Result; } @@ -261,7 +261,7 @@ pub struct PieceSpecLoaded { pub occultable: PieceSpecLoadedOccultable, } pub type PieceSpecLoadedOccultable = - Option<(OccultIlkName, Arc)>; + Option<(OccultIlkName, Arc)>; #[typetag::serde(tag="type")] pub trait PieceSpec: Debug + Sync + Send + 'static { @@ -269,9 +269,10 @@ pub trait PieceSpec: Debug + Sync + Send + 'static { fn count(&self, _pcaliases: &PieceAliases) -> usize { 1 } fn load(&self, i: usize, gpc: &mut GPiece, ig: &Instance, depth: SpecDepth) -> Result; - fn load_occult(&self, _ig: &Instance, _:SpecDepth) - -> Result, SpecError> { - throw!(SpE::ComplexPieceWhereSimpleRequired) + /// Used when a piece wants to use another for its occulted form + fn load_inert(&self, _ig: &Instance, _:SpecDepth) + -> Result, SpecError> { + throw!(SpE::ComplexPieceWhereInertRequired) } } diff --git a/src/hidden.rs b/src/hidden.rs index b3e22917..d86fef3c 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -402,7 +402,7 @@ impl IPiece { #[throws(IE)] pub fn show_or_instead<'p>(&self, ioccults: &'p IOccults, y: Option) - -> Either { + -> Either { match y { Some(y) => Left(y), None => Right({ diff --git a/src/occultilks.rs b/src/occultilks.rs index e871f972..0c63c53c 100644 --- a/src/occultilks.rs +++ b/src/occultilks.rs @@ -18,7 +18,7 @@ pub struct OccultIlkName(pub Arc); #[derive(Debug,Serialize,Deserialize)] pub struct OccultIlkData { - pub p_occ: Arc, + pub p_occ: Arc, } type Id = OccultIlkId; diff --git a/src/pcaliases.rs b/src/pcaliases.rs index 3bf7c632..25bf7b75 100644 --- a/src/pcaliases.rs +++ b/src/pcaliases.rs @@ -71,9 +71,9 @@ impl PieceSpec for Alias { r } #[throws(SpecError)] - fn load_occult(&self, ig: &Instance, depth: SpecDepth) - -> Box { - self.resolve(&ig.pcaliases)?.load_occult(ig, self.new_depth(depth)?)? + fn load_inert(&self, ig: &Instance, depth: SpecDepth) + -> Box { + self.resolve(&ig.pcaliases)?.load_inert(ig, self.new_depth(depth)?)? } } diff --git a/src/pcrender.rs b/src/pcrender.rs index 9d3910b9..3a65dc45 100644 --- a/src/pcrender.rs +++ b/src/pcrender.rs @@ -47,7 +47,7 @@ impl VisiblePieceAngle { impl PriOccultedGeneral { #[throws(IE)] pub fn instead<'p>(&self, ioccults: &'p IOccults, p: &'p IPiece) - -> Either + -> Either { p.show_or_instead(ioccults, self.fully_visible())? } diff --git a/src/shapelib.rs b/src/shapelib.rs index c635733d..eca18a23 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -173,11 +173,11 @@ pub struct Item { descs: IndexVec, outline: Outline, #[serde(default)] - back: Option>, + back: Option>, } #[derive(Debug,Serialize,Deserialize)] -struct ItemOccultable { +struct ItemInertForOcculted { desc: Html, svgd: Arc, xform: FaceTransform, @@ -218,13 +218,13 @@ impl SvgBaseName where T: Borrow { } #[dyn_upcast] -impl OutlineTrait for ItemOccultable { delegate! { to self.outline { +impl OutlineTrait for ItemInertForOcculted { delegate! { to self.outline { fn outline_path(&self, scale: f64) -> Result; fn thresh_dragraise(&self) -> Result, IE>; fn bbox_approx(&self) -> Result; }}} #[typetag::serde(name="Lib")] -impl OccultedPieceTrait for ItemOccultable { +impl InertPieceTrait for ItemInertForOcculted { #[throws(IE)] fn svg(&self, f: &mut Html, _: VisiblePieceId) { self.xform.write_svgd(f, &self.svgd)?; @@ -382,7 +382,7 @@ impl PieceTrait for Item { } #[typetag::serde(name="LibItem")] -impl OccultedPieceTrait for Item { +impl InertPieceTrait for Item { #[throws(IE)] fn svg(&self, f: &mut Html, id: VisiblePieceId) { self.svg_face(f, default(), id)?; @@ -546,12 +546,12 @@ 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); } else if let Some(back_spec) = &idata.group.d.back { - match back_spec.load_occult(ig, depth) { + match back_spec.load_inert(ig, depth) { Err(SpecError::AliasNotFound) => { }, Err(e) => throw!(e), Ok(p) => { @@ -581,12 +581,12 @@ impl Contents { )?; Ok(Arc::new(occ_data)) }).clone()?; - let it = Arc::new(ItemOccultable { + let it = Arc::new(ItemInertForOcculted { svgd, xform: occ.xform.clone(), desc: occ.desc.clone(), outline: occ.outline.clone(), - }) as Arc; + }) as Arc; Some((OccultIlkName(occ_name.into_inner()), it)) }, }; @@ -641,9 +641,9 @@ impl PieceSpec for ItemSpec { self.find_load(ig,depth)?.into() } #[throws(SpecError)] - fn load_occult(&self, ig: &Instance, depth: SpecDepth) - -> Box { - self.find_load(ig,depth)?.0 as Box + fn load_inert(&self, ig: &Instance, depth: SpecDepth) + -> Box { + self.find_load(ig,depth)?.0 as Box } } diff --git a/src/spec.rs b/src/spec.rs index 20f63fbf..162a72f6 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -78,7 +78,7 @@ pub enum SpecError { #[error("specified with of edges, but no edges")] SpecifiedWidthOfNoEdges, #[error("shape not supported")] UnsupportedShape, #[error("negative timeout")] NegativeTimeout, - #[error("complex piece where simple needed")] ComplexPieceWhereSimpleRequired, + #[error("complex piece where inert needed")] ComplexPieceWhereInertRequired, #[error("piece alias not found")] AliasNotFound, #[error("piece alias target is multi spec")] AliasTargetMultiSpec, #[error("piece alias loop")] AliasLoop(String), -- 2.30.2