maker_panel/features/
screw_hole.rs

1use super::InnerAtom;
2use crate::Layer;
3use geo::Coordinate;
4use std::fmt;
5
6/// An interior feature representing a receptical for a fastener.
7#[derive(Debug, Clone)]
8pub struct ScrewHole {
9    center: Coordinate<f64>,
10    drill_radius: f64,
11    annular_ring_radius: f64,
12}
13
14impl ScrewHole {
15    /// Creates a screw hole with the specified diameter.
16    pub fn with_diameter(dia: f64) -> Self {
17        Self {
18            drill_radius: dia / 2.0,
19            annular_ring_radius: (dia / 2.0) + 1.25,
20            ..Self::default()
21        }
22    }
23}
24
25impl Default for ScrewHole {
26    fn default() -> Self {
27        Self {
28            center: [0., 0.].into(),
29            drill_radius: 1.55,
30            annular_ring_radius: 2.75,
31        }
32    }
33}
34
35impl fmt::Display for ScrewHole {
36    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
37        write!(
38            f,
39            "drill(center = {:?}, {}/{})",
40            self.center, self.drill_radius, self.annular_ring_radius
41        )
42    }
43}
44
45impl super::InnerFeature for ScrewHole {
46    fn name(&self) -> &'static str {
47        "screw_hole"
48    }
49
50    fn translate(&mut self, v: Coordinate<f64>) {
51        self.center = self.center + v;
52    }
53
54    fn atoms(&self) -> Vec<InnerAtom> {
55        vec![
56            InnerAtom::Circle {
57                center: self.center,
58                radius: self.annular_ring_radius,
59                layer: Layer::BackCopper,
60            },
61            InnerAtom::Circle {
62                center: self.center,
63                radius: self.annular_ring_radius,
64                layer: Layer::BackMask,
65            },
66            InnerAtom::Circle {
67                center: self.center,
68                radius: self.annular_ring_radius,
69                layer: Layer::FrontCopper,
70            },
71            InnerAtom::Circle {
72                center: self.center,
73                radius: self.annular_ring_radius,
74                layer: Layer::FrontMask,
75            },
76            InnerAtom::Drill {
77                center: self.center,
78                radius: self.drill_radius,
79                plated: true,
80            },
81        ]
82    }
83}