Skip to main content

shape_core/elements/lines/line_2d/
convert.rs

1use super::*;
2
3impl<T> Line<T> {
4    /// Create a new line from two point
5    #[inline(always)]
6    pub fn new<P>(start: P, end: P) -> Self
7    where
8        Point<T>: From<P>,
9    {
10        Self { s: start.into(), e: end.into() }
11    }
12    /// Create a new line from anchor point and vector
13    pub fn from_anchor<S, V>(start: S, v: V) -> Self
14    where
15        T: Clone + Add<Output = T>,
16        S: Into<Point<T>>,
17        V: Into<Vector<T>>,
18    {
19        let s = start.into();
20        let Vector { dx: vx, dy: vy } = v.into();
21        let e = Point { x: s.x.clone() + vx, y: s.y.clone() + vy };
22        Self { s, e }
23    }
24}