shape_core/elements/rectangles/
parallelogram.rs

1use super::*;
2
3impl<T> Parallelogram<T> {
4    pub fn new<P>(anchor: P, side: (P, P)) -> Self
5    where
6        Point<T>: From<P>,
7    {
8        Self { anchor: anchor.into(), side: (side.0.into(), side.1.into()) }
9    }
10}
11
12impl<T> Parallelogram<T>
13where
14    T: Clone + Num,
15{
16    pub fn vertexes(&self) -> Vec<Point<T>> {
17        let a = self.anchor.clone();
18        let b = self.anchor.clone() + &self.side.0;
19        let c = self.anchor.clone() + &self.side.1;
20        let d = self.anchor.clone() + &self.side.0 + &self.side.1;
21        vec![a, b, c, d]
22    }
23    pub fn side_edges(&self) -> (Line<T>, Line<T>) {
24        let a = Line::new(&self.anchor, &self.side.0);
25        let b = Line::new(&self.anchor, &self.side.1);
26        (a, b)
27    }
28    /// Check if the parallelogram is a square_2d
29    pub fn is_square(&self) -> bool
30    where
31        T: Float,
32    {
33        self.is_rectangle() && self.is_diamond()
34    }
35    /// Check if the parallelogram is a diamond
36    pub fn is_diamond(&self) -> bool
37    where
38        T: Float,
39    {
40        let (a, b) = self.side_edges();
41        a.length() == b.length()
42    }
43    /// Check if the parallelogram is a rectangle_2d
44    pub fn is_rectangle(&self) -> bool {
45        let a = Line::new(&self.anchor, &self.side.0);
46        let b = Line::new(&self.anchor, &self.side.1);
47        a.is_orthogonal(&b)
48    }
49}