Next: 17 SGI IRIX Specific
Up: 16 Standard Windowing Interface
Previous: 16.2 Standard Module stdwinevents
This module contains useful operations on rectangles.
A rectangle is defined as in module
stdwin
:
a pair of points, where a point is a pair of integers.
For example, the rectangle
(10, 20), (90, 80)
is a rectangle whose left, top, right and bottom edges are 10, 20, 90
and 80, respectively.
Note that the positive vertical axis points down (as in
stdwin
).
The module defines the following objects:
- error
-
The exception raised by functions in this module when they detect an
error.
The exception argument is a string describing the problem in more
detail.
- empty
-
The rectangle returned when some operations return an empty result.
This makes it possible to quickly check whether a result is empty:
>>> import rect
>>> r1 = (10, 20), (90, 80)
>>> r2 = (0, 0), (10, 20)
>>> r3 = rect.intersect([r1, r2])
>>> if r3 is rect.empty: print 'Empty intersection'
Empty intersection
>>>
- is_empty(r)
-
Returns true if the given rectangle is empty.
A rectangle
(left, top), (right, bottom)
is empty if
,
left >= right
or top => bottom
.
,
or
.
,
- intersect(list)
-
Returns the intersection of all rectangles in the list argument.
It may also be called with a tuple argument.
Raises
rect.error
if the list is empty.
Returns
rect.empty
if the intersection of the rectangles is empty.
- union(list)
-
Returns the smallest rectangle that contains all non-empty rectangles in
the list argument.
It may also be called with a tuple argument or with two or more
rectangles as arguments.
Returns
rect.empty
if the list is empty or all its rectangles are empty.
- pointinrect(point, rect)
-
Returns true if the point is inside the rectangle.
By definition, a point
(h, v)
is inside a rectangle
(left, top), (right, bottom)
if
,
left <= h < right
and
top <= v < bottom
.
,
and
.
,
- inset(rect,
)
-
Returns a rectangle that lies inside the
rect
argument by
dh
pixels horizontally
and
dv
pixels
vertically.
If
dh
or
dv
is negative, the result lies outside
rect.
- rect2geom(rect)
-
Converts a rectangle to geometry representation:
(left, top), (width, height)
.
- geom2rect(geom)
-
Converts a rectangle given in geometry representation back to the
standard rectangle representation
(left, top), (right, bottom)
.
Next: 17 SGI IRIX Specific
Up: 16 Standard Windowing Interface
Previous: 16.2 Standard Module stdwinevents
guido@cnri.reston.va.us