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
use super::*;

impl<T> Square<T>
where
    T: Num + Clone,
{
    pub fn new(x: T, y: T, side: T) -> Self {
        Self { x, y, s: side }
    }
    pub fn from_anchor<P>(anchor: P, side: T) -> Self
    where
        Point<T>: From<P>,
    {
        let Point { x, y } = anchor.into();
        Self { x, y, s: side }
    }

    pub fn from_center<P>(center: P, side: T) -> Self
    where
        Point<T>: From<P>,
    {
        let Point { x: x0, y: y0 } = center.into();
        let Point { x, y } = Point::new(x0 - side.clone() / two(), y0 - side.clone() / two());
        Self { x, y, s: side }
    }
}