1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
use super::InnerAtom;
use crate::Layer;
use geo::{Coordinate, Rect};
use std::fmt;

/// An interior feature that just renders a smiley on the front silkscreen.
#[derive(Debug, Clone)]
pub struct Smiley {
    center: Coordinate<f64>,
}

impl Default for Smiley {
    fn default() -> Self {
        Self {
            center: [0., 0.].into(),
        }
    }
}

impl fmt::Display for Smiley {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "smiley(center = {:?})", self.center,)
    }
}

impl super::InnerFeature for Smiley {
    fn name(&self) -> &'static str {
        "smiley"
    }

    fn translate(&mut self, v: Coordinate<f64>) {
        self.center = self.center + v;
    }

    fn atoms(&self) -> Vec<InnerAtom> {
        vec![
            InnerAtom::Circle {
                center: self.center
                    + Coordinate {
                        x: -0.6f64,
                        y: -0.6f64,
                    },
                radius: 0.4,
                layer: Layer::FrontLegend,
            },
            InnerAtom::Circle {
                center: self.center
                    + Coordinate {
                        x: 0.6f64,
                        y: -0.6f64,
                    },
                radius: 0.4,
                layer: Layer::FrontLegend,
            },
            InnerAtom::Rect {
                layer: Layer::FrontLegend,
                rect: Rect::new(
                    self.center
                        + Coordinate {
                            x: -1.4f64,
                            y: 0.15f64,
                        },
                    self.center
                        + Coordinate {
                            x: -1.0f64,
                            y: 0.9f64,
                        },
                ),
            },
            InnerAtom::Rect {
                layer: Layer::FrontLegend,
                rect: Rect::new(
                    self.center
                        + Coordinate {
                            x: -1.0f64,
                            y: 0.6f64,
                        },
                    self.center
                        + Coordinate {
                            x: 1.0f64,
                            y: 0.9f64,
                        },
                ),
            },
            InnerAtom::Rect {
                layer: Layer::FrontLegend,
                rect: Rect::new(
                    self.center
                        + Coordinate {
                            x: 1.0f64,
                            y: 0.9f64,
                        },
                    self.center
                        + Coordinate {
                            x: 1.4f64,
                            y: 0.15f64,
                        },
                ),
            },
        ]
    }
}