chiark / gitweb /
Move shapelib Outline structs into outline
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 14 May 2022 22:14:24 +0000 (23:14 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 14 May 2022 22:14:24 +0000 (23:14 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/clock.rs
src/imports.rs
src/outline.rs
src/shapelib.rs

index 30aebecb53abe7d3821a5463d7b166d30161f0e1..7e3e42d47cd92fcce5e02ad5b03adac0d541ce99 100644 (file)
@@ -3,7 +3,6 @@
 // There is NO WARRANTY.
 
 use crate::prelude::*;
-use shapelib::RectOutline;
 
 use nix::sys::time::TimeValLike as TVL;
 
index cf03b4446cf4303f572bd96eed0285aeb8eca6ab..a948fb83b18532cffc8d75dbf8d6f166bae9d982 100644 (file)
@@ -101,7 +101,6 @@ pub use crate::pcaliases::*;
 pub use crate::pcrender::*;
 pub use crate::pieces::*;
 pub use crate::shapelib;
-pub use crate::shapelib::{CircleOutline, RectOutline};
 pub use crate::shapelib::{ItemEnquiryData, LibraryEnquiryData};
 pub use crate::shapelib::{LibraryLoadError};
 pub use crate::spec::*;
index ebe25122f4e3eb2421d94b228ff999130fe0790f..d5a06b44bec754a6e3860e3e9a73080ddeaa6b2c 100644 (file)
@@ -15,8 +15,6 @@ macro_rules! shape_defns { {
 } => { paste!{
 
 
-  $( use crate::shapelib::[< $Shape Outline >]; )*
-
   #[dyn_upcast(OutlineTrait)]
   #[enum_dispatch(OutlineTrait)]
   #[derive(Clone,Debug,Serialize,Deserialize)]
@@ -54,3 +52,78 @@ shape_defns! {
   Circle "Circle";
   Rect   "Rect"  ;
 }
+
+
+//---------- Circle ----------
+
+#[derive(Clone,Copy,Debug,Serialize,Deserialize)]
+pub struct CircleOutline { pub diam: f64 }
+
+#[dyn_upcast]
+impl OutlineTrait for CircleOutline {
+  #[throws(IE)]
+  fn outline_path(&self, scale: f64) -> Html {
+    svg_circle_path(self.diam * scale)?
+  }
+  #[throws(IE)]
+  fn thresh_dragraise(&self) -> Option<Coord> {
+    Some((self.diam * 0.5) as Coord)
+  }
+  #[throws(IE)]
+  fn bbox_approx(&self) -> Rect {
+    let d = (self.diam * 0.5).round() as Coord;
+    Rect{ corners: [PosC::new(-d,-d), PosC::new(d, d)]}
+  }
+}
+
+//---------- RectOutline ----------
+
+#[derive(Clone,Copy,Debug,Serialize,Deserialize)]
+pub struct RectOutline { pub xy: PosC<f64> }
+
+impl RectOutline {
+  // Used by code elsewhere eg deck.rs for occultation boundaries etc.
+  #[throws(CoordinateOverflow)]
+  pub fn rect(&self, nominal: Pos) -> RectC<Coord> {
+    let offset = (self.xy * 0.5)?;
+    let offset = offset.try_map(
+      |c| c.floor().to_i32().ok_or(CoordinateOverflow)
+    )?;
+    let rect = RectC{ corners:
+      [-1,1].iter().map(|&signum| Ok::<_,CoordinateOverflow>({
+        (nominal + (offset * signum)?)?
+      }))
+        .collect::<Result<ArrayVec<_,2>,_>>()?
+        .into_inner().unwrap()
+    };
+    rect
+  }
+
+  #[throws(CoordinateOverflow)]
+  pub fn region(&self, nominal: Pos) -> Region {
+    Region::Rect(self.rect(nominal)?)
+  }
+}
+
+#[dyn_upcast]
+impl OutlineTrait for RectOutline {
+  #[throws(IE)]
+  fn outline_path(&self, scale: f64) -> Html {
+    let xy = (self.xy * scale)?;
+    svg_rectangle_path(xy)?
+  }
+  #[throws(IE)]
+  fn thresh_dragraise(&self) -> Option<Coord> {
+    let smallest: f64 = self.xy.coords.iter().cloned()
+      .map(OrderedFloat::from).min().unwrap().into();
+    Some((smallest * 0.5) as Coord)
+  }
+  #[throws(IE)]
+  fn bbox_approx(&self) -> Rect {
+    let pos: Pos = self.xy.map(
+      |v| ((v * 0.5).round()) as Coord
+    );
+    let neg = (-pos)?;
+    Rect{ corners: [ neg, pos ] }
+  }
+}
index 4e3277b7b2c26b6d39c71fe4b17c288eeec9c0dd..1f79415974fba6d1594b8c7df1cccfef77e40cb2 100644 (file)
@@ -813,56 +813,6 @@ impl_via_ambassador!{
 
 //---------- RectOutline ----------
 
-#[derive(Clone,Copy,Debug,Serialize,Deserialize)]
-pub struct RectOutline { pub xy: PosC<f64> }
-
-impl RectOutline {
-  // Used by code elsewhere eg deck.rs for occultation boundaries etc.
-  #[throws(CoordinateOverflow)]
-  pub fn rect(&self, nominal: Pos) -> RectC<Coord> {
-    let offset = (self.xy * 0.5)?;
-    let offset = offset.try_map(
-      |c| c.floor().to_i32().ok_or(CoordinateOverflow)
-    )?;
-    let rect = RectC{ corners:
-      [-1,1].iter().map(|&signum| Ok::<_,CoordinateOverflow>({
-        (nominal + (offset * signum)?)?
-      }))
-        .collect::<Result<ArrayVec<_,2>,_>>()?
-        .into_inner().unwrap()
-    };
-    rect
-  }
-
-  #[throws(CoordinateOverflow)]
-  pub fn region(&self, nominal: Pos) -> Region {
-    Region::Rect(self.rect(nominal)?)
-  }
-}
-
-#[dyn_upcast]
-impl OutlineTrait for RectOutline {
-  #[throws(IE)]
-  fn outline_path(&self, scale: f64) -> Html {
-    let xy = (self.xy * scale)?;
-    svg_rectangle_path(xy)?
-  }
-  #[throws(IE)]
-  fn thresh_dragraise(&self) -> Option<Coord> {
-    let smallest: f64 = self.xy.coords.iter().cloned()
-      .map(OrderedFloat::from).min().unwrap().into();
-    Some((smallest * 0.5) as Coord)
-  }
-  #[throws(IE)]
-  fn bbox_approx(&self) -> Rect {
-    let pos: Pos = self.xy.map(
-      |v| ((v * 0.5).round()) as Coord
-    );
-    let neg = (-pos)?;
-    Rect{ corners: [ neg, pos ] }
-  }
-}
-
 impl ShapeLoadableTrait for RectShapeIndicator {
   fn load(&self, size: PosC<f64>) -> Outline {
     RectOutline { xy: size }.into()
@@ -878,26 +828,6 @@ impl ShapeLoadableTrait for RectShapeIndicator {
 
 //---------- CircleOutline ----------
 
-#[derive(Clone,Copy,Debug,Serialize,Deserialize)]
-pub struct CircleOutline { pub diam: f64 }
-
-#[dyn_upcast]
-impl OutlineTrait for CircleOutline {
-  #[throws(IE)]
-  fn outline_path(&self, scale: f64) -> Html {
-    svg_circle_path(self.diam * scale)?
-  }
-  #[throws(IE)]
-  fn thresh_dragraise(&self) -> Option<Coord> {
-    Some((self.diam * 0.5) as Coord)
-  }
-  #[throws(IE)]
-  fn bbox_approx(&self) -> Rect {
-    let d = (self.diam * 0.5).round() as Coord;
-    Rect{ corners: [PosC::new(-d,-d), PosC::new(d, d)]}
-  }
-}
-
 impl ShapeLoadableTrait for CircleShapeIndicator {
   fn load(&self, size: PosC<f64>) -> Outline {
     let diam = size