From c4679e5e291a88ab670321f19ee83efc08846722 Mon Sep 17 00:00:00 2001 From: Colin Rofls Date: Tue, 26 Sep 2023 16:42:47 -0400 Subject: [PATCH] [write-fonts] iup: fixup vector distance calculation We were checking the axes independently, instead of checking the overall length of the vector. --- write-fonts/src/tables/gvar/iup.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/write-fonts/src/tables/gvar/iup.rs b/write-fonts/src/tables/gvar/iup.rs index 14fd8466e..72a69860a 100644 --- a/write-fonts/src/tables/gvar/iup.rs +++ b/write-fonts/src/tables/gvar/iup.rs @@ -302,10 +302,12 @@ fn can_iup_in_between( let real_values = &deltas[(from + 1) as usize..to]; + // compute this once here instead of in the loop + let tolerance_sq = tolerance.powi(2); Ok(real_values .iter() .zip(iup_values) - .all(|(d, i)| (d.x - i.x).abs() <= tolerance && (d.y - i.y).abs() <= tolerance)) + .all(|(d, i)| (*d - i).hypot2() <= tolerance_sq)) } ///