Prev: stdwinevents Up: STDWIN ONLY Top: Top

8.3. Standard Module rect

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

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 -- exception of module rect
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 -- data of module rect
The rectangle returned when some operations return an empty result. This makes it possible to quickly check whether a result is empty:

is_empty (r) -- function of module rect
Returns true if the given rectangle is empty. A rectangle (left, top), (right, bottom) is empty if left >= right or top => bottom.
intersect (list) -- function of module rect
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) -- function of module rect
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) -- function of module 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.
inset (rect, (dh, dv)) -- function of module 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) -- function of module rect
Converts a rectangle to geometry representation: (left, top), (width, height).
geom2rect (geom) -- function of module rect
Converts a rectangle given in geometry representation back to the standard rectangle representation (left, top), (right, bottom).