<> <> <> <> <> <<>> DIRECTORY ImagerTransformation, GGBasicTypes, GGTransform; GGTransformImpl: CEDAR PROGRAM IMPORTS ImagerTransformation EXPORTS GGTransform = BEGIN Point: TYPE = GGBasicTypes.Point; Identity: PUBLIC PROC RETURNS [id: ImagerTransformation.Transformation] = { id _ ImagerTransformation.Translate[[0, 0]]; }; Transform: PUBLIC PROC [m: ImagerTransformation.Transformation, p: Point] RETURNS [newP: Point] = { result: ImagerTransformation.VEC; result _ ImagerTransformation.Transform[m, [p.x, p.y] ]; newP _ [result.x, result.y]; }; RotateAboutPoint: PUBLIC PROC [origin: Point, degrees: REAL] RETURNS [m: ImagerTransformation.Transformation] = { m _ ImagerTransformation.Translate[ [-origin.x, -origin.y] ]; m _ ImagerTransformation.PostRotate[m, degrees]; m _ ImagerTransformation.PostTranslate[m, [origin.x, origin.y]]; }; ScaleAboutPoint: PUBLIC PROC [origin: Point, scalar: REAL] RETURNS [m: ImagerTransformation.Transformation] = { m _ ImagerTransformation.Translate[ [-origin.x, -origin.y] ]; m _ ImagerTransformation.PostScale[m, scalar]; m _ ImagerTransformation.PostTranslate[m, [origin.x, origin.y]]; }; ScaleUnevenAboutPoint: PUBLIC PROC [origin: Point, scalarX: REAL, scalarY: REAL] RETURNS [m: ImagerTransformation.Transformation] = { m _ ImagerTransformation.Translate[ [-origin.x, -origin.y] ]; m _ ImagerTransformation.PostScale2[m, [scalarX, scalarY]]; m _ ImagerTransformation.PostTranslate[m, [origin.x, origin.y]]; }; <> <<>> SixPoints: PUBLIC PROC[pts: ARRAY [0..5] OF Point] RETURNS[transform: ImagerTransformation.Transformation] = { dpts: ARRAY [0..3] OF Point; a,b,d,e: REAL; del: REAL; xform: ImagerTransformation.Transformation; dpts[0].x _ pts[1].x-pts[0].x; dpts[0].y _ pts[1].y-pts[0].y; dpts[1].x _ pts[2].x-pts[0].x; dpts[1].y _ pts[2].y-pts[0].y; dpts[2].x _ pts[4].x-pts[3].x; dpts[2].y _ pts[4].y-pts[3].y; dpts[3].x _ pts[5].x-pts[3].x; dpts[3].y _ pts[5].y-pts[3].y; del _ dpts[0].x*dpts[1].y-dpts[1].x*dpts[0].y; IF del=0 THEN ERROR; a _ (dpts[2].x*dpts[1].y-dpts[3].x*dpts[0].y)/del; b _ (dpts[0].x*dpts[3].x-dpts[1].x*dpts[2].x)/del; d _ (dpts[2].y*dpts[1].y-dpts[3].y*dpts[0].y)/del; e _ (dpts[0].x*dpts[3].y-dpts[1].x*dpts[2].y)/del; xform _ ImagerTransformation.Create[a: a, b: b, c: 0, d: d, e: e, f: 0]; xform _ ImagerTransformation.PostTranslate[xform, [x: pts[3].x, y: pts[3].y]]; xform _ ImagerTransformation.PreTranslate[xform, [x: -pts[0].x, y: -pts[0].y]]; RETURN[xform]; }; FourPoints: PUBLIC PROC[pts: ARRAY [0..3] OF Point] RETURNS[transform: ImagerTransformation.Transformation] = { xform: ImagerTransformation.Transformation; a,b,d,e: REAL; x1: REAL _ pts[1].x-pts[0].x; x2: REAL _ pts[3].x-pts[2].x; y1: REAL _ pts[1].y-pts[0].y; y2: REAL _ pts[3].y-pts[2].y; del: REAL _ x1*x1+y1*y1; <> <> <> <> <> IF del=0 THEN ERROR; a _ (x1*x2+y1*y2)/del; e _ a; d _ (x1*y2-y1*x2)/del; b _ -d ; <> <> xform _ ImagerTransformation.Create[a: a, b: b, c: 0, d: d, e: e, f: 0]; xform _ ImagerTransformation.PostTranslate[xform, [x: pts[2].x, y: pts[2].y]]; xform _ ImagerTransformation.PreTranslate[xform, [x: -pts[0].x, y: -pts[0].y]]; RETURN[xform] }; <<>> <<>> END.