Skip to content

Commit

Permalink
Fix QuadToCubic trait, changed recently for #20
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlcctrlv committed Jan 13, 2022
1 parent ee7f0e8 commit 945f0aa
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/outline/quad_to_cubic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ pub trait QuadToCubic<QCO: FromKurboPoint + ToKurboPoint, const N: usize> {
fn quad_to_cubic(self) -> [QCO; N];
}

// This method of Quad->Cubic conversion is used all over the place in FontForge.
impl<QCO: FromKurboPoint + ToKurboPoint> QuadToCubic<QCO, 4> for [QCO; 3] {
fn quad_to_cubic(self) -> [QCO; 4] {
#[allow(unused_assignments)]
let [p0, mut p1, mut p2, p3] = [self[0].to_kurbo(), self[1].to_kurbo(), self[2].to_kurbo(), self[2].to_kurbo()];
p1.x = p0.x + (2./3.) * (p1.x-p0.x);
p1.y = p0.y + (2./3.) * (p1.y-p0.y);
p2.x = p2.x + (2./3.) * (p1.x-p2.x);
p2.y = p2.y + (2./3.) * (p1.y-p2.y);
let [p0_o, p1_o, p2_o, p3_o] = [self[0].to_kurbo(), self[1].to_kurbo(), self[2].to_kurbo(), self[2].to_kurbo()];
let [p0, mut p1, mut p2, p3] = [p0_o, p1_o, p2_o, p3_o];
p1.x = p0_o.x + (2./3.) * (p1_o.x-p0_o.x);
p1.y = p0_o.y + (2./3.) * (p1_o.y-p0_o.y);
p2.x = p2_o.x + (2./3.) * (p1_o.x-p2_o.x);
p2.y = p2_o.y + (2./3.) * (p1_o.y-p2_o.y);
[QCO::from_kurbo(&p0), QCO::from_kurbo(&p1), QCO::from_kurbo(&p2), QCO::from_kurbo(&p3)]
}
}

// This method of Quad->Cubic conversion is used all over the place in FontForge.

0 comments on commit 945f0aa

Please sign in to comment.