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) =>