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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
use super::InnerAtom;
use geo::{Coordinate, MultiPolygon};
use std::fmt;
#[derive(Debug, Clone)]
pub struct RMount {
direction: crate::Direction,
rect: geo::Rect<f64>,
depth: f64,
}
impl RMount {
pub fn new(depth: f64) -> Self {
let direction = crate::Direction::Up;
let tl: Coordinate<f64> = [-3.15f64, -depth / 2. - 1.].into();
let br: Coordinate<f64> = [3.15f64, depth / 2. + 1.].into();
let rect = geo::Rect::new(tl, br);
Self {
direction,
rect,
depth,
}
}
pub fn direction(self, direction: crate::Direction) -> Self {
Self { direction, ..self }
}
}
impl fmt::Display for RMount {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "rmount({:?}, {:?})", self.rect.min(), self.rect.max(),)
}
}
impl super::Feature for RMount {
fn name(&self) -> &'static str {
"rmount"
}
fn edge_union(&self) -> Option<MultiPolygon<f64>> {
let out = self.rect.clone().to_polygon().into();
use geo::algorithm::rotate::Rotate;
match self.direction {
crate::Direction::Up => Some(out),
crate::Direction::Down => Some(out.rotate(180.)),
crate::Direction::Left => Some(out.rotate(-90.)),
crate::Direction::Right => Some(out.rotate(90.)),
}
}
fn edge_subtract(&self) -> Option<MultiPolygon<f64>> {
use geo_booleanop::boolean::BooleanOp;
let center = self.rect.center();
let channel = geo::Rect::new(
Coordinate::<f64>::from([-1.75f64, -self.depth / 2. - 1.]) + center,
Coordinate::<f64>::from([1.75f64, self.depth / 2.]) + center,
);
let nut = geo::Rect::new(
Coordinate::<f64>::from([-3.12f64, -1.4]) + center,
Coordinate::<f64>::from([3.12f64, 1.4]) + center,
);
let out = MultiPolygon::<f64>::from(channel.to_polygon()).union(&nut.to_polygon());
use geo::algorithm::rotate::Rotate;
match self.direction {
crate::Direction::Up => Some(out),
crate::Direction::Down => Some(out.rotate(180.)),
crate::Direction::Left => Some(out.rotate(-90.)),
crate::Direction::Right => Some(out.rotate(90.)),
}
}
fn translate(&mut self, v: Coordinate<f64>) {
use geo::algorithm::translate::Translate;
self.rect.translate_inplace(v.x, v.y);
}
fn interior(&self) -> Vec<super::InnerAtom> {
let center = self.rect.center();
let angle = match self.direction {
crate::Direction::Up => 0.,
crate::Direction::Down => 180.,
crate::Direction::Left => -90.,
crate::Direction::Right => 90.,
};
let origin = geo::Point::new(0., 0.);
use geo::algorithm::rotate::RotatePoint;
vec![
InnerAtom::Drill {
center: (geo::Point::from([-3.08f64, -1.32]).rotate_around_point(angle, origin)
+ center.into())
.into(),
radius: 0.15,
plated: false,
},
InnerAtom::Drill {
center: (geo::Point::from([3.08f64, -1.32]).rotate_around_point(angle, origin)
+ center.into())
.into(),
radius: 0.15,
plated: false,
},
InnerAtom::Drill {
center: (geo::Point::from([-3.08f64, 1.32]).rotate_around_point(angle, origin)
+ center.into())
.into(),
radius: 0.15,
plated: false,
},
InnerAtom::Drill {
center: (geo::Point::from([3.08f64, 1.32]).rotate_around_point(angle, origin)
+ center.into())
.into(),
radius: 0.15,
plated: false,
},
]
}
}