arrayTools

class fontTools.misc.arrayTools.Vector(values, keep=False)[source]

A math-like vector.

dot(other)[source]
toInt()[source]
fontTools.misc.arrayTools.asInt16(array)[source]

Round and cast to 16 bit integer.

fontTools.misc.arrayTools.calcBounds(array)[source]

Return the bounding rectangle of a 2D points array as a tuple: (xMin, yMin, xMax, yMax)

fontTools.misc.arrayTools.calcIntBounds(array, round=<function otRound>)[source]

Return the integer bounding rectangle of a 2D points array as a tuple: (xMin, yMin, xMax, yMax) Values are rounded to closest integer towards +Infinity using otRound function by default, unless an optional ‘round’ function is passed.

fontTools.misc.arrayTools.insetRect(rect, dx, dy)[source]

Inset the rectangle by dx, dy on all sides.

fontTools.misc.arrayTools.intRect(rect1)[source]

Return the rectangle, rounded off to integer values, but guaranteeing that the resulting rectangle is NOT smaller than the original.

fontTools.misc.arrayTools.normRect(rect)[source]

Normalize the rectangle so that the following holds: xMin <= xMax and yMin <= yMax

fontTools.misc.arrayTools.offsetRect(rect, dx, dy)[source]

Offset the rectangle by dx, dy.

fontTools.misc.arrayTools.pairwise(iterable, reverse=False)[source]

Iterate over current and next items in iterable, optionally in reverse order.

>>> tuple(pairwise([]))
()
>>> tuple(pairwise([], reverse=True))
()
>>> tuple(pairwise([0]))
((0, 0),)
>>> tuple(pairwise([0], reverse=True))
((0, 0),)
>>> tuple(pairwise([0, 1]))
((0, 1), (1, 0))
>>> tuple(pairwise([0, 1], reverse=True))
((1, 0), (0, 1))
>>> tuple(pairwise([0, 1, 2]))
((0, 1), (1, 2), (2, 0))
>>> tuple(pairwise([0, 1, 2], reverse=True))
((2, 1), (1, 0), (0, 2))
>>> tuple(pairwise(['a', 'b', 'c', 'd']))
(('a', 'b'), ('b', 'c'), ('c', 'd'), ('d', 'a'))
>>> tuple(pairwise(['a', 'b', 'c', 'd'], reverse=True))
(('d', 'c'), ('c', 'b'), ('b', 'a'), ('a', 'd'))
fontTools.misc.arrayTools.pointInRect(p, rect)[source]

Return True when point (x, y) is inside rect.

fontTools.misc.arrayTools.pointsInRect(array, rect)[source]

Find out which points or array are inside rect. Returns an array with a boolean for each point.

fontTools.misc.arrayTools.rectCenter(rect0)[source]

Return the center of the rectangle as an (x, y) coordinate.

fontTools.misc.arrayTools.scaleRect(rect, x, y)[source]

Scale the rectangle by x, y.

fontTools.misc.arrayTools.sectRect(rect1, rect2)[source]

Return a boolean and a rectangle. If the input rectangles intersect, return True and the intersecting rectangle. Return False and (0, 0, 0, 0) if the input rectangles don’t intersect.

fontTools.misc.arrayTools.unionRect(rect1, rect2)[source]

Return the smallest rectangle in which both input rectangles are fully enclosed. In other words, return the total bounding rectangle of both input rectangles.

fontTools.misc.arrayTools.updateBounds(bounds, p, min=<built-in function min>, max=<built-in function max>)[source]

Return the bounding recangle of rectangle bounds and point (x, y).

fontTools.misc.arrayTools.vectorLength(vector)[source]

Return the length of the given vector.