[manual index][section index]


Rect - rectangular portion of the plane


include	"draw.m";
draw := load Draw Draw->PATH;

Rect: adt
  min:      Point;
  max:      Point;

  canon:    fn(r: self Rect):             Rect;
  dx:       fn(r: self Rect):             int;
  dy:       fn(r: self Rect):             int;
  eq:       fn(r: self Rect, s: Rect):    int;
  Xrect:    fn(r: self Rect, s: Rect):    int;
  inrect:   fn(r: self Rect, s: Rect):    int;
  clip:     fn(r: self Rect, s: Rect):    (Rect, int);
  combine:  fn(r: self Rect, s: Rect):    Rect;
  contains: fn(r: self Rect, p: Point):   int;
  addpt:    fn(r: self Rect, p: Point):   Rect;
  subpt:    fn(r: self Rect, p: Point):   Rect;
  inset:    fn(r: self Rect; n: int):     Rect;


The type Rect defines a rectangular portion of the integer grid.

min, max
These members define the upper left (min) and lower right (max) points for the rectangle. The rectangle contains the pixels min.x <= max.x and min.y <= max.y. In general, Rect coordinates should be in canonical form: min.x <= max.x and min.y <= max.y. Some functions give undefined results if the input rectangles are not canonical.
Returns a canonical rectangle by sorting the coordinates of r.
Returns the horizontal dimension of r.
Returns the vertical dimension of r.
Returns non-zero if the rectangles r and s have the same coordinates and zero otherwise.
Returns non-zero if the rectangles r and s intersect and zero otherwise. Intersection means the rectangles share at least one pixel; zero-sized rectangles do not intersect.
Returns non-zero if r is completely inside s and zero otherwise. Rectangles with equal coordinates are considered to be inside each other. Zero-sized rectangles contain no rectangles.
Computes the intersection between r and s. If the input rectangles intersect, clip returns the resulting rectangle and a non-zero integer value. If the rectangles do not intersect, clip returns r and a zero value.
Returns the smallest rectangle sufficient to cover all the pixels of r and s.
Returns non-zero if the rectangle r contains the pixel with the coordinates of p and zero otherwise. Zero-sized rectangles contain no points.
Returns the rectangle (r.min.add(p), r.max.add(p)).
Returns the rectangle (r.min.sub(p), r.max.sub(p)).
Returns the rectangle (r.min.add((n, n)), r.max.sub((n, n)). The result will not be in canonical form if the inset amount is too large for the rectangle.

DRAW-RECT(2 ) Rev:  Thu Feb 15 14:43:26 GMT 2007