glifparser/outline/
quad_to_cubic.rs

1use crate::point::PointLike;
2
3pub trait QuadToCubic<QCO: Default, const N: usize> {
4    fn quad_to_cubic(self) -> [QCO; N];
5}
6
7// This method of Quad->Cubic conversion is used all over the place in FontForge.
8impl<QCO> QuadToCubic<QCO, 4> for [QCO; 3] where QCO: PointLike + Default {
9    fn quad_to_cubic(self) -> [QCO; 4] {
10        let [p0_o, p1_o, p2_o] = self;
11        let (mut p1, mut p2): (QCO, QCO) = Default::default();
12        p1.set_x( p0_o.x() + (2./3.) * (p1_o.x()-p0_o.x()) );
13        p1.set_y( p0_o.y() + (2./3.) * (p1_o.y()-p0_o.y()) );
14        p2.set_x( p2_o.x() + (2./3.) * (p1_o.x()-p2_o.x()) );
15        p2.set_y( p2_o.y() + (2./3.) * (p1_o.y()-p2_o.y()) );
16        let (p0, p3) = (p0_o, p2_o);
17        [p0, p1, p2, p3]
18    }
19}