-- LSFit.mesa
-- Michael Plass 10-Mar-82 15:18:23

DIRECTORY
  Complex,
  Seq;

LSFit: CEDAR DEFINITIONS =
BEGIN
ComplexSequence: TYPE = Seq.ComplexSequence;
ComplexSequenceRec: TYPE = Seq.ComplexSequenceRec;
RealSequence: TYPE = Seq.RealSequence;
RealSequenceRec: TYPE = Seq.RealSequenceRec;
NatSequence: TYPE = Seq.NatSequence;
NatSequenceRec: TYPE = Seq.NatSequenceRec;

Patch: TYPE = RECORD[c0,c1,c2,c3: REAL ← 0];
PatchSequence: TYPE = REF PatchSequenceRec;
PatchSequenceRec: TYPE = RECORD[element: SEQUENCE length:NAT OF Patch];

Handle: TYPE = REF StateRec;
StateRec: TYPE = RECORD
   [n: NAT, -- number of points
    z: ComplexSequence,
    weight: RealSequence,
    t: RealSequence, -- the current best guess of parameter values
    knots: RealSequence,
    closedCurve: BOOLEAN ← FALSE,
    xPatches,yPatches: PatchSequence
    ];

Create: PROCEDURE [sa: ComplexSequence] RETURNS [Handle];

InitialKnots: PUBLIC PROCEDURE [h: Handle, nknots: NAT ← 2];

XYat: PROCEDURE [h: Handle, t: REAL] RETURNS [Complex.Vec];

ClosestKnot: PROCEDURE [h: Handle, z: Complex.Vec]
    RETURNS [NAT];

InitialParametricCubic: PROCEDURE[sa: ComplexSequence] RETURNS [Handle];

ImproveParametricCubic: PROCEDURE [h: Handle, first: NAT ← 0, last: NAT ← LAST[NAT]];

FitParametricCubic: PROCEDURE [h: Handle, first, last: NAT, epsilon: REAL];
	-- does the whole thing for a single piece
			
ReParameterize: PUBLIC PROC [p: Patch, t0,t1: REAL, nt0,nt1: REAL]
		RETURNS[np: Patch];

InitialParametricSpline:
	PUBLIC PROCEDURE [sa: ComplexSequence, nknots: NAT, closed: BOOLEAN ← FALSE]
	RETURNS [Handle];

Sort: PUBLIC PROCEDURE [v: RealSequence];

InitialTValues: PUBLIC PROCEDURE [h: Handle];

AdjustTValues: PUBLIC PROCEDURE [h: Handle];

FitXAndY: PUBLIC PROCEDURE [h: Handle];

ImproveParametricSpline:
	PUBLIC PROCEDURE [h: Handle];

END.