fix: correct colors of labels when point color defaults (#51)
Also fixes motion of points when pivoting if they lie on a circle that only later has its center identified as the pivot point (i.e., not yet at the time the pivotable point is being defined). Also implements the "center" method of constructing a point. With this PR, apparently all diagrams through Book III work OK. Reviewed-on: #51 Co-authored-by: Glen Whitney <glen@studioinfinity.org> Co-committed-by: Glen Whitney <glen@studioinfinity.org>
This commit is contained in:
parent
6489fb7fac
commit
29dfc54646
@ -77,6 +77,7 @@ type PivotData
|
|||||||
pivot: string
|
pivot: string
|
||||||
lastAngle: number
|
lastAngle: number
|
||||||
rotatable: string[]
|
rotatable: string[]
|
||||||
|
maybeRotatable: Record<string, string>
|
||||||
fixed: Record<string, boolean>
|
fixed: Record<string, boolean>
|
||||||
|
|
||||||
pivotData: Record<string, PivotData> := {}
|
pivotData: Record<string, PivotData> := {}
|
||||||
@ -112,13 +113,18 @@ function postApplets(jApplets: AppletDescription[], codebase = '')
|
|||||||
pivot = geoname(jApp.id, elements, 'point') + 'Pivot'
|
pivot = geoname(jApp.id, elements, 'point') + 'Pivot'
|
||||||
pivotData[pivot] = {
|
pivotData[pivot] = {
|
||||||
api, jApp.params.pivot,
|
api, jApp.params.pivot,
|
||||||
lastAngle: 0, rotatable: [], fixed: {}}
|
lastAngle: 0, rotatable: [], maybeRotatable: {}, fixed: {}}
|
||||||
cdata: ConstructionData := {
|
cdata: ConstructionData := {
|
||||||
bg: ([255, 255, 255] as RGB),
|
bg: ([255, 255, 255] as RGB),
|
||||||
is3d, jApp.id, jApp.width, jApp.height, elements, pivot}
|
is3d, jApp.id, jApp.width, jApp.height, elements, pivot}
|
||||||
for name, value in jApp.params
|
for name, value in jApp.params
|
||||||
dispatchJcommand
|
dispatchJcommand
|
||||||
api, name, value, cdata
|
api, name, value, cdata
|
||||||
|
if pivot
|
||||||
|
pd := pivotData[pivot]
|
||||||
|
for entity, circ in pd.maybeRotatable
|
||||||
|
if cdata.elements[circ].ends?[0] is pd.pivot
|
||||||
|
pd.rotatable.push entity
|
||||||
if is3d
|
if is3d
|
||||||
depth .= jApp.width
|
depth .= jApp.width
|
||||||
if jApp.height > depth then depth = jApp.height
|
if jApp.height > depth then depth = jApp.height
|
||||||
@ -350,8 +356,9 @@ function jToG(
|
|||||||
console.log 'Hiding point', point if traceC
|
console.log 'Hiding point', point if traceC
|
||||||
api.setVisible point, false
|
api.setVisible point, false
|
||||||
else if dimension is 0 or colors[1] // Need to color the points
|
else if dimension is 0 or colors[1] // Need to color the points
|
||||||
ptRGB := colors[1] ? joyce2rgb colors[1], cdata.bg
|
if not colors[1]
|
||||||
: pointDefaultRGB name, method, isPivot
|
colors[1] = pointDefaultColorName name, method, isPivot
|
||||||
|
ptRGB := joyce2rgb colors[1], cdata.bg
|
||||||
for each point of parts[0]
|
for each point of parts[0]
|
||||||
console.log 'Coloring point', point, 'to', colors[1] if traceC
|
console.log 'Coloring point', point, 'to', colors[1] if traceC
|
||||||
api.setVisible point, true
|
api.setVisible point, true
|
||||||
@ -361,24 +368,29 @@ function jToG(
|
|||||||
if invisible colors[0]
|
if invisible colors[0]
|
||||||
console.log 'Hiding label', name if traceC
|
console.log 'Hiding label', name if traceC
|
||||||
api.setLabelVisible name, false
|
api.setLabelVisible name, false
|
||||||
else if colors[dimension+1] and colors[dimension+1] is not colors[0]
|
else if colors[0]
|
||||||
|
if colors[dimension+1] and colors[dimension+1] is not colors[0]
|
||||||
// Have to make a text to provide the caption, since GeoGebra
|
// Have to make a text to provide the caption, since GeoGebra
|
||||||
// doesn't allow caption different color from entity.
|
// doesn't allow caption different color from entity.
|
||||||
textName := 'GeoText' + index
|
textName := 'GeoText' + index
|
||||||
locationExpr := switch klass
|
locationExpr := switch klass
|
||||||
when 'point' then `1.02${name}`
|
when 'point' then `1.02${name}`
|
||||||
when 'line'
|
when 'line'
|
||||||
(`Midpoint(${name}) + `
|
(`Midpoint(${name})`
|
||||||
+ `Rotate(Direction(${name})*Length(${name})*0.02, pi/2)`)
|
+ ` + Rotate(Direction(${name})`
|
||||||
|
+ `*Length(${name})*0.02, pi/2)`)
|
||||||
when 'circle'
|
when 'circle'
|
||||||
`Center(${name}) + Radius(${name})*Vector((12/13,5/13))*1.03`
|
(`Center(${name})`
|
||||||
|
+ ` + Radius(${name})*Vector((12/13,5/13))*1.03`)
|
||||||
when 'polygon' then `Centroid(${name})`
|
when 'polygon' then `Centroid(${name})`
|
||||||
when 'sector'
|
when 'sector'
|
||||||
`(5*Center(${name}) - ${cmdr.ends?[0]} - ${cmdr.ends?[1]})/3`
|
(`(5*Center(${name})`
|
||||||
|
+ ` - ${cmdr.ends?[0]} - ${cmdr.ends?[1]})/3`)
|
||||||
when 'plane'
|
when 'plane'
|
||||||
`Intersect(${name}, PerpendicularLine((0, 0, 0), ${name}))`
|
`Intersect(${name}, PerpendicularLine((0, 0, 0), ${name}))`
|
||||||
when 'sphere'
|
when 'sphere'
|
||||||
`Center(${name})+Radius(${name})*Vector((12/13,0,5/13))*1.03`
|
(`Center(${name})`
|
||||||
|
+ ` + Radius(${name})*Vector((12/13,0,5/13))*1.03`)
|
||||||
when 'polyhedron'
|
when 'polyhedron'
|
||||||
// The "ends" are faces or vertices roughly opposite
|
// The "ends" are faces or vertices roughly opposite
|
||||||
// from each other
|
// from each other
|
||||||
@ -394,14 +406,13 @@ function jToG(
|
|||||||
api.setColor textName, ...textCol
|
api.setColor textName, ...textCol
|
||||||
// and hide the underlying GeoGebra label
|
// and hide the underlying GeoGebra label
|
||||||
api.setLabelVisible name, false
|
api.setLabelVisible name, false
|
||||||
else if colors[0]
|
else // specified label color matches the entity color
|
||||||
// Label gets the correct color from element
|
// So label gets the correct color from element
|
||||||
// but we had better make sure it is visible:
|
// but we had better make sure it is visible:
|
||||||
console.log 'Showing label', name if traceC
|
console.log 'Showing label', name if traceC
|
||||||
api.setLabelVisible name, true
|
api.setLabelVisible name, true
|
||||||
else
|
else // label color is defaulting
|
||||||
// label color is defaulting. Same as element for points, invisible
|
// Make it same as the element for points, invisible otherwise:
|
||||||
// otherwise:
|
|
||||||
show := klass is 'point'
|
show := klass is 'point'
|
||||||
console.log 'Setting label vis of', name, 'to', show if traceC
|
console.log 'Setting label vis of', name, 'to', show if traceC
|
||||||
api.setLabelVisible name, show
|
api.setLabelVisible name, show
|
||||||
@ -486,14 +497,15 @@ function joyce2rgb(cname: string, backgroundRGB?: RGB): RGB
|
|||||||
console.warn 'Could not parse color:', cname
|
console.warn 'Could not parse color:', cname
|
||||||
[128, 128, 128]
|
[128, 128, 128]
|
||||||
|
|
||||||
function pointDefaultRGB(name: string, method: string, isPivot: boolean): RGB
|
function pointDefaultColorName(
|
||||||
if isPivot then return joyce2rgb 'green'
|
name: string, method: string, isPivot: boolean): string
|
||||||
|
if isPivot then return 'green'
|
||||||
switch method
|
switch method
|
||||||
'free'
|
'free'
|
||||||
joyce2rgb 'red'
|
'red'
|
||||||
/.*[Ss]lider$/
|
/.*[Ss]lider$/
|
||||||
joyce2rgb 'orange'
|
'orange'
|
||||||
else joyce2rgb 'black'
|
else 'black'
|
||||||
|
|
||||||
function geoname(
|
function geoname(
|
||||||
jname: JoyceName, elements: JoyceElements, klass: JoyceClass): GeoName
|
jname: JoyceName, elements: JoyceElements, klass: JoyceClass): GeoName
|
||||||
@ -564,14 +576,26 @@ classHandler: Record<JoyceClass, ClassHandler> :=
|
|||||||
makeAngDiv(method, args, cdata, aux, auxiliaries, commands)
|
makeAngDiv(method, args, cdata, aux, auxiliaries, commands)
|
||||||
unless foot return
|
unless foot return
|
||||||
commands.push `${name} = ${foot}`
|
commands.push `${name} = ${foot}`
|
||||||
|
'center'
|
||||||
|
entity := args.circle ? args.circle[0] : args.sphere?[0]
|
||||||
|
if entity
|
||||||
|
commands.push `${name} = Center(${entity})`
|
||||||
|
entityEnds := cdata.elements[entity].ends
|
||||||
|
if entityEnds and not entityEnds[0]
|
||||||
|
entityEnds[0] = name // labeled the center
|
||||||
|
else
|
||||||
|
console.warn 'Nothing to produce center point of in',
|
||||||
|
name, method, args
|
||||||
'circleSlider'
|
'circleSlider'
|
||||||
unless args.circle then return
|
unless args.circle then return
|
||||||
circ := args.circle[0]
|
circ := args.circle[0]
|
||||||
commands.push `${name} = Point(${circ})`
|
commands.push `${name} = Point(${circ})`
|
||||||
if (pivotable
|
if pivotable
|
||||||
and cdata.elements[circ].ends?[0] // center
|
maybeCenter := cdata.elements[circ].ends?[0]
|
||||||
is pivotData[cdata.pivot].pivot)
|
if maybeCenter is pivotData[cdata.pivot].pivot
|
||||||
pivotData[cdata.pivot].rotatable.push name
|
pivotData[cdata.pivot].rotatable.push name
|
||||||
|
if not maybeCenter
|
||||||
|
pivotData[cdata.pivot].maybeRotatable[name] = circ
|
||||||
if args.scalar and args.scalar.length
|
if args.scalar and args.scalar.length
|
||||||
callbacks.push (api: AppletObject) =>
|
callbacks.push (api: AppletObject) =>
|
||||||
api.setCoords name, ...vertFlipped(args.scalar or [], cdata)
|
api.setCoords name, ...vertFlipped(args.scalar or [], cdata)
|
||||||
@ -658,6 +682,7 @@ classHandler: Record<JoyceClass, ClassHandler> :=
|
|||||||
'vertex'
|
'vertex'
|
||||||
commands.push
|
commands.push
|
||||||
`${name} = Vertex(${args.polygon?[0]},${args.scalar?[0]})`
|
`${name} = Vertex(${args.polygon?[0]},${args.scalar?[0]})`
|
||||||
|
else console.warn 'Unknown point method:', method
|
||||||
|
|
||||||
line: (name, method, args, index, cdata) =>
|
line: (name, method, args, index, cdata) =>
|
||||||
return := freshCommander()
|
return := freshCommander()
|
||||||
@ -770,13 +795,6 @@ classHandler: Record<JoyceClass, ClassHandler> :=
|
|||||||
ends[0] = pt[0]
|
ends[0] = pt[0]
|
||||||
ends[1] = aux
|
ends[1] = aux
|
||||||
auxiliaries.push aux
|
auxiliaries.push aux
|
||||||
if args.line?.length is 1
|
|
||||||
ln := args.line[0]
|
|
||||||
commands.push
|
|
||||||
`${name} = Rotate(${ln}, pi/2, ${pt[0]}${inPlane})`
|
|
||||||
`${aux} = Vertex(${name}, 2)`
|
|
||||||
madeSegment = true
|
|
||||||
else
|
|
||||||
commands.push
|
commands.push
|
||||||
`${aux} = Rotate(${pt[1]}, pi/2, ${pt[0]}${inPlane})`
|
`${aux} = Rotate(${pt[1]}, pi/2, ${pt[0]}${inPlane})`
|
||||||
when 3
|
when 3
|
||||||
|
Loading…
Reference in New Issue
Block a user