feat: Enough commands to get to the @

This commit is contained in:
Glen Whitney 2023-09-19 00:31:02 -07:00
parent a55342ae95
commit 6905d73f57

View File

@ -57,7 +57,7 @@ function dispatchJcommand(api: AppletObject, param: Element): void
console.log `Geogebra command '${command}' translated from`, console.log `Geogebra command '${command}' translated from`,
val, 'failed.' val, 'failed.'
else else
console.log `Unknown command '${val}'` console.log `Could not parse command '${val}'`
else else
console.log `Unkown param ${param}` console.log `Unkown param ${param}`
@ -72,22 +72,44 @@ classHandler: Record<string, ClassHandler> :=
point: (name, method, data, colors) => point: (name, method, data, colors) =>
command .= '' command .= ''
callbacks: GeogebraCallback[] .= [] callbacks: GeogebraCallback[] .= []
args := data.split(',')
switch method switch method
/free|fixed/ /free|fixed/
command += `${name} = (${data})` command += `${name} = (${data})`
if method is 'fixed' if method is 'fixed'
callbacks.push (api: AppletObject) => api.setFixed(name, true) callbacks.push (api: AppletObject) => api.setFixed(name, true)
'perpendicular' 'perpendicular'
[center, direction] := data.split(',') [center, direction] := args
command += `${name} = Rotate(${direction}, 3*pi/2, ${center})` 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} return {command, callbacks}
line: (name, method, data, colors) => line: (name, method, data, colors) =>
command .= '' command .= ''
callbacks: GeogebraCallback[] .= [] callbacks: GeogebraCallback[] .= []
args := data.split(',')
switch method switch method
'connect' 'connect'
command += `${name} = Segment(${data})` 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} return {command, callbacks}
circle: (name, method, data, colors) => circle: (name, method, data, colors) =>