diff options
author | Just <Just@4cde692c-a291-49d1-8350-778aa11640f8> | 2000-01-26 19:32:45 +0000 |
---|---|---|
committer | Just <Just@4cde692c-a291-49d1-8350-778aa11640f8> | 2000-01-26 19:32:45 +0000 |
commit | deb3b632f4e676bbb634c6b53ac2e76d248f5936 (patch) | |
tree | d32be300d042f9846e070938f3193f2d7bd242b7 /Lib/fontTools/misc/arrayTools.py | |
parent | 56804d237a76d9bcb9eb219bdf2ee692f9fcb23b (diff) | |
download | fonttools-deb3b632f4e676bbb634c6b53ac2e76d248f5936.tar.gz |
Two new functions:
- vectorLength(vector): calculate the length of a vector
- asInt16(): round and cast any array (or number) to 16 bit ints
git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@69 4cde692c-a291-49d1-8350-778aa11640f8
Diffstat (limited to 'Lib/fontTools/misc/arrayTools.py')
-rw-r--r-- | Lib/fontTools/misc/arrayTools.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/fontTools/misc/arrayTools.py b/Lib/fontTools/misc/arrayTools.py index 9e8d59fc..fde004f4 100644 --- a/Lib/fontTools/misc/arrayTools.py +++ b/Lib/fontTools/misc/arrayTools.py @@ -1,5 +1,5 @@ # -# This module should move to a more appropriate location +# Various array and rectangle tools # import Numeric @@ -16,7 +16,6 @@ def calcBounds(array): xmax, ymax = Numeric.maximum.reduce(array) return xmin, ymin, xmax, ymax - def pointsInRect(array, rect): """Find out which points or array are inside rect. Returns an array with a boolean for each point. @@ -30,6 +29,13 @@ def pointsInRect(array, rect): Numeric.less(array, rightbottom)) return Numeric.logical_and.reduce(condition, -1) +def vectorLength(vector): + return Numeric.sqrt(vector[0]**2 + vector[1]**2) + +def asInt16(array): + "Round and cast to 16 bit integer." + return Numeric.floor(array + 0.5).astype(Numeric.Int16) + def normRect((l, t, r, b)): """XXX doc""" |