#[serde(default)] pub edges: ColourMap,
#[serde(default="default_edge_width")] pub edge_width: f64,
pub itemname: String,
- pub outline: Box<dyn Outline>,
+ pub outline: OutlineRepr,
}
pub const SELECT_SCALE: f64 = 1.1;
-x*0.5, -y*0.5, x, y, -x))
}
-#[typetag::serde]
impl Outline for SimpleShape {
delegate! {
to self.outline {
#[throws(SpecError)]
fn new(desc: Html, path: Html,
- outline: Box<dyn Outline>,
+ outline: OutlineRepr,
def_itemname: &'_ str,
common: &SimpleCommon)
-> SimpleShape
(SimpleShape::new(
Html::lit("disc"),
svg_circle_path(self.diam as f64)?,
- Box::new(outline),
+ outline.into(),
"simple-disc",
&self.common,
)?, &self.common)
impl SimplePieceSpec for piece_specs::Square {
#[throws(SpecError)]
fn load_raw(&self) -> (SimpleShape, &SimpleCommon) {
- let outline = shapelib::Square { xy: self.xy()?.map(|v| v as f64) };
+ let outline = shapelib::Rectangle { xy: self.xy()?.map(|v| v as f64) };
(SimpleShape::new(
Html::lit("square"),
svg_rectangle_path(self.xy()?.promote())?,
- Box::new(outline),
+ outline.into(),
"simple-square",
&self.common,
)?, &self.common)
#[typetag::deserialize(tag="outline")]
pub trait OutlineDefn: Debug + Sync + Send {
fn check(&self, lgi: &GroupData) -> Result<(),LLE>;
- fn load(&self, lgi: &GroupData) -> Result<Box<dyn Outline>,IE>;
+ fn load(&self, lgi: &GroupData) -> Result<OutlineRepr,IE>;
}
#[derive(Debug)]
desc_hidden: DescId,
svgs: IndexVec<SvgId, Html>,
descs: IndexVec<DescId, Html>,
- outline: Box<dyn Outline>,
+ outline: OutlineRepr,
}
#[derive(Debug,Clone,Serialize,Deserialize,Eq,PartialEq,Ord,PartialOrd)]
}
}
-#[typetag::serde(name="Lib")]
impl Outline for Item { delegate! { to self.outline {
fn surround_path(&self, pri: &PieceRenderInstructions) -> Result<Html, IE>;
fn thresh_dragraise(&self, pri: &PieceRenderInstructions)
}
}
-#[derive(Serialize,Deserialize,Debug)]
+#[derive(Clone,Copy,Debug,Serialize,Deserialize)]
pub struct Circle { pub diam: f64 }
-#[typetag::serde(name="Circle")]
impl Outline for Circle {
#[throws(IE)]
fn surround_path(&self, _pri: &PieceRenderInstructions) -> Html {
impl OutlineDefn for CircleDefn {
#[throws(LibraryLoadError)]
fn check(&self, lgd: &GroupData) { Self::get_size(lgd)?; }
- fn load(&self, lgd: &GroupData) -> Result<Box<dyn Outline>,IE> {
- Ok(Box::new(Circle {
+ fn load(&self, lgd: &GroupData) -> Result<OutlineRepr,IE> {
+ Ok(Circle {
diam: Self::get_size(lgd).map_err(|e| e.ought())?,
- }))
+ }.into())
}
}
impl CircleDefn {
}
}
-#[derive(Serialize,Deserialize,Debug)]
-pub struct Square { pub xy: PosC<f64> }
+#[derive(Clone,Copy,Debug,Serialize,Deserialize)]
+pub struct Rectangle { pub xy: PosC<f64> }
-#[typetag::serde(name="Square")]
-impl Outline for Square {
+impl Outline for Rectangle {
#[throws(IE)]
fn surround_path(&self, _pri: &PieceRenderInstructions) -> Html {
let size = self.xy * SELECT_SCALE;
impl OutlineDefn for SquareDefn {
#[throws(LibraryLoadError)]
fn check(&self, lgd: &GroupData) { Self::get(lgd)?; }
- fn load(&self, lgd: &GroupData) -> Result<Box<dyn Outline>,IE> {
- Ok(Box::new(
- Self::get(lgd).map_err(|e| e.ought())?
- ))
+ fn load(&self, lgd: &GroupData) -> Result<OutlineRepr,IE> {
+ Ok(
+ Self::get(lgd).map_err(|e| e.ought())?.into()
+ )
}
}
impl SquareDefn {
#[throws(LibraryLoadError)]
- fn get(group: &GroupData) -> Square {
- Square { xy: PosC(
+ fn get(group: &GroupData) -> Rectangle {
+ Rectangle { xy: PosC(
match group.d.size.as_slice() {
&[s] => [s,s],
s if s.len() == 2 => s.try_into().unwrap(),