From 71a3fd4cc4ec46b4a30b169bfaffecd8e45f69aa Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Tue, 17 Oct 2023 18:04:50 -0700 Subject: [PATCH] feat: Get all Rostamian's old pages working This commit is just the last piece in the puzzle, implementing the perpendicular method for lines. Resolves #36. --- src/adapptlet.civet | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/adapptlet.civet b/src/adapptlet.civet index 2542a4b..7ae1262 100644 --- a/src/adapptlet.civet +++ b/src/adapptlet.civet @@ -257,6 +257,7 @@ function jToG( cmdr.callbacks.push (api: AppletObject) => for each aux of cmdr.auxiliaries api.setAuxiliary aux, true + api.setLabelVisible aux, false api.setVisible aux,false // set up the pivot if there is one @@ -405,7 +406,6 @@ function pivotListener(slider: string) for each anchor of pd.rotatable relX[anchor] = pd.api.getXcoord(anchor) - pX relY[anchor] = pd.api.getYcoord(anchor) - pY - console.log 'Unfixing', anchor, relX[anchor], relY[anchor] pd.api.setFixed anchor, false ct := Math.cos rotation st := Math.sin rotation @@ -414,7 +414,6 @@ function pivotListener(slider: string) rY := relY[anchor]*ct + relX[anchor]*st pd.api.setCoords(anchor, rX + pX, rY + pY) if pd.fixed[anchor] - console.log 'Re-fixing', anchor, rX, rY pd.api.setFixed anchor, true function invisible(cname: string): boolean @@ -712,6 +711,41 @@ classHandler: Record := madeSegment = true else commands.push `${aux}2 = Translate(${oldEnd}, ${aux}1)` + 'perpendicular' + pt := args.subpoints + unless pt then return + inPlane .= '' + if cdata.is3d + unless args.plane?.length is 1 then return + inPlane = `,${args.plane[0]}` + switch pt.length + when 2 + ends[0] = pt[0] + ends[1] = aux + auxiliaries.push aux + if args.line?.length is 1 + ln := args.line[0] + commands.push + `${name} = Rotate(${ln}, 3*pi/2, ${pt[0]}${inPlane})` + `${aux} = Vertex(${name}, 2)` + madeSegment = true + else + commands.push + `${aux} = Rotate(${pt[1]}, 3*pi/2, ${pt[0]}${inPlane})` + when 3 + return // TODO: line perpendicular to plane + when 4 + ends[0] = pt[0] + ends[1] = aux + 2 + auxiliaries.push aux+1, aux+2 + commands.push + `${aux}1 = Rotate(${pt[1]}, 3*pi/2, ${pt[0]}${inPlane})` + unitVec := `UnitVector(Vector(${pt[0]}, ${aux}1))` + dist := `Distance(${pt[2]}, ${pt[3]})` + commands.push + `${aux}2 = Translate(${pt[0]}, ${dist}*${unitVec})` + else return + unless madeSegment commands.push `${name} = Segment(${ends[0]},${ends[1]})` callbacks.push (api: AppletObject) => api.setLabelVisible name, true