googlefonts / ufo2ft

A bridge from UFOs to FontTools objects (and therefore, OTFs and TTFs).
MIT License
151 stars 43 forks source link

hhea.caretSlopeRun calculated using math.tan() instead of math.atan() #703

Closed yanone closed 1 year ago

yanone commented 1 year ago

The two lines at the top and bottom here are wrong. math.atan() is used to calculate the triangle legs from a given angle, math.tan() is used for the inverse, to calculate the angle from the leg length.

This is correct:

import math
italicAngle = -12
caretSlopeRun = math.atan(math.radians(-italicAngle)) * 1000
roundTrippedItalicAngle = math.degrees(math.tan(-caretSlopeRun / 1000))
print(italicAngle, caretSlopeRun, roundTrippedItalicAngle)

prints:

-12 206.45531758085963 -12.000000000000002

I can make a PR.

yanone commented 1 year ago

The current code calculates 213 as the careSlopeRun instead of 206 for -12°, which is probably close enough that no one ever noticed the mistake.

anthrotype commented 1 year ago

good catch, please send PR thanks

yanone commented 1 year ago

My proposal is wrong. ufo2ft had it right all along.