feat: Start implementing Rostamian's pages (#39)

Began with incenter.html, the first one alphabetically. Needed one
  new point construction method, and a new option to see what was
  going on.

  Got the planar diagrams on that page working. The next step on #36 will
  be to get 3D diagrams as the theorem on this page generalizes to 3D. That
  will be a bigger task, so merging this now.

Reviewed-on: #39
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Co-committed-by: Glen Whitney <glen@studioinfinity.org>
This commit is contained in:
Glen Whitney 2023-10-06 19:38:56 +00:00 committed by Glen Whitney
parent e7361f94a7
commit c99b51dafa
21 changed files with 3549 additions and 37 deletions

View file

@ -303,6 +303,7 @@ function jToG(
cmdr
function invisible(cname: string): boolean
if adapParams.config?.showall then return false
cname is '0' or cname is 'none'
function joyce2rgb(cname: string, backgroundRGB?: RGB): RGB
@ -378,16 +379,6 @@ classHandler: Record<JoyceClass, ClassHandler> :=
aux := name + 'aUx'
parts[0].push name
switch method
/free|fixed/
commands.push `${name} = (${args.scalar?.join ','})`
if method is 'fixed'
callbacks.push (api: AppletObject) => api.setFixed name, true
'perpendicular'
// Note only the two-point option implemented so far
unless args.subpoints return
[center, direction] := args.subpoints
// Note clockwise 90° rotation (3π/2) confirmed in Joyce source
commands.push `${name} = Rotate(${direction}, 3*pi/2, ${center})`
'angleDivider'
// Note doesn't yet handle plane argument
unless args.subpoints return
@ -406,6 +397,27 @@ classHandler: Record<JoyceClass, ClassHandler> :=
`${aux}4 = Rotate(${start}, ${aux}3/${n}, ${center})`
`${name} = Intersect(${destination}, Ray(${center}, ${aux}4))`
auxiliaries.push ...[2..4].map (i) => `${aux}${i}`
'extend'
unless args.subpoints then return
sp := args.subpoints
direction .= `UnitVector(Vector(${sp[0]},${sp[1]}))`
if args.line and (
not args.point or args.point[0] !== args.subpoints[0])
direction = `UnitVector(${args.line[0]})`
displacement := `Distance(${sp[2]}, ${sp[3]})*${direction}`
commands.push `${name} = Translate(${sp[1]}, ${displacement})`
'first'
unless args.subpoints then return
commands.push `${name} = ${args.subpoints[0]}`
/fixed|free/
commands.push `${name} = (${args.scalar?.join ','})`
if method is 'fixed'
callbacks.push (api: AppletObject) => api.setFixed name, true
'foot'
pt := args.subpoints
unless pt then return
commands.push
`${name} = ClosestPoint(Line(${pt[1]},${pt[2]}), ${pt[0]})`
'intersection'
// Checking Joyce source, means intersection of lines, not
// intersection of line segments
@ -413,6 +425,9 @@ classHandler: Record<JoyceClass, ClassHandler> :=
l1 := `Line(${args.subpoints[0]},${args.subpoints[1]})`
l2 := `Line(${args.subpoints[2]},${args.subpoints[3]})`
commands.push `${name} = Intersect(${l1},${l2})`
'last'
unless args.subpoints then return
commands.push `${name} = ${args.subpoints.at(-1)}`
'lineSegmentSlider'
segment .= args.line?[0]
unless segment
@ -424,35 +439,28 @@ classHandler: Record<JoyceClass, ClassHandler> :=
if args.scalar and args.scalar.length
callbacks.push (api: AppletObject) =>
api.setCoords name, ...args.scalar as XYZ
'first'
unless args.subpoints then return
commands.push `${name} = ${args.subpoints[0]}`
'last'
unless args.subpoints then return
commands.push `${name} = ${args.subpoints.at(-1)}`
'extend'
unless args.subpoints then return
sp := args.subpoints
direction .= `UnitVector(Vector(${sp[0]},${sp[1]}))`
if args.line and (
not args.point or args.point[0] !== args.subpoints[0])
direction = `UnitVector(${args.line[0]})`
displacement := `Distance(${sp[2]}, ${sp[3]})*${direction}`
commands.push `${name} = Translate(${sp[1]}, ${displacement})`
'vertex'
commands.push
`${name} = Vertex(${args.polygon?[0]},${args.scalar?[0]})`
'midpoint'
if args.line
commands.push `${name} = Midpoint(${args.line[0]})`
else
commands.push
`${name} = Midpoint(${args.point?[0]},${args.point?[1]})`
'foot'
'perpendicular'
// Note only the two-point option implemented so far
unless args.subpoints return
[center, direction] := args.subpoints
// Note clockwise 90° rotation (3π/2) confirmed in Joyce source
commands.push `${name} = Rotate(${direction}, 3*pi/2, ${center})`
'proportion'
pt := args.subpoints
unless pt then return
len := `Distance(${pt[2]},${pt[3]})*Distance(${pt[4]},${pt[5]})`
+ `/ Distance(${pt[0]},${pt[1]})`
direction := `UnitVector(Vector(${pt[6]}, ${pt[7]}))`
commands.push `${name} = Translate(${pt[6]}, ${len}*${direction})`
'vertex'
commands.push
`${name} = ClosestPoint(Line(${pt[1]},${pt[2]}), ${pt[0]})`
`${name} = Vertex(${args.polygon?[0]},${args.scalar?[0]})`
line: (name, method, args) =>
return := freshCommander()

View file

@ -1,4 +1,4 @@
export const flags = ['commands', 'color'] as const
export const flags = ['color', 'commands', 'showall'] as const
export type FlagType = (typeof flags)[number]
export type ConfigType = Partial<Record<FlagType, boolean>>

View file

@ -1,11 +1,8 @@
import {flags} from ./adapptypes.ts
console.log('arrived')
boxes := ['commands', 'color']
cache := await browser.storage.local.get boxes
console.log('Found', cache)
cache := await browser.storage.local.get flags
for each box of boxes
for each box of flags
checkbox := document.getElementById(box) as HTMLInputElement
unless checkbox then continue
checkbox.checked = cache[box] ?? false