<> <> <> <> <> <> <> <> <<>> DIRECTORY Cubic, Complex, FitState, SafeStorage USING [ReclaimCollectibleObjects], JaM, FitJaM, FitBasic, FitStateUtils, FitIO, Real, Rope, Seq, Vector; FitEditJaM: CEDAR PROGRAM IMPORTS Complex, JaM, Real, Vector, FitState, FitJaM, FitIO, FitStateUtils, SafeStorage = { State: TYPE = JaM.State; GetVec: PROC [state: JaM.State] RETURNS [z:Complex.VEC] = { z.y _ JaM.PopReal[state]; z.x _ JaM.PopReal[state]; }; ResetSa: PROC[state: State] = {FitState.ResetData[FitJaM.defaultFitState, samples, FALSE]}; ResetAllSa: PROC[state: State] = {FitState.ResetData[FitJaM.defaultFitState, samples, TRUE]}; AddSa: PROC[state: State] = { y: REAL _ JaM.PopReal[state]; x: REAL _ JaM.PopReal[state]; FitState.AddSample[FitJaM.defaultFitState, x,y]; }; CountSa: PROC[state: State] = { n: INT _ 0; count: FitStateUtils.SampleProc = {n _ n+1}; FitStateUtils.ForAllSamples[FitJaM.defaultFitState.slist,count]; JaM.PushInt[state,n]; }; SelectSa: PROC [state: JaM.State] = { closest: FitBasic.SampleHandle; z: Complex.VEC; z.y _ JaM.PopReal[state]; z.x _ JaM.PopReal[state]; [closest,] _ FindSa[z]; IF closest#NIL THEN FitJaM.defaultFitState.slist.selectedSample _ closest; }; TheSa: PROC [state: JaM.State] = { JaM.PushReal[state,FitJaM.defaultFitState.slist.selectedSample.xy.x]; JaM.PushReal[state,FitJaM.defaultFitState.slist.selectedSample.xy.y]; }; FindSa: PROC [z: Complex.VEC] RETURNS[found: FitBasic.SampleHandle, index: NAT] = { closest,d: REAL _ 10.0E+30; i: NAT _ 0; do: FitStateUtils.SampleProc = { p: Complex.VEC _ FitIO.MagnifyPoint[FitJaM.defaultFitIO, s.xy]; IF ABS[p.x-z.x] none, 1 => potential, 2 => forced, ENDCASE => none; }; TanIn: PROC [state: JaM.State] = { FitJaM.defaultFitState.slist.selectedSample.tanIn _ GetVec[state]}; TanOut: PROC [state: JaM.State] = { FitJaM.defaultFitState.slist.selectedSample.tanOut _ GetVec[state]}; ForceJoint: PROC [state: JaM.State] = {OPEN FitJaM.defaultFitState; IF slist.selectedSample.jointType#none THEN slist.selectedSample.jointType _ IF JaM.PopBool[state] THEN forced ELSE potential; }; Closed: PROC [state: JaM.State] = { FitJaM.defaultFitState.closed _ JaM.PopBool[state]}; HomeSa: PROC [state: JaM.State] = {OPEN FitJaM.defaultFitState; slist.selectedSample _ slist.header; }; MakeFirstSa: PROC [state: JaM.State] = {OPEN FitJaM.defaultFitState; IF slist.selectedSample # NIL THEN { slist.first _ slist.selectedSample; slist.last _ slist.first.prev; IF slist.last=slist.header THEN slist.last _ slist.last.prev; }; }; NextSa: PROC [state: JaM.State] = {OPEN FitJaM.defaultFitState; slist.selectedSample _ slist.selectedSample.next; IF slist.selectedSample = slist.header THEN slist.selectedSample _ slist.selectedSample.next }; PrevSa: PROC [state: JaM.State] = {OPEN FitJaM.defaultFitState; slist.selectedSample _ slist.selectedSample.prev; IF slist.selectedSample = slist.header THEN slist.selectedSample _ slist.selectedSample.prev }; ScaleSa: PROC [state: JaM.State] = { FitState.ScaleData[FitJaM.defaultFitState,JaM.PopReal[state], samples]; }; TranSa: PROC [state: JaM.State] = { z: Complex.VEC _ GetVec[state]; FitState.TranslateData[FitJaM.defaultFitState, z, samples]; }; InterpolateSa: PROC[state: State] = { OPEN FitJaM.defaultFitState; mindelta: REAL _ MAX[JaM.PopReal[state], 0.00001]; selected: FitBasic.SampleHandle _ slist.selectedSample; first: BOOLEAN _ TRUE; from: FitBasic.SampleHandle _ slist.header.next; do: FitStateUtils.SampleProc = { IF first THEN {from _ s; first _ FALSE} ELSE { to: FitBasic.SampleHandle _ s; delta: Complex.VEC _ Complex.Sub[to.xy, from.xy]; k: REAL _ Real.RoundLI[Complex.Abs[delta]/mindelta]; slist.selectedSample _ to; FOR i: REAL _ 1, i+1 UNTIL i>k DO v: Complex.VEC _ Complex.Add[s.xy, Vector.Mul[delta, i/(k+1)]]; FitState.InsertBeforeSample[FitJaM.defaultFitState, v.x,v.y]; ENDLOOP; from _ to; }; }; FitStateUtils.ForAllSamples[slist, do]; IF closed THEN [] _ do[slist.header.next]; slist.selectedSample _ selected; }; Subrange: PROC [state: JaM.State] = {OPEN FitJaM.defaultFitState; first,last: FitBasic.SampleHandle; p0,p1: Complex.VEC; i0,i1: NAT; p1.y _ JaM.PopReal[state]; p1.x _ JaM.PopReal[state]; [last,i1] _ FindSa[p1]; p0.y _ JaM.PopReal[state]; p0.x _ JaM.PopReal[state]; [first,i0] _ FindSa[p0]; IF i0 IF type=1 THEN {s.tanIn _ s.tanOut _ [0,0]}; forced => IF type=2 THEN {s.tanIn _ s.tanOut _ [0,0]}; ENDCASE => IF type=0 THEN {s.tanIn _ s.tanOut _ [0,0]} }; FitStateUtils.ForAllSamples[FitJaM.defaultFitState.slist, reset]; }; ForAllLinks: PROC[state: State] = { body: JaM.Any _ JaM.Pop[state]; do: FitStateUtils.LinkProc = { JaM.PushReal[state,l.cubic.b0.x]; JaM.PushReal[state,l.cubic.b0.y]; JaM.PushReal[state,l.cubic.b1.x]; JaM.PushReal[state,l.cubic.b1.y]; JaM.PushReal[state,l.cubic.b2.x]; JaM.PushReal[state,l.cubic.b2.y]; JaM.PushReal[state,l.cubic.b3.x]; JaM.PushReal[state,l.cubic.b3.y]; JaM.Execute[state, body ! JaM.Stop => CONTINUE]; }; FitStateUtils.ForAllLinks[FitJaM.defaultFitState.traj,do]; }; ResetCon: PROC[state: State] = {FitState.ResetData[FitJaM.defaultFitState, contours, FALSE]}; ResetAllCon: PROC[state: State] = {FitState.ResetData[FitJaM.defaultFitState, contours, TRUE]}; CountCon: PROC[state: State] = { JaM.PushInt[state, FitState.CountContours[FitJaM.defaultFitState]]}; AddCon: PROC[state: State] = {FitState.NewContour[FitJaM.defaultFitState]}; NextCon: PROC[state: State] = {FitState.NextContour[FitJaM.defaultFitState]}; SetSLen: PROC[state: State] = {FitState.SetMinDist[FitJaM.defaultFitState,JaM.PopReal[state]]}; CollectGarbage: PROC[state: State] = { SafeStorage.ReclaimCollectibleObjects[suspendMe: TRUE, traceAndSweep: TRUE]; }; Init: FitJaM.InitProc = { <> JaM.Register[state,".resetsa", ResetSa]; JaM.Register[state,".resetallsa", ResetAllSa]; JaM.Register[state,".addsa", AddSa]; JaM.Register[state,".countsa", CountSa]; JaM.Register[state,".selectsa", SelectSa]; -- x y => . Selects a sample point for editing JaM.Register[state,".interpolatesa", InterpolateSa]; -- d => . Interpolates samples to make deltas no larger than about d JaM.Register[state,".thesa", TheSa]; -- => x y . Returns the current sample JaM.Register[state,".thetanin", TheTanIn]; -- => x y boolean . Returns the tanIn of the current sample, and whether it is a node JaM.Register[state,".thetanout", TheTanOut]; -- => x y boolean . Returns the tanOut of the current sample, and whether it is a node JaM.Register[state,".deletesa", DeleteSa]; -- => . Deletes the current sample JaM.Register[state,".insertsa", InsertSa]; -- x y => . Inserts before the current sample JaM.Register[state,".insertbetween", InsertBetween]; -- x y => . Inserts between the current sample and the neighbor nearest the new point JaM.Register[state,".jointsa", JointSa]; -- type => . sets joint type: 0 (.false) = none, 1 (.true) = potential, 2 = forced JaM.Register[state,".tanIn", TanIn]; -- deltax deltay => . Sets the tanIn at selected sample JaM.Register[state,".tanOut", TanOut]; -- deltax deltay => . Sets the tanIn at selected sample JaM.Register[state,".forcejoint", ForceJoint]; -- boolean => . flips between potential and forced JaM.Register[state,".closed", Closed]; -- boolean => . Sets the closed bit on the samples JaM.Register[state,".homesa", HomeSa]; -- => . Selects the header JaM.Register[state,".makefirstsa", MakeFirstSa]; -- => . Selects the header JaM.Register[state,".nextsa", NextSa]; -- => x y . Moves selection to the next sample JaM.Register[state,".prevsa", PrevSa]; -- => x y . Moves selection to the previous sample JaM.Register[state,".scalesa", ScaleSa]; -- x y => . Scales/rotates all samples by multiplying by x+iy JaM.Register[state,".transa", TranSa]; -- x y => . Translates all samples by adding x+iy JaM.Register[state,".subrange", Subrange]; -- change CurrentSamples so it returns a subrange JaM.Register[state,".allsa", NoSubrange]; -- remove the subrange JaM.Register[state,".resetjoints", ResetJoints]; -- remove the nodes JaM.Register[state,".resetforcedjoints", ResetForcedJoints]; -- remove the corners JaM.Register[state,".resettangents", ResetTangents]; -- type => remove the tangents type: 0 = all, 1 = potential only, 2 = forced only JaM.Register[state,".foralllinks", ForAllLinks]; JaM.Register[state,".nextcon", NextCon]; JaM.Register[state,".resetcon", ResetCon]; JaM.Register[state,".resetallcon", ResetAllCon]; JaM.Register[state,".addcon", AddCon]; JaM.Register[state,".countcon", CountCon]; JaM.Register[state,".setslen", SetSLen]; JaM.Register[state,".collectgarbage", CollectGarbage]; }; FitJaM.RegisterInit[$FitEditJaM, Init]; }. <> <> <> <> <> <

> <> <> <<};>> < . moves the selected sample so it is colinear with its two left neightbors and with its two right neighbors>> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <<};>> <<>>