m.stone September 26, 1980 5:47 PM
Last Edited by: Stone, March 15, 1983 3:27 pm
DIRECTORY
CubicSplines,
RegularALSpline,
RegularUMSpline,
LocalSplines,
Cubic2,
Imager USING [VEC];
CubicSplinesImpl: CEDAR PROGRAM
IMPORTS RegularALSpline, RegularUMSpline, LocalSplines, Cubic2
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 PROCEDURE [coeffs: Coeffs, MoveTo: PROCEDURE[ScrPt], DrawTo: PROCEDURE[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 PROCEDURE
[knots: KnotSequence, splineType: SplineType] RETURNS [CoeffsSequence] =
BEGIN
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;
END.