DIRECTORY Cubic2, CubicSplines, Imager USING [VEC], LocalSplines, RegularALSpline, RegularUMSpline; CubicSplinesImpl: CEDAR PROGRAM IMPORTS Cubic2, LocalSplines, RegularALSpline, RegularUMSpline EXPORTS CubicSplines = BEGIN OPEN CubicSplines; TooFewKnots: PUBLIC SIGNAL [numknots: INTEGER] = CODE; UnknownSpline: PUBLIC SIGNAL [splineType: SplineType] = CODE; VEC: TYPE = Imager.VEC; Bezier: TYPE = Cubic2.Bezier; DisplayCubic: PUBLIC PROC [coeffs: Coeffs, MoveTo: PROC[ScrPt], DrawTo: PROC[ScrPt], tol: REAL ¬ 0.5] = { subdivide: PROC[bezier: Bezier] = { IF Cubic2.Flat[bezier, tol] THEN { DrawTo[[bezier.b3.x, bezier.b3.y]]; RETURN} ELSE { b1, b2: Bezier; [b1,b2] ¬ Cubic2.Split[bezier]; subdivide[b1]; subdivide[b2]; }; }; bezier: Bezier ¬ Cubic2.CoeffsToBezier[[ c0: [coeffs.t0[X], coeffs.t0[Y]], c1: [coeffs.t1[X], coeffs.t1[Y]], c2: [coeffs.t2[X], coeffs.t2[Y]], c3: [coeffs.t3[X], coeffs.t3[Y]] ]]; MoveTo[[bezier.b0.x, bezier.b0.y]]; subdivide[bezier]; }; MakeSpline: PUBLIC PROC [knots: KnotSequence, splineType: SplineType] RETURNS [CoeffsSequence] = { allCoeffs: CoeffsSequence; numknots: INTEGER ¬ knots.length; SELECT splineType FROM IN [naturalUM..cyclicUM] => allCoeffs ¬ RegularUMSpline.MakeSpline[knots,splineType ! TooFewKnots => BEGIN SIGNAL TooFewKnots[numknots]; CONTINUE; END; UnknownSpline => BEGIN SIGNAL UnknownSpline[splineType]; CONTINUE; END ]; IN [naturalAL..cyclicAL] => allCoeffs ¬ RegularALSpline.MakeSpline[knots,splineType ! TooFewKnots => BEGIN SIGNAL TooFewKnots[numknots]; CONTINUE; END; UnknownSpline => BEGIN SIGNAL UnknownSpline[splineType]; CONTINUE; END ]; IN [bezier..crspline] => allCoeffs ¬ LocalSplines.MakeSpline[knots,splineType ! TooFewKnots => BEGIN SIGNAL TooFewKnots[numknots]; CONTINUE; END; UnknownSpline => BEGIN SIGNAL UnknownSpline[splineType]; CONTINUE; END ]; ENDCASE => SIGNAL UnknownSpline[splineType]; RETURN[allCoeffs]; }; END. θ CubicSplinesImpl.mesa Copyright Σ 1987, 1992 by Xerox Corporation. All rights reserved. m.stone September 26, 1980 5:47 PM Last Edited by: Stone, March 15, 1983 3:27 pm Russ Atkinson (RRA) February 2, 1987 10:22:32 pm PST Κ•NewlineDelimiter –(cedarcode) style™code™Kšœ Οeœ7™BKšœ!Οk™#Kšœ-™-K™4K˜šž ˜ Kšœ˜Kšœ ˜ Kšœžœžœ˜Kšœ ˜ Kšœ˜Kšœ˜—K˜—šΟnœžœž˜Kšžœ7˜>Kšžœžœžœ˜/—K˜Kš Ÿ œžœžœ žœžœ˜6KšŸ œžœžœžœ˜=K˜Kšžœžœ žœ˜Kšœžœ˜K˜šŸ œžœžœŸœžœ Ÿœžœžœ ˜išœ žœ˜#šžœžœ˜"Kšœ#˜#Kšžœ˜—šžœ˜K˜K˜Kšœ˜Kšœ˜K˜—K˜K˜—˜(Kšœ"˜"Kšœ"˜"Kšœ"˜"Kšœ!˜!Kšœ˜—Kšœ#˜#Kšœ˜Kšœ˜K˜—KšŸ œžœžœ/žœ˜c˜K˜Kšœ žœ˜!Kšžœ ž˜˜šžœ˜˜9˜Kšžœžœžœžœ˜2—˜Kšžœžœžœž˜5——K˜——˜šžœ˜˜9˜Kšžœžœžœžœ˜2—˜Kšžœžœžœž˜5——K˜——˜šžœ˜˜6˜Kšžœžœžœžœ˜2—˜Kšžœžœžœž˜5—K˜———˜Kšžœžœ˜,—K˜Kšžœ ˜Kšœ˜—K˜Kšžœ˜K˜K˜—…—| y