chiark / gitweb /
Rect[Shape]: rename from Rectangle and from Square
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 25 Mar 2021 13:08:46 +0000 (13:08 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 25 Mar 2021 13:08:46 +0000 (13:08 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
14 files changed:
library/cards-oxymoron.toml
library/edited.toml
library/wikimedia.toml
specs/demo.game.toml
specs/mao.game.toml
specs/penultima.game.toml
src/clock.rs
src/deck.rs
src/hand.rs
src/pieces.rs
src/prelude.rs
src/shapelib-toml.rs
src/shapelib.rs
src/spec.rs

index f354e010c7341da5a01d3cd13638e0d89b0bba22..9b3b46b1b3b4d9972c75b6c47ffe9bc73b6a15de 100644 (file)
@@ -10,7 +10,7 @@ filename_suffix = ".gif"
 
 [group.clubs]
 item_prefix = "card-oxymoron-"
-outline = "Square"
+outline = "Rect"
 size = [73, 97]
 centre = [36.5, 48.5]
 scale = 0.25
index 34ce30fd180c3a99b6d5db0e290a0df9e266a92a..e2b5411c51bcb0f07cb9dc34e1c70e2c512a1fe2 100644 (file)
@@ -8,7 +8,7 @@ method = "none"
 [group.chess-board]
 size = [242, 246]
 scale = 0.38
-outline = "Square"
+outline = "Rect"
 files = """
 chess-board    -       the chessboard
 """
index a2093f83bb4c65652a882d959f7924cef2691ccf..d26f95d0735d33ce16bc7cabeba2a1cb180c3ad0 100644 (file)
@@ -112,7 +112,7 @@ files = """
 """
 
 [group.misc]
-outline = "Square"
+outline = "Rect"
 size = [448,326]
 centre = [224, 163]
 scale = 0.025
@@ -121,7 +121,7 @@ mgmt-library-load-marker   Box_with_polygons        a library load area marker
 """
 
 [group.card-backs]
-outline = "Square"
+outline = "Rect"
 size = [73, 97]
 
 # sizes to match cards-oxymoron:
@@ -136,7 +136,7 @@ card-rainbow                Card_back_13    a rainbow card
 """
 
 [group.cards-bellot]
-outline = "Square"
+outline = "Rect"
 size = [73, 97]
 
 # sizes to match cards-oxymoron:
index 8ed1fb0faa5cb4f5c769e697b1234461d5ec0021..c8cb6807ddba56f6627bfece606e2626c9959961 100644 (file)
@@ -13,7 +13,7 @@ edges = ["black","white"]
 
 [[pieces]]
 pos = [90, 20]
-type = "Square"
+type = "Rect"
 size = [10]
 angle.Compass = 1
 faces = ["blue", "grey"]
@@ -33,7 +33,7 @@ item = "chess-b-N"
 
 [[pieces]]
 pos = [120, 30]
-type = "Square"
+type = "Rect"
 size = [10]
 angle.Compass = 1
 faces = [ ]
@@ -45,7 +45,7 @@ pos = [40, 40]
 type = "Hand"
 edge = "white"
 colour = "grey"
-shape.type = "Rectangle"
+shape.type = "Rect"
 shape.xy = [70,20]
 
 [[pieces]]
index 57c4b3fa1dc96d725a55bbc41c36650bfc376310..cad206c28c1ab6bd4b15bfaa733579e18938529d 100644 (file)
@@ -12,7 +12,7 @@ faces = ["lightblue", "grey"]
 edges = ["black", "white"]
 label.colour = "black"
 label.place = "BottomLeftOutside"
-shape.type = "Rectangle"
+shape.type = "Rect"
 shape.xy = [25,30]
 
 [[pieces]]
@@ -22,7 +22,7 @@ faces = ["lightblue", "grey"]
 edges = ["black", "white"]
 label.colour = "black"
 label.place = "BottomLeftOutside"
-shape.type = "Rectangle"
+shape.type = "Rect"
 shape.xy = [25,30]
 
 [[pieces]]
@@ -32,7 +32,7 @@ faces = ["lightblue", "grey"]
 edges = ["black", "white"]
 label.place = "TopLeftOutside"
 label.colour = "black"
-shape.type = "Rectangle"
+shape.type = "Rect"
 shape.xy = [25,30]
 
 
@@ -107,7 +107,7 @@ label.colour = "black"
 type = "Hand"
 edge = "white"
 edge_width = 0.75
-shape.type = "Rectangle"
+shape.type = "Rect"
 shape.xy = [97,25]
 
 [[pieces]]
@@ -119,7 +119,7 @@ label.colour = "black"
 type = "Hand"
 edge = "white"
 edge_width = 0.75
-shape.type = "Rectangle"
+shape.type = "Rect"
 shape.xy = [97,25]
 
 [[pieces]]
@@ -131,7 +131,7 @@ label.colour = "black"
 type = "Hand"
 edge = "white"
 edge_width = 0.75
-shape.type = "Rectangle"
+shape.type = "Rect"
 shape.xy = [97,25]
 
 [[pieces]]
@@ -143,7 +143,7 @@ label.colour = "black"
 type = "Hand"
 edge = "darkgrey"
 edge_width = 1.0
-shape.type = "Rectangle"
+shape.type = "Rect"
 shape.xy = [97,25]
 
 [[pieces]]
@@ -155,7 +155,7 @@ label.colour = "black"
 type = "Hand"
 edge = "white"
 edge_width = 0.75
-shape.type = "Rectangle"
+shape.type = "Rect"
 shape.xy = [97,25]
 
 [[pieces]]
@@ -167,7 +167,7 @@ label.colour = "black"
 type = "Hand"
 edge = "white"
 edge_width = 0.75
-shape.type = "Rectangle"
+shape.type = "Rect"
 shape.xy = [97,25]
 
 [[pieces]]
@@ -179,7 +179,7 @@ label.colour = "black"
 type = "Hand"
 edge = "white"
 edge_width = 0.75
-shape.type = "Rectangle"
+shape.type = "Rect"
 shape.xy = [97,25]
 
 [[pieces]]
@@ -191,7 +191,7 @@ label.colour = "black"
 type = "Hand"
 edge = "white"
 edge_width = 0.75
-shape.type = "Rectangle"
+shape.type = "Rect"
 shape.xy = [97,25]
 
 [[pieces]]
@@ -203,7 +203,7 @@ label.colour = "black"
 type = "Hand"
 edge = "white"
 edge_width = 0.75
-shape.type = "Rectangle"
+shape.type = "Rect"
 shape.xy = [97,25]
 
 [[pieces]]
@@ -215,5 +215,5 @@ label.colour = "black"
 type = "Hand"
 edge = "darkgrey"
 edge_width = 1.0
-shape.type = "Rectangle"
+shape.type = "Rect"
 shape.xy = [97,25]
index 283ac981b15bae0f76dc3857af6a7752dc0418b1..f57902d1b3b99a8b2f918e6954f8b090d83d755f 100644 (file)
@@ -55,7 +55,7 @@ count = 8
 
 [[pieces]]
 pos = [20, 85]
-type = "Square"
+type = "Rect"
 faces = ["yellow","#f4f"]
 posd = [10, 0]
 size = [7,7]
@@ -63,7 +63,7 @@ count = 8
 
 [[pieces]]
 pos = [20, 95]
-type = "Square"
+type = "Rect"
 faces = ["#333"]
 posd = [10, 0]
 size = [9,1]
@@ -71,7 +71,7 @@ count = 8
 
 [[pieces]]
 pos = [20, 100]
-type = "Square"
+type = "Rect"
 faces = ["#333"]
 posd = [10, 0]
 size = [9,1]
@@ -79,7 +79,7 @@ count = 8
 
 [[pieces]]
 pos = [17, 110]
-type = "Square"
+type = "Rect"
 faces = ["#333"]
 posd = [5, 0]
 size = [1,9]
@@ -190,7 +190,7 @@ pos = [20, 60]
 type = "Hand"
 edge = "white"
 colour = "grey"
-shape.type = "Rectangle"
+shape.type = "Rect"
 shape.xy = [20,10]
 
 [[pieces]]
index 174f9133363b2216ce6a8b29480bc924e5fb8a96..0d7fedf4f86610eaba1c925595dc6d944cfb11eb 100644 (file)
@@ -3,7 +3,7 @@
 // There is NO WARRANTY.
 
 use crate::prelude::*;
-use shapelib::Rectangle;
+use shapelib::RectShape;
 
 use nix::sys::time::TimeValLike as TVL;
 
@@ -388,7 +388,7 @@ impl ThreadState {
 
 const W: Coord = 40;
 const H: Coord = 14;
-const OUTLINE: Rectangle = Rectangle { xy: PosC::new(W as f64, H as f64) };
+const OUTLINE: RectShape = RectShape { xy: PosC::new(W as f64, H as f64) };
 
 
 // ==================== piece management, loading, etc. ====================
index 5d6e32945fd2f674429924f645b1a038ac9be435..6a708e10284ead145ee06dd084a904a3066ccd41 100644 (file)
@@ -11,7 +11,7 @@ pub const ENABLED_DESC: &str = "a pickup deck (enabled)";
 
 #[derive(Debug,Serialize,Deserialize)]
 struct Deck {
-  shape: GenericSimpleShape<(), shapelib::Rectangle>,
+  shape: GenericSimpleShape<(), RectShape>,
   label: Option<piece_specs::PieceLabel>,
 }
 
@@ -46,7 +46,7 @@ impl PieceSpec for piece_specs::Deck {
       edge_width: self.edge_width,
     };
     let shape = match self.shape {
-      Outline::Rectangle(r) => r,
+      Outline::RectShape(r) => r,
       _ => throw!(SpecError::UnsupportedShape),
     };
     let shape = GenericSimpleShape::new(
index ea74fe871b16aa3d93d6373efb63e0a0b01bd974..a49ebeee45d16ba4a57b0ec48b6cfb6a61b89434 100644 (file)
@@ -16,7 +16,7 @@ struct MagicOwner {
 
 #[derive(Debug,Serialize,Deserialize)]
 struct Hand {
-  shape: GenericSimpleShape<(), shapelib::Rectangle>,
+  shape: GenericSimpleShape<(), RectShape>,
   label: Option<PieceLabel>,
 }
 
@@ -59,7 +59,7 @@ impl PieceSpec for piece_specs::Hand {
       edge_width: self.edge_width,
     };
     let shape = match self.shape {
-      Outline::Rectangle(r) => r,
+      Outline::RectShape(r) => r,
       _ => throw!(SpecError::UnsupportedShape),
     };
     let shape = GenericSimpleShape::new(
index fed4679efce97e5e43f6b5bd4d9796841697523a..f8f2a65c400ebcc1ce99719ce805b89e709c039b 100644 (file)
@@ -152,7 +152,7 @@ impl PieceTrait for SimpleShape {
 impl piece_specs::PieceLabel {
   #[throws(IE)]
   pub fn svg(&self, f: &mut Html,
-             outline: &shapelib::Rectangle,
+             outline: &RectShape,
              def_colour: Option<&Colour>,
              text: &Html) {
     let colour = {
@@ -281,7 +281,7 @@ pub trait SimplePieceSpec: Debug {
 impl SimplePieceSpec for piece_specs::Disc {
   #[throws(SpecError)]
   fn load_raw(&self) -> (SimpleShape, &SimpleCommon) {
-    let outline = shapelib::Circle { diam: self.diam as f64 };
+    let outline = CircleShape { diam: self.diam as f64 };
     (SimpleShape::new(
       Html::lit("disc"),
       outline.into(),
@@ -300,7 +300,7 @@ impl PieceSpec for piece_specs::Disc {
   }
 }
 
-impl piece_specs::Square {
+impl piece_specs::Rect {
   #[throws(SpecError)]
   fn xy(&self) -> Pos {
     match *self.size.as_slice() {
@@ -312,21 +312,25 @@ impl piece_specs::Square {
 }
 
 #[typetag::serde]
-impl SimplePieceSpec for piece_specs::Square {
+impl SimplePieceSpec for piece_specs::Rect {
   #[throws(SpecError)]
   fn load_raw(&self) -> (SimpleShape, &SimpleCommon) {
-    let outline = shapelib::Rectangle { xy: self.xy()?.map(|v| v as f64) };
+    let outline = RectShape { xy: self.xy()?.map(|v| v as f64) };
+    let desc = Html::lit(
+      if outline.xy.x() == outline.xy.y()
+      { "square" } else { "rectangle" }
+    );
     (SimpleShape::new(
-      Html::lit("square"),
+      desc,
       outline.into(),
-      "simple-square",
+      "simple-rect",
       &self.common,
     )?, &self.common)
   }
 }
 
 #[typetag::serde]
-impl PieceSpec for piece_specs::Square {
+impl PieceSpec for piece_specs::Rect {
   #[throws(SpecError)]
   fn load(&self, _: usize, _: &mut GPiece, _ir: &InstanceRef)
           -> PieceSpecLoaded {
index b927b0c34c0234286b6968aca3908ec3b42df326..523270ccaaa642e9e4b90fa2da3734655aac24c5 100644 (file)
@@ -139,6 +139,7 @@ pub use crate::occultilks::*;
 pub use crate::pcrender::*;
 pub use crate::pieces::*;
 pub use crate::shapelib;
+pub use crate::shapelib::{CircleShape, RectShape};
 pub use crate::slotmap_slot_idx::*;
 pub use crate::spec::*;
 pub use crate::spec::piece_specs::{FaceColourSpecs, SimpleCommon};
index d36e2b0514b6a7ac7c680bfd176cb382c9835dcd..ecbcbd04255c7e69da605ed79c2137c384d59bc8 100644 (file)
@@ -153,7 +153,7 @@ pub struct GroupDetails {
   /// If specified, pieces in this group can be occulted.
   pub occulted: Option<OccultationMethod>,
 
-  /// One of `"Circle"` or `"Square"`, to define the outline shape.
+  /// One of `"Circle"` or `"Rect"`, to define the outline shape.
   /// The size is taken from `size`.
   ///
   /// This value is a string, not some weird Rust type, despite
index ae3979398a166ccfb3fdc8bd08193ef337db5884..e2b4bb3528c698d3f5af5d396d37a36a6d3c8ae6 100644 (file)
@@ -735,10 +735,10 @@ pub fn load(libs: &Vec<Config1>) {
 }
 
 #[derive(Clone,Copy,Debug,Serialize,Deserialize)]
-pub struct Circle { pub diam: f64 }
+pub struct CircleShape { pub diam: f64 }
 
 #[dyn_upcast]
-impl OutlineTrait for Circle {
+impl OutlineTrait for CircleShape {
   #[throws(IE)]
   fn outline_path(&self, scale: f64) -> Html {
     svg_circle_path(self.diam * scale)?
@@ -761,7 +761,7 @@ impl OutlineDefn for CircleDefn {
   #[throws(LibraryLoadError)]
   fn check(&self, lgd: &GroupData) { Self::get_size(lgd)?; }
   fn load(&self, lgd: &GroupData) -> Result<Outline,IE> {
-    Ok(Circle {
+    Ok(CircleShape {
       diam: Self::get_size(lgd).map_err(|e| e.ought())?,
     }.into())
   }
@@ -778,9 +778,9 @@ impl CircleDefn {
 }
 
 #[derive(Clone,Copy,Debug,Serialize,Deserialize)]
-pub struct Rectangle { pub xy: PosC<f64> }
+pub struct RectShape { pub xy: PosC<f64> }
 
-impl Rectangle {
+impl RectShape {
   #[throws(CoordinateOverflow)]
   pub fn rect(&self, centre: Pos) -> RectC<Coord> {
     let offset = (self.xy * 0.5)?;
@@ -804,7 +804,7 @@ impl Rectangle {
 }
 
 #[dyn_upcast]
-impl OutlineTrait for Rectangle {
+impl OutlineTrait for RectShape {
   #[throws(IE)]
   fn outline_path(&self, scale: f64) -> Html {
     let xy = (self.xy * scale)?;
@@ -827,9 +827,9 @@ impl OutlineTrait for Rectangle {
 }
 
 #[derive(Deserialize,Debug)]
-struct SquareDefn { }
-#[typetag::deserialize(name="Square")]
-impl OutlineDefn for SquareDefn {
+struct RectDefn { }
+#[typetag::deserialize(name="Rect")]
+impl OutlineDefn for RectDefn {
   #[throws(LibraryLoadError)]
   fn check(&self, lgd: &GroupData) { Self::get(lgd)?; }
   fn load(&self, lgd: &GroupData) -> Result<Outline,IE> {
@@ -838,10 +838,10 @@ impl OutlineDefn for SquareDefn {
     )
   }
 }
-impl SquareDefn {
+impl RectDefn {
   #[throws(LibraryLoadError)]
-  fn get(group: &GroupData) -> Rectangle {
-    Rectangle { xy: PosC{ coords:
+  fn get(group: &GroupData) -> RectShape {
+    RectShape { xy: PosC{ coords:
       match group.d.size.as_slice() {
         &[s] => [s,s],
         s if s.len() == 2 => s.try_into().unwrap(),
index f1fa845ca249a5109f403823507a45cfec9ca3aa..fca2ab6b9855ff134382b842a945ca2deb906a46 100644 (file)
@@ -193,14 +193,14 @@ pub struct CompassAngle(u8);
 mod outline {
   use super::*;
   use crate::prelude::*;
-  use crate::shapelib::{Circle, Rectangle};
+  use crate::shapelib::{CircleShape, RectShape};
   #[dyn_upcast(OutlineTrait)]
   #[enum_dispatch(OutlineTrait)]
   #[derive(Clone,Debug,Serialize,Deserialize)]
   #[serde(tag="type")]
   pub enum Outline {
-    Circle,
-    #[serde(alias="Square")] Rectangle,
+    #[serde(rename="Circle")] CircleShape,
+    #[serde(rename="Rect")]   RectShape,
   }
 }
 pub use outline::*;
@@ -226,7 +226,7 @@ pub mod piece_specs {
   }
 
   #[derive(Debug,Serialize,Deserialize)]
-  pub struct Square {
+  pub struct Rect {
     pub size: Vec<Coord>,
     #[serde(flatten)]
     pub common: SimpleCommon,