-- File: PadGraphicsImpl.mesa -- Last edited by Bier on December 18, 1982 1:29 am -- Author: Eric Bier on August 6, 1982 12:30 pm -- Contents: Simple 2d graphics package for the scratchpad DIRECTORY Graphics, PadGraphics, Matrix3d, RealFns, SVDraw, SVPolygon2d, SVVector2d; PadGraphicsImpl: PROGRAM IMPORTS Graphics, RealFns, SVDraw, SVVector2d EXPORTS PadGraphics = BEGIN Path: TYPE = SVPolygon2d.Path; Point2d: TYPE = Matrix3d.Point2d; Polygon: TYPE = SVPolygon2d.Polygon; Vector2d: TYPE = SVVector2d.Vector2d; squareSide: REAL _ 6.0; ScreenToPad: PUBLIC PROC [screenPoint: Point2d, origin: Point2d, scalar: REAL _ 1] RETURNS [padPoint: Point2d] = { -- origin is the pad origin in screen coordintates padPoint[1] _ screenPoint[1] - origin[1]; padPoint[2] _ screenPoint[2] - origin[2]; padPoint _ SVVector2d.Scale[padPoint, 1/scalar]; }; PadToScreen: PUBLIC PROC [padPoint: Point2d, origin: Point2d, scalar: REAL _ 1] RETURNS [screenPoint: Point2d] = { padPoint _ SVVector2d.Scale[padPoint, scalar]; screenPoint[1] _ padPoint[1] + origin[1]; screenPoint[2] _ padPoint[2] + origin[2]; }; MoveTo: PUBLIC PROC [dc: Graphics.Context, padPoint: Point2d, origin: Point2d] = { screenPoint: Point2d; screenPoint _ PadToScreen[padPoint, origin]; Graphics.SetCP[dc, screenPoint[1], screenPoint[2]]; }; DrawTo: PUBLIC PROC [dc: Graphics.Context, padPoint: Point2d, origin: Point2d] = { screenPoint: Point2d; screenPoint _ PadToScreen[padPoint, origin]; Graphics.DrawTo[dc, screenPoint[1], screenPoint[2]]; }; MirrorMoveTo: PUBLIC PROC [dc: Graphics.Context, padPoint: Point2d, origin: Point2d] = { screenPoint: Point2d; padPoint[1] _ -padPoint[1]; screenPoint _ PadToScreen[padPoint, origin]; Graphics.SetCP[dc, screenPoint[1], screenPoint[2]]; }; MirrorDrawTo: PUBLIC PROC [dc: Graphics.Context, padPoint: Point2d, origin: Point2d] = { screenPoint: Point2d; padPoint[1] _ -padPoint[1]; screenPoint _ PadToScreen[padPoint, origin]; Graphics.DrawTo[dc, screenPoint[1], screenPoint[2]]; }; DrawPathNeighborHood: PUBLIC PROC [dc: Graphics.Context, path: Path, index: NAT, origin: Point2d] = { -- draw three points and 2 edges corresponding to the neighborhood of path[index]; -- path is in pad coordinates. -- if index is one of the two ends of the path then draw 2 points and 1 edge. DrawSquare[dc, squareSide, path[index], origin]; IF index>0 THEN { MoveTo[dc, path[index-1], origin]; DrawTo[dc, path[index], origin]; }; IF index0 THEN { MirrorMoveTo[dc, path[index-1], origin]; MirrorDrawTo[dc, path[index], origin]; }; IF index