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
use super::*;
impl<T> Parallelogram<T> {
pub fn new<P>(anchor: P, side: (P, P)) -> Self
where
Point<T>: From<P>,
{
Self { anchor: anchor.into(), side: (side.0.into(), side.1.into()) }
}
}
impl<T> Parallelogram<T>
where
T: Clone + Num,
{
pub fn vertexes(&self) -> Vec<Point<T>> {
let a = self.anchor.clone();
let b = self.anchor.clone() + &self.side.0;
let c = self.anchor.clone() + &self.side.1;
let d = self.anchor.clone() + &self.side.0 + &self.side.1;
vec![a, b, c, d]
}
pub fn side_edges(&self) -> (Line<T>, Line<T>) {
let a = Line::new(&self.anchor, &self.side.0);
let b = Line::new(&self.anchor, &self.side.1);
(a, b)
}
pub fn is_square(&self) -> bool
where
T: Float,
{
self.is_rectangle() && self.is_diamond()
}
pub fn is_diamond(&self) -> bool
where
T: Float,
{
let (a, b) = self.side_edges();
a.length() == b.length()
}
pub fn is_rectangle(&self) -> bool {
let a = Line::new(&self.anchor, &self.side.0);
let b = Line::new(&self.anchor, &self.side.1);
a.is_orthogonal(&b)
}
}