From 6905d73f572909055f2037d60feca0f6a8a0e4d0 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Tue, 19 Sep 2023 00:31:02 -0700 Subject: [PATCH] feat: Enough commands to get to the @ --- src/adapptlet.civet | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/adapptlet.civet b/src/adapptlet.civet index 2bc1f99..5fbc3fb 100644 --- a/src/adapptlet.civet +++ b/src/adapptlet.civet @@ -57,7 +57,7 @@ function dispatchJcommand(api: AppletObject, param: Element): void console.log `Geogebra command '${command}' translated from`, val, 'failed.' else - console.log `Unknown command '${val}'` + console.log `Could not parse command '${val}'` else console.log `Unkown param ${param}` @@ -72,22 +72,44 @@ classHandler: Record := point: (name, method, data, colors) => command .= '' callbacks: GeogebraCallback[] .= [] + args := data.split(',') switch method /free|fixed/ command += `${name} = (${data})` if method is 'fixed' callbacks.push (api: AppletObject) => api.setFixed(name, true) 'perpendicular' - [center, direction] := data.split(',') + [center, direction] := args command += `${name} = Rotate(${direction}, 3*pi/2, ${center})` + 'angleDivider' + n .= -1 + // use the fact that NaN doesn't equal itself: + nLoc := args.findIndex((arg) => (n = parseInt arg) is n) + if n >= 0 + args.splice(nLoc) + [center, start, end] := args + command += `${name}aUx1 = Segment(${start}, ${end}) + ${name}aUx2 = Angle(${start}, ${center}, ${end}) + ${name}aUx2a = If(${name}aUx2 > pi, ${name}aUx2 - 2*pi, ${name}aUx2) + ${name}aUx3 = Rotate(${start}, ${name}aUx2a/${n}, ${center}) + ${name}aUx4 = Ray(${center}, ${name}aUx3) + ${name} = Intersect(${name}aUx1, ${name}aUx4)` + 'intersection' + command += `${name} = Intersect(${data})` return {command, callbacks} line: (name, method, data, colors) => command .= '' callbacks: GeogebraCallback[] .= [] + args := data.split(',') switch method 'connect' command += `${name} = Segment(${data})` + 'parallel' + [newStart, oldStart, oldEnd] := args + command += `${name}aUx1 = Vector(${oldStart}, ${newStart}) + ${name}aUx2 = Translate(${oldEnd}, ${name}aUx1) + ${name} = Segment(${newStart}, ${name}aUx2)` return {command, callbacks} circle: (name, method, data, colors) => -- 2.34.1