aboutsummaryrefslogtreecommitdiff
path: root/lib/rect.py
diff options
context:
space:
mode:
authorSkip Montanaro <[email protected]>2021-02-16 20:14:16 -0600
committerSkip Montanaro <[email protected]>2021-02-16 20:14:16 -0600
commitc2587c76f1b416cdbecb979e54941933246bf856 (patch)
treebb61ee9128075ce22af4eafa232f13c2e5a07896 /lib/rect.py
parentd90761a005b24018ae237bf551515772a1de656f (diff)
downloadpython-0.9.1-patched-QoL-c2587c76f1b416cdbecb979e54941933246bf856.tar.xz
python-0.9.1-patched-QoL-c2587c76f1b416cdbecb979e54941933246bf856.zip
starting over
Diffstat (limited to 'lib/rect.py')
-rw-r--r--lib/rect.py76
1 files changed, 38 insertions, 38 deletions
diff --git a/lib/rect.py b/lib/rect.py
index 8f61e11..aa5ff44 100644
--- a/lib/rect.py
+++ b/lib/rect.py
@@ -18,71 +18,71 @@ empty = (0, 0), (0, 0)
# Check if a rectangle is empty.
#
def is_empty((left, top), (right, bottom)):
- return left >= right or top >= bottom
+ return left >= right or top >= bottom
# Compute the intersection or two or more rectangles.
# This works with a list or tuple argument.
#
def intersect(list):
- if not list: raise error, 'intersect called with empty list'
- if is_empty(list[0]): return empty
- (left, top), (right, bottom) = list[0]
- for rect in list[1:]:
- if is_empty(rect):
- return empty
- (l, t), (r, b) = rect
- if left < l: left = l
- if top < t: top = t
- if right > r: right = r
- if bottom > b: bottom = b
- if is_empty((left, top), (right, bottom)):
- return empty
- return (left, top), (right, bottom)
+ if not list: raise error, 'intersect called with empty list'
+ if is_empty(list[0]): return empty
+ (left, top), (right, bottom) = list[0]
+ for rect in list[1:]:
+ if is_empty(rect):
+ return empty
+ (l, t), (r, b) = rect
+ if left < l: left = l
+ if top < t: top = t
+ if right > r: right = r
+ if bottom > b: bottom = b
+ if is_empty((left, top), (right, bottom)):
+ return empty
+ return (left, top), (right, bottom)
# Compute the smallest rectangle containing all given rectangles.
# This works with a list or tuple argument.
#
def union(list):
- (left, top), (right, bottom) = empty
- for (l, t), (r, b) in list[1:]:
- if not is_empty((l, t), (r, b)):
- if l < left: left = l
- if t < top: top = t
- if r > right: right = r
- if b > bottom: bottom = b
- res = (left, top), (right, bottom)
- if is_empty(res):
- return empty
- return res
+ (left, top), (right, bottom) = empty
+ for (l, t), (r, b) in list[1:]:
+ if not is_empty((l, t), (r, b)):
+ if l < left: left = l
+ if t < top: top = t
+ if r > right: right = r
+ if b > bottom: bottom = b
+ res = (left, top), (right, bottom)
+ if is_empty(res):
+ return empty
+ return res
# Check if a point is in a rectangle.
#
def pointinrect((h, v), ((left, top), (right, bottom))):
- return left <= h < right and top <= v < bottom
+ return left <= h < right and top <= v < bottom
# Return a rectangle that is dh, dv inside another
#
def inset(((left, top), (right, bottom)), (dh, dv)):
- left = left + dh
- top = top + dv
- right = right - dh
- bottom = bottom - dv
- r = (left, top), (right, bottom)
- if is_empty(r):
- return empty
- else:
- return r
+ left = left + dh
+ top = top + dv
+ right = right - dh
+ bottom = bottom - dv
+ r = (left, top), (right, bottom)
+ if is_empty(r):
+ return empty
+ else:
+ return r
# Conversions between rectangles and 'geometry tuples',
# given as origin (h, v) and dimensions (width, height).
#
def rect2geom((left, top), (right, bottom)):
- return (left, top), (right-left, bottom-top)
+ return (left, top), (right-left, bottom-top)
def geom2rect((h, v), (width, height)):
- return (h, v), (h+width, v+height)
+ return (h, v), (h+width, v+height)