From: Ian Jackson Date: Tue, 16 Mar 2021 11:58:47 +0000 (+0000) Subject: hidden: make .instead be a method on PriOG X-Git-Tag: otter-0.4.0~20 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=8bfb95028f69a1c480694fb207492d00e498018b;p=otter.git hidden: make .instead be a method on PriOG Signed-off-by: Ian Jackson --- diff --git a/src/pcrender.rs b/src/pcrender.rs index 21542d6e..72562950 100644 --- a/src/pcrender.rs +++ b/src/pcrender.rs @@ -40,6 +40,30 @@ impl VisiblePieceAngle { } } +impl PriOccultedGeneral { + #[throws(IE)] + fn instead<'p>(&self, ioccults: &'p IOccults, p: &'p IPiece) + -> Either + { + use PriOG::*; + match self { + Visible(v) => Left(*v), + Occulted | Displaced(..) => { + Right({ + let occilk = p.occilk.as_ref() + .ok_or_else(|| internal_logic_error(format!( + "occulted non-occultable {:?}", p)))? + .borrow(); + let occ_data = ioccults.ilks.get(occilk) + .ok_or_else(|| internal_logic_error(format!( + "occulted ilk vanished {:?} {:?}", p, occilk)))?; + occ_data.p_occ.as_ref() + }) + }, + } + } +} + impl PieceRenderInstructions { #[throws(IE)] pub fn map_piece_update_op(&self, ioccults: &IOccults, @@ -91,27 +115,6 @@ impl PieceRenderInstructions { } } - #[throws(IE)] - fn instead<'p>(&self, ioccults: &'p IOccults, p: &'p IPiece) - -> Either - { - match self.occulted { - PriOcculted::Visible(v) => Left(v), - PriOcculted::Occulted | PriOcculted::Displaced(..) => { - Right({ - let occilk = p.occilk.as_ref() - .ok_or_else(|| internal_logic_error(format!( - "occulted non-occultable {:?}", p)))? - .borrow(); - let occ_data = ioccults.ilks.get(occilk) - .ok_or_else(|| internal_logic_error(format!( - "occulted ilk vanished {:?} {:?}", p, occilk)))?; - occ_data.p_occ.as_ref() - }) - }, - } - } - pub fn angle(&self, gpc: &GPiece) -> VisiblePieceAngle { match self.occulted { PriOcculted::Visible(_) => gpc.angle, @@ -132,7 +135,7 @@ impl PieceRenderInstructions { gpc: &GPiece, ipc: &IPiece) -> Html { let pri = self; - let instead = pri.instead(ioccults, ipc)?; + let instead = pri.occulted.instead(ioccults, ipc)?; let o: &dyn OutlineTrait = match instead { Left(_) => Borrow::::borrow(&ipc.p).dyn_upcast(), @@ -183,7 +186,7 @@ impl PieceRenderInstructions { #[throws(IE)] pub fn describe_fallible(&self, ioccults: &IOccults, gpc: &GPiece, ipc: &IPiece) -> Html { - match self.instead(ioccults, ipc)? { + match self.occulted.instead(ioccults, ipc)? { Left(_y) => ipc.p.describe_html(gpc)?, Right(i) => i.describe_html()?, }