feat: Enough commands to get to the @ (#29)

Reviewed-on: #29
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Co-committed-by: Glen Whitney <glen@studioinfinity.org>
This commit is contained in:
Glen Whitney 2023-09-19 07:32:11 +00:00 committed by Glen Whitney
parent a55342ae95
commit 550ce0168c

View File

@ -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<string, ClassHandler> :=
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) =>