aboutsummaryrefslogtreecommitdiff
path: root/Lib/fontTools/misc/arrayTools.py
diff options
context:
space:
mode:
authorJust <Just@4cde692c-a291-49d1-8350-778aa11640f8>2000-01-16 20:37:11 +0000
committerJust <Just@4cde692c-a291-49d1-8350-778aa11640f8>2000-01-16 20:37:11 +0000
commit470b5050eea71e2ea0aee4cf94d292d0e532f3ef (patch)
treeef4825786a95791c09b683f4b8392809aebc3d7d /Lib/fontTools/misc/arrayTools.py
parentc2be3d982b04c4bbb1c11d9ab8452f78415d6522 (diff)
downloadfonttools-470b5050eea71e2ea0aee4cf94d292d0e532f3ef.tar.gz
yet another reorganization round...
git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@58 4cde692c-a291-49d1-8350-778aa11640f8
Diffstat (limited to 'Lib/fontTools/misc/arrayTools.py')
-rw-r--r--Lib/fontTools/misc/arrayTools.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/Lib/fontTools/misc/arrayTools.py b/Lib/fontTools/misc/arrayTools.py
new file mode 100644
index 00000000..9792b737
--- /dev/null
+++ b/Lib/fontTools/misc/arrayTools.py
@@ -0,0 +1,42 @@
+#
+# This module should move to a more appropriate location
+#
+
+import Numeric
+
+
+def calcBounds(array):
+ """Calculate the bounding rectangle of a 2D array.
+ Returns a 4-tuple:
+ smallest x, smallest y, largest x, largest y.
+ """
+ if len(array) == 0:
+ return 0, 0, 0, 0
+ xmin, ymin = Numeric.minimum.reduce(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.
+ """
+ if len(array) < 1:
+ return []
+ lefttop = rect[:2]
+ rightbottom = rect[2:]
+ condition = Numeric.logical_and(
+ Numeric.greater(array, lefttop),
+ Numeric.less(array, rightbottom))
+ return Numeric.logical_and.reduce(condition, -1)
+
+
+def normRect((l, t, r, b)):
+ """XXX doc"""
+ return min(l, r), min(t, b), max(l, r), max(t, b)
+
+def scaleRect((l, t, r, b), x, y):
+ return l * x, t * y, r * x, b * y
+
+def offsetRect((l, t, r, b), dx, dy):
+ return l+dx, t+dy, r+dx, b+dy