SOLVED Rotate 90º seems to send contours upward.
-
I'm wondering if it'd make sense to slightly alter the built-in RF way to rotate. Continuing to rotate often won't return you to your home position, and instead send the glyph up or down, presumably because the bounds are odd.
See video demo, and alternative script suggestion:
g = CurrentGlyph() # gather midpoint of selection xs = [] ys = [] for pt in g.selection: xs.append(pt.x) ys.append(pt.y) mid_x = round((max(xs) + min(xs)) / 2) mid_y = round((max(ys) + min(ys)) / 2) # rotate around midpoint for pt in g.selection: pt.rotateBy(90, origin = (mid_x, mid_y)) g.update()
This is for the
selection
, but you get the idea.TIA!
-
@frederik Makes sense to lean toward using one method. Did not know their were changes to
round
from py2 to py3! Appreciate you looking at this, Frederik!
-
I tried when only the rounding the offset position with the default python
round
its that seems to be oke... And this will be "fixed" in the next beta/release.The reason why every rounding is with
otRound
is to keep a single rounding func for all sort of rounding.This is also the difference between
round
in py2 vs py3.
-
@frederik I see. I just did some more testing with
otRound
andround
and it looks likeotRound
goes rightward over several rotations, which I now notice from my last video.round
seems to return home each time, though. Any reasonround
would be bad?odd-width-and-height bounds:
r
: upward
round
: stationary on average
otRound
: rightwardHere's another video and test script:
from fontTools.misc.fixedTools import otRound g = CurrentGlyph() # contour 0 : round c_0 = g[0] mid_x_0 = round((c_0.bounds[0] + c_0.bounds[2]) / 2) mid_y_0 = round((c_0.bounds[1] + c_0.bounds[3]) / 2) c_0.rotateBy(90, origin = (mid_x_0, mid_y_0)) # contour 1 : otRound c_1 = g[1] mid_x_1 = otRound((c_1.bounds[0] + c_1.bounds[2]) / 2) mid_y_1 = otRound((c_1.bounds[1] + c_1.bounds[3]) / 2) c_1.rotateBy(90, origin = (mid_x_1, mid_y_1)) g.update()
-
yeah, if this is the case then the numbers are just not working for you... by hitting a single
r
the points are rotated and rounded off, next them the same happens.I can reproduce all cases: moving up, moving right, doing nothing... with both the internal rotation and your example script. I just have to move a point 1 unit up/down/left/right.
-
@frederik said in Rotate 90º seems to always round up.:
otRound
RF’s native rotate still sends the contour upward, and otRound doesn’t: see here. Something else must be going on.
-
RoboFont is using
otRound
fromfontTools.misc.fixedTools
see the difference here:
from fontTools.misc.fixedTools import otRound value = .5 print(otRound(value)) print(round(value)) value = .49 print(otRound(value)) print(round(value)) value = .51 print(otRound(value)) print(round(value))
see https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/fixedTools.py#L24-L32