DIRECTORY GGBasicTypes, GGBoundBox, GGBuiltinShapes, GGModelTypes, GGOutline, GGSegment, GGSegmentTypes, GGTransform, GGSlice, GGTraj, GGVector, ImagerColor, RealFns, Rope; GGBuiltinShapesImpl: CEDAR PROGRAM IMPORTS GGBoundBox, GGOutline, GGSegment, GGSlice, GGTraj, GGTransform, GGVector, ImagerColor, RealFns EXPORTS GGBuiltinShapes = BEGIN Outline: TYPE = GGModelTypes.Outline; Point: TYPE = GGBasicTypes.Point; Segment: TYPE = GGSegmentTypes.Segment; Slice: TYPE = GGModelTypes.Slice; SliceDescriptor: TYPE = GGModelTypes.SliceDescriptor; Traj: TYPE = GGModelTypes.Traj; Vector: TYPE = GGBasicTypes.Vector; Problem: PUBLIC SIGNAL [msg: Rope.ROPE] = CODE; PolygonInCircle: PUBLIC PROC [sideCount: NAT, origin: Point, radius: REAL] RETURNS [outline: Outline] = { traj: Traj; theta0, theta, deltaTheta, sin, cos: REAL; lastPoint, thisPoint: Point; success: BOOL; seg: Segment; deltaTheta _ 360.0/sideCount; theta0 _ -90.0 + deltaTheta/2.0; sin _ RealFns.SinDeg[theta0]; cos _ RealFns.CosDeg[theta0]; thisPoint _ GGVector.Add[GGVector.Scale[[cos, sin], radius], origin]; traj _ GGTraj.CreateTraj[thisPoint]; lastPoint _ thisPoint; FOR i: NAT IN [1..sideCount-1] DO theta _ theta0 + i*deltaTheta; sin _ RealFns.SinDeg[theta]; cos _ RealFns.CosDeg[theta]; thisPoint _ GGVector.Add[GGVector.Scale[[cos, sin], radius], origin]; seg _ GGSegment.MakeLine[lastPoint, thisPoint, NIL]; success _ GGTraj.AddSegment[traj, hi, seg, lo]; IF NOT success THEN SIGNAL Problem[msg: "Couldn't add segment"]; lastPoint _ thisPoint; ENDLOOP; sin _ RealFns.SinDeg[theta0]; cos _ RealFns.CosDeg[theta0]; thisPoint _ GGVector.Add[GGVector.Scale[[cos, sin], radius], origin]; seg _ GGSegment.MakeLine[lastPoint, thisPoint, NIL]; GGTraj.CloseWithSegment[traj, seg, lo]; outline _ GGOutline.CreateOutline[traj, round, ImagerColor.ColorFromGray[0.5]]; }; Box: PUBLIC PROC [origin: Point, sideLength: REAL] RETURNS [slice: Slice] = { halfSide: REAL _ sideLength/2.0; box: GGBoundBox.BoundBox _ GGBoundBox.CreateBoundBox[origin.x-halfSide, origin.y-halfSide, origin.x+halfSide, origin.y+halfSide]; sliceD: SliceDescriptor _ GGSlice.MakeBoxSlice[box, ul, GGTransform.Identity[] ]; slice _ sliceD.slice; }; Circle: PUBLIC PROC [origin: Point, radius: REAL] RETURNS [slice: Slice] = { outerPoint: Point _ [origin.x + radius, origin.y]; sliceD: SliceDescriptor _ GGSlice.MakeCircleSlice[origin, outerPoint]; slice _ sliceD.slice; }; Polygon: PUBLIC PROC [sideCount: NAT, origin: Point, sideLength: REAL] RETURNS [outline: Outline] = { }; KnotchedLine: PUBLIC PROC [p0, p1: Point, segmentCount: NAT] RETURNS [outline: Outline] = { delta: Vector; lastPoint, thisPoint: Point; traj: Traj; seg: Segment; success: BOOL; delta _ GGVector.Scale[GGVector.Sub[p1, p0], 1.0/segmentCount]; lastPoint _ p0; traj _ GGTraj.CreateTraj[lastPoint]; THROUGH [1..segmentCount-1] DO thisPoint _ GGVector.Add[lastPoint, delta]; seg _ GGSegment.MakeLine[lastPoint, thisPoint, NIL]; success _ GGTraj.AddSegment[traj, hi, seg, lo]; IF NOT success THEN SIGNAL Problem[msg: "Couldn't add segment"]; lastPoint _ thisPoint; ENDLOOP; thisPoint _ p1; seg _ GGSegment.MakeLine[lastPoint, thisPoint, NIL]; success _ GGTraj.AddSegment[traj, hi, seg, lo]; IF NOT success THEN SIGNAL Problem[msg: "Couldn't add segment"]; outline _ GGOutline.CreateOutline[traj, round, ImagerColor.ColorFromGray[0.5]]; }; END. \GGBuiltinShapesImpl.mesa Copyright c 1986 by Xerox Corporation. All rights reserved. Last edited by Bier on June 23, 1986 Contents: The regular polygons and other commonly requested shapes. Pier, October 28, 1986 5:27:09 pm PST Bier, November 13, 1986 6:55:14 pm PST The bottom-most edge of the returned polygon will be horizontal. The polygon will be inscribed inside the circle with radius "radius" centered at "origin". The bottom-most edge of the returned polygon will be horizontal. The polygon will be inscribed inside a circle centered at "origin". Each side of the polygon will have length "sideLength". Returns a trajectory with "segmentCount" straight line segments, all of the same length. The entire trajectory is a single straight line, from point p0 to p1. All of its segments are collinear. Knotched lines are useful as rulers. Κ„˜codešœ™Kšœ Οmœ1™