ImagerBasicsImpl.mesa
Copyright © 1985, 1986 by Xerox Corporation. All rights reserved.
Michael Plass, May 17, 1985 3:50:19 pm PDT
Doug Wyatt, March 7, 1986 4:10:00 pm PST
DIRECTORY
ImagerBasics USING [Box, Extents, Rectangle, VEC];
ImagerBasicsImpl: CEDAR PROGRAM
EXPORTS ImagerBasics
~ BEGIN OPEN ImagerBasics;
BoxFromRectangle:
PUBLIC
PROC [r: Rectangle]
RETURNS [b: Box] ~ {
Pt:
PROC [x, y:
REAL] ~
INLINE {
IF x > b.xmax THEN b.xmax ← x ELSE IF x < b.xmin THEN b.xmin ← x;
IF y > b.ymax THEN b.ymax ← y ELSE IF y < b.ymin THEN b.ymin ← y;
};
b ← [r.x, r.y, r.x, r.y];
Pt[r.x+r.w, r.y+r.h];
};
RectangleFromBox:
PUBLIC
PROC [b: Box]
RETURNS [Rectangle] ~ {
IF b.xmin > b.xmax THEN {t: REAL ← b.xmin; b.xmin ← b.xmax; b.xmax ← t};
IF b.ymin > b.ymax THEN {t: REAL ← b.ymin; b.ymin ← b.ymax; b.ymax ← t};
RETURN [[x: b.xmin, y: b.ymin, w: b.xmax-b.xmin, h: b.ymax-b.ymin]];
};
BoxFromExtents:
PUBLIC
PROC [e: Extents]
RETURNS [b: Box] ~ {
Pt:
PROC [x, y:
REAL] ~
INLINE {
IF x > b.xmax THEN b.xmax ← x ELSE IF x < b.xmin THEN b.xmin ← x;
IF y > b.ymax THEN b.ymax ← y ELSE IF y < b.ymin THEN b.ymin ← y;
};
b ← [e.rightExtent, e.ascent, e.rightExtent, e.ascent];
Pt[-e.leftExtent, -e.descent];
};
ExtentsFromBox:
PUBLIC
PROC [b: Box]
RETURNS [Extents] ~ {
IF b.xmin > b.xmax THEN {t: REAL ← b.xmin; b.xmin ← b.xmax; b.xmax ← t};
IF b.ymin > b.ymax THEN {t: REAL ← b.ymin; b.ymin ← b.ymax; b.ymax ← t};
RETURN [[leftExtent: -b.xmin, descent: -b.ymin, rightExtent: b.xmax, ascent: b.ymax]];
};
RectangleFromExtents:
PUBLIC
PROC [e: Extents]
RETURNS [Rectangle] ~ {
Pt:
PROC [x, y:
REAL] ~
INLINE {
IF x > b.xmax THEN b.xmax ← x ELSE IF x < b.xmin THEN b.xmin ← x;
IF y > b.ymax THEN b.ymax ← y ELSE IF y < b.ymin THEN b.ymin ← y;
};
b: Box ← [e.rightExtent, e.ascent, e.rightExtent, e.ascent];
Pt[-e.leftExtent, -e.descent];
RETURN[[x: b.xmin, y: b.ymin, w: b.xmax-b.xmin, h: b.ymax-b.ymin]];
};
ExtentsFromRectangle:
PUBLIC
PROC [r: Rectangle]
RETURNS [Extents] ~ {
b: Box ← [xmin: r.x, ymin: r.y, xmax: r.x+r.w, ymax: r.y+r.h];
IF b.xmin > b.xmax THEN {t: REAL ← b.xmin; b.xmin ← b.xmax; b.xmax ← t};
IF b.ymin > b.ymax THEN {t: REAL ← b.ymin; b.ymin ← b.ymax; b.ymax ← t};
RETURN [[leftExtent: -b.xmin, descent: -b.ymin, rightExtent: b.xmax, ascent: b.ymax]];
};
IntersectBox:
PUBLIC
PROC [a: Box, b: Box]
RETURNS [c: Box] ~ {
IF a.xmin > a.xmax THEN {t: REAL ← a.xmin; a.xmin ← a.xmax; a.xmax ← t};
IF a.ymin > a.ymax THEN {t: REAL ← a.ymin; a.ymin ← a.ymax; a.ymax ← t};
IF b.xmin > b.xmax THEN {t: REAL ← b.xmin; b.xmin ← b.xmax; b.xmax ← t};
IF b.ymin > b.ymax THEN {t: REAL ← b.ymin; b.ymin ← b.ymax; b.ymax ← t};
c ← [xmin: MAX[a.xmin, b.xmin], ymin: MAX[a.ymin, b.ymin], xmax: MIN[a.xmax, b.xmax], ymax: MIN[a.ymax, b.ymax]];
IF c.xmin>=c.xmax OR c.ymin>=c.ymax THEN c ← [0, 0, 0, 0];
};
BoundBox:
PUBLIC
PROC [a: Box, b: Box]
RETURNS [c: Box] ~ {
IF a.xmin > a.xmax THEN {t: REAL ← a.xmin; a.xmin ← a.xmax; a.xmax ← t};
IF a.ymin > a.ymax THEN {t: REAL ← a.ymin; a.ymin ← a.ymax; a.ymax ← t};
IF b.xmin > b.xmax THEN {t: REAL ← b.xmin; b.xmin ← b.xmax; b.xmax ← t};
IF b.ymin > b.ymax THEN {t: REAL ← b.ymin; b.ymin ← b.ymax; b.ymax ← t};
c ← [xmin: MIN[a.xmin, b.xmin], ymin: MIN[a.ymin, b.ymin], xmax: MAX[a.xmax, b.xmax], ymax: MAX[a.ymax, b.ymax]];
};
BoundPoint:
PUBLIC
PROC [a: Box, b:
VEC]
RETURNS [Box] ~ {
IF a.xmin > a.xmax THEN {t: REAL ← a.xmin; a.xmin ← a.xmax; a.xmax ← t};
IF a.ymin > a.ymax THEN {t: REAL ← a.ymin; a.ymin ← a.ymax; a.ymax ← t};
RETURN [[xmin: MIN[a.xmin, b.x], ymin: MIN[a.ymin, b.y], xmax: MAX[a.xmax, b.x], ymax: MAX[a.ymax, b.y]]];
};
END.