MODULE Square; (* Procedures and predicates for arbitrarily oriented squares. *) IMPORT Geometry, PS; (* \section{Adjacent Corner Representation} *) PROC Draw(a, b) IS PS.MoveTo(a); PS.LineTo(b); PS.LineTo((1, 1) REL (a, b)); PS.LineTo((0, 1) REL (a, b)); PS.Close() END; UI PointTool(Draw); (* Append a closed square path with edge "ab" to the current path. The square is constructed to the left of the ray from "a" to "b". *) FUNC area = Area(a, b) IS area = Geometry.Dist2(a, b) END; (* "area" is the area of the square with edge "ab". *) (* \section{Center-Corner Representation} *) PROC DrawC(c, b) IS PS.MoveTo(b); PS.LineTo((0, 1) REL (c, b)); PS.LineTo((-1, 0) REL (c, b)); PS.LineTo((0, -1) REL (c, b)); PS.Close() END; UI PointTool(DrawC); (* Append a closed square path with center "c" and corner vertex "b" to the current path. *) FUNC area = AreaC(c, b) IS area = 2 * Geometry.Dist2(c, b) END; (* "area" is the area of the square with center "c" and corner vertex "b". *)