From 6e0b9c615fada600619041a45f06a70951f171ce Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 19 Nov 2023 08:25:32 -0700 Subject: [PATCH] [statisticsPen] Another bandaid :-( --- Lib/fontTools/pens/statisticsPen.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/fontTools/pens/statisticsPen.py b/Lib/fontTools/pens/statisticsPen.py index ad2e354a0..d22904fc0 100644 --- a/Lib/fontTools/pens/statisticsPen.py +++ b/Lib/fontTools/pens/statisticsPen.py @@ -98,7 +98,11 @@ class StatisticsPen(MomentsPen): if stddevX * stddevY == 0: correlation = float("NaN") else: + # XXX The above formula should never produce a value outside + # the range [-1, 1], but due to reasons I don't understand, + # (probably the same issue as above), it does. So we clamp. correlation = covariance / (stddevX * stddevY) + correlation = max(-1, min(1, correlation)) self.correlation = correlation if abs(correlation) > 1e-3 else 0 slant = covariance / varianceY if varianceY != 0 else float("NaN")