ImagerBoxImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Michael Plass, May 17, 1985 3:50:19 pm PDT
DIRECTORY
Imager USING [Rectangle, Box, VEC],
ImagerBox USING [],
ImagerFont USING [Extents]
;
ImagerBoxImpl: CEDAR PROGRAM
EXPORTS ImagerBox
~ BEGIN OPEN Imager, ImagerFont;
BoxFromRect: 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];
};
RectFromBox: 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]];
};
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];
};
BoundingBox: 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.