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
diff --git a/Lib/fontTools/misc/arrayTools.py b/Lib/fontTools/misc/arrayTools.py
index 9e8d59f..fde004f 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 @@
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 @@
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"""