CubicSplinesImpl.mesa
Copyright Ó 1987 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
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.