chiark / gitweb /
refactor: drop PieceRenderInstructions from Outline
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 28 Feb 2021 12:58:54 +0000 (12:58 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 28 Feb 2021 12:58:54 +0000 (12:58 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/otterlib.rs
src/gamestate.rs
src/hand.rs
src/pieces.rs
src/shapelib.rs

index e55ece7e179c3eec4ccfa2dbb2460e12e74b492f..a4200693af6a7ab90f656ebdbfead77a6e3b6c94 100644 (file)
@@ -169,7 +169,7 @@ fn preview(items: Vec<ItemForOutput>) {
           .join(" ");
         let wh = size.iter().map(|&s| s * SVG_SCALE)
           .collect::<Vec<_>>();
-        let surround = pc.surround_path(&pri)?;
+        let surround = pc.surround_path()?;
         print!(r#"<svg xmlns="http://www.w3.org/2000/svg"
                        viewBox="{}" width={} height={}>"#,
                &viewport, wh[0], wh[1]);
index cdb7ed6466f77f96b5a188279cf482a1896ed1b3..9b702ae7872209937c5752837bd7a5b1653f03d2 100644 (file)
@@ -112,13 +112,11 @@ impl_downcast!(PieceXData);
 
 #[enum_dispatch]
 pub trait OutlineTrait: Send + Debug {
-  fn outline_path(&self, pri: &PieceRenderInstructions, scale: f64)
-          -> Result<Html, IE>;
-  fn surround_path(&self, pri: &PieceRenderInstructions) -> Result<Html, IE> {
-    self.outline_path(pri, SELECT_SCALE)
+  fn outline_path(&self, scale: f64) -> Result<Html, IE>;
+  fn surround_path(&self) -> Result<Html, IE> {
+    self.outline_path(SELECT_SCALE)
   }
-  fn thresh_dragraise(&self, pri: &PieceRenderInstructions)
-                      -> Result<Option<Coord>, IE>;
+  fn thresh_dragraise(&self) -> Result<Option<Coord>, 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##"</g>"##)?;
     write!(&mut defs.0,
            r##"<path id="surround{}" d="{}"/>"##,
-           pri.id, p.surround_path(pri)?.0)?;
+           pri.id, p.surround_path()?.0)?;
     defs
   }
   inner(self, gpc, p.borrow())?
index e5643ea242a5c0f8342c1265ad6b69c711903824..be2ce4ef461ce4468a047b3b249244f1579eb527 100644 (file)
@@ -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<Html,IE>;
-      fn thresh_dragraise(&self, _pri: &PieceRenderInstructions)
-                          -> Result<Option<Coord>,IE>;
+      fn outline_path(&self, scale: f64) -> Result<Html,IE>;
+      fn thresh_dragraise(&self) -> Result<Option<Coord>,IE>;
       fn bbox_approx(&self) -> Result<[Pos;2], IE>;
     }
   }
index 4615c79f9c0928a0117cb87b8b55e0c610a6f6f7..d03beacf6882eaafeb570d0a5e46bdf2e63a5cee 100644 (file)
@@ -117,10 +117,8 @@ impl<Desc, Outl> OutlineTrait for GenericSimpleShape<Desc, Outl>
 {
   delegate! {
     to self.outline {
-      fn outline_path(&self, _pri: &PieceRenderInstructions, scale: f64)
-                       -> Result<Html,IE>;
-      fn thresh_dragraise(&self, _pri: &PieceRenderInstructions)
-                          -> Result<Option<Coord>,IE>;
+      fn outline_path(&self, scale: f64) -> Result<Html,IE>;
+      fn thresh_dragraise(&self) -> Result<Option<Coord>,IE>;
       fn bbox_approx(&self) -> Result<[Pos;2], IE>;
     }
   }
@@ -211,7 +209,7 @@ impl<Desc, Outl> GenericSimpleShape<Desc, Outl>
         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,
index a7e68a36b93ae11f2a4436c9fda41f393189b467..45b084b43aa9c9aaf6368584b4013f273bce25a6 100644 (file)
@@ -143,10 +143,8 @@ impl ItemEnquiryData {
 }
 
 impl OutlineTrait for Item { delegate! { to self.outline {
-  fn outline_path(&self, pri: &PieceRenderInstructions, scale: f64)
-                  -> Result<Html, IE>;
-  fn thresh_dragraise(&self, pri: &PieceRenderInstructions)
-                      -> Result<Option<Coord>, IE>;
+  fn outline_path(&self, scale: f64) -> Result<Html, IE>;
+  fn thresh_dragraise(&self) -> Result<Option<Coord>, 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<Coord> {
+  fn thresh_dragraise(&self) -> Option<Coord> {
     Some((self.diam * 0.5) as Coord)
   }
   #[throws(IE)]
@@ -540,13 +538,12 @@ pub struct Rectangle { pub xy: PosC<f64> }
 
 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<Coord> {
+  fn thresh_dragraise(&self) -> Option<Coord> {
     let smallest: f64 = self.xy.0.iter().cloned()
       .map(OrderedFloat::from).min().unwrap().into();
     Some((smallest * 0.5) as Coord)