From: Ian Jackson Date: Sun, 28 Feb 2021 12:58:54 +0000 (+0000) Subject: refactor: drop PieceRenderInstructions from Outline X-Git-Tag: otter-0.4.0~285 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=a64a610bb243b36ab7fd479cb0656ce5bc0622e3;p=otter.git refactor: drop PieceRenderInstructions from Outline Signed-off-by: Ian Jackson --- diff --git a/src/bin/otterlib.rs b/src/bin/otterlib.rs index e55ece7e..a4200693 100644 --- a/src/bin/otterlib.rs +++ b/src/bin/otterlib.rs @@ -169,7 +169,7 @@ fn preview(items: Vec) { .join(" "); let wh = size.iter().map(|&s| s * SVG_SCALE) .collect::>(); - let surround = pc.surround_path(&pri)?; + let surround = pc.surround_path()?; print!(r#""#, &viewport, wh[0], wh[1]); diff --git a/src/gamestate.rs b/src/gamestate.rs index cdb7ed64..9b702ae7 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -112,13 +112,11 @@ impl_downcast!(PieceXData); #[enum_dispatch] pub trait OutlineTrait: Send + Debug { - fn outline_path(&self, pri: &PieceRenderInstructions, scale: f64) - -> Result; - fn surround_path(&self, pri: &PieceRenderInstructions) -> Result { - self.outline_path(pri, SELECT_SCALE) + fn outline_path(&self, scale: f64) -> Result; + fn surround_path(&self) -> Result { + self.outline_path(SELECT_SCALE) } - fn thresh_dragraise(&self, pri: &PieceRenderInstructions) - -> Result, IE>; + fn thresh_dragraise(&self) -> Result, IE>; fn bbox_approx(&self) -> Result<[Pos;2], IE>; } @@ -379,7 +377,7 @@ impl PieceRenderInstructions { let PriOccluded::Visible = pri.occluded; let mut defs = Html(String::new()); - let dragraise = match p.thresh_dragraise(pri)? { + let dragraise = match p.thresh_dragraise()? { Some(n) if n < 0 => throw!(SvgE::NegativeDragraise), Some(n) => n, None => -1, @@ -392,7 +390,7 @@ impl PieceRenderInstructions { write!(&mut defs.0, r##""##)?; write!(&mut defs.0, r##""##, - pri.id, p.surround_path(pri)?.0)?; + pri.id, p.surround_path()?.0)?; defs } inner(self, gpc, p.borrow())? diff --git a/src/hand.rs b/src/hand.rs index e5643ea2..be2ce4ef 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -38,10 +38,8 @@ impl PieceXData for HandState { } impl OutlineTrait for Hand { delegate!{ to self.shape { - fn outline_path(&self, _pri: &PieceRenderInstructions, scale: f64) - -> Result; - fn thresh_dragraise(&self, _pri: &PieceRenderInstructions) - -> Result,IE>; + fn outline_path(&self, scale: f64) -> Result; + fn thresh_dragraise(&self) -> Result,IE>; fn bbox_approx(&self) -> Result<[Pos;2], IE>; } } diff --git a/src/pieces.rs b/src/pieces.rs index 4615c79f..d03beacf 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -117,10 +117,8 @@ impl OutlineTrait for GenericSimpleShape { delegate! { to self.outline { - fn outline_path(&self, _pri: &PieceRenderInstructions, scale: f64) - -> Result; - fn thresh_dragraise(&self, _pri: &PieceRenderInstructions) - -> Result,IE>; + fn outline_path(&self, scale: f64) -> Result; + fn thresh_dragraise(&self) -> Result,IE>; fn bbox_approx(&self) -> Result<[Pos;2], IE>; } } @@ -211,7 +209,7 @@ impl GenericSimpleShape write!(f, "{}", otherwise) } }; - let path = self.outline_path(pri, 1.0)?; + let path = self.outline_path(1.0)?; if self.colours.len() == 0 { write!(f, diff --git a/src/shapelib.rs b/src/shapelib.rs index a7e68a36..45b084b4 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -143,10 +143,8 @@ impl ItemEnquiryData { } impl OutlineTrait for Item { delegate! { to self.outline { - fn outline_path(&self, pri: &PieceRenderInstructions, scale: f64) - -> Result; - fn thresh_dragraise(&self, pri: &PieceRenderInstructions) - -> Result, IE>; + fn outline_path(&self, scale: f64) -> Result; + fn thresh_dragraise(&self) -> Result, IE>; fn bbox_approx(&self) -> Result<[Pos; 2], IE>; }}} @@ -498,11 +496,11 @@ pub struct Circle { pub diam: f64 } impl OutlineTrait for Circle { #[throws(IE)] - fn outline_path(&self, _pri: &PieceRenderInstructions, scale: f64) -> Html { + fn outline_path(&self, scale: f64) -> Html { svg_circle_path(self.diam * scale)? } #[throws(IE)] - fn thresh_dragraise(&self, _pri: &PieceRenderInstructions) -> Option { + fn thresh_dragraise(&self) -> Option { Some((self.diam * 0.5) as Coord) } #[throws(IE)] @@ -540,13 +538,12 @@ pub struct Rectangle { pub xy: PosC } impl OutlineTrait for Rectangle { #[throws(IE)] - fn outline_path(&self, _pri: &PieceRenderInstructions, scale: f64) -> Html { + fn outline_path(&self, scale: f64) -> Html { let xy = (self.xy * scale)?; svg_rectangle_path(xy)? } #[throws(IE)] - fn thresh_dragraise(&self, _pri: &PieceRenderInstructions) - -> Option { + fn thresh_dragraise(&self) -> Option { let smallest: f64 = self.xy.0.iter().cloned() .map(OrderedFloat::from).min().unwrap().into(); Some((smallest * 0.5) as Coord)