Skip to content

Commit

Permalink
Merge pull request #898 from CindyJS/kortenkamp/fix-reference-in-string
Browse files Browse the repository at this point in the history
Fixes handling of @# syntax in texts.
  • Loading branch information
kortenkamp committed Jun 19, 2023
2 parents 676896f + 4654caf commit b02fcf2
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 74 deletions.
119 changes: 49 additions & 70 deletions examples/165_stellenwerttafel.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">

<title>Stellenwerttafel-Tausendstel.cdy</title>
<title>Stellenwerttafel mit Tausendsteln (C)2011-2022 Ulrich Kortenkamp</title>
<style type="text/css">
html,body { margin: 0px; padding: 0px; }
html,body,#CSCanvas { width: 100%; height: 100%; }
Expand All @@ -24,8 +24,8 @@
width: 100%;
}
</style>
<link rel="stylesheet" href="../build/js/CindyJS.css">
<script type="text/javascript" src="../build/js/Cindy.js"></script>
<link rel="stylesheet" href="../build/js/CindyJS.css" />
<script type="text/javascript" src="../build/js/Cindy.js"></script>
<script id="csinit" type="text/x-cindyscript">
zaehler =0;
zaehler():= (zaehler = zaehler+1;zaehler);
Expand Down Expand Up @@ -100,7 +100,7 @@
);

fadein(pts,startcoord):= (
err("fadin"+pts+"-"+startcoord);
//err("fadin"+pts+"-"+startcoord);
faders = faders ++ [[pts,startcoord,0]];
)

Expand Down Expand Up @@ -166,73 +166,52 @@
;
</script>
<script id="csmouseup" type="text/x-cindyscript">
partition=partition();
partition=partition();
if (movingpoint != 0,

endpartition = select(1..anz,contains(partition_#,movingpoint))_1;

err("moved from "+startpartition+" to "+endpartition);

if (startpartition < endpartition,
// do we have enough points in startpartition?
need = pot_endpartition/pot_startpartition - 1;
avail = length(partition_startpartition);
err("we need " + need + " points");
err("we have " + avail + " points");
if (need > avail,

moveback(movingpoint,startofmover),

movers = (partition_startpartition)_(1..need);
movepartition(movers,startpartition,endpartition,movingpoint.xy);
);

,
// we have to create lots of new points

tocreate = pot_startpartition/pot_endpartition -1;
//err("creating "+tocreate+" points");
dd=(startpartition-endpartition);
newpoints = apply(1..tocreate,(
p = createpoint("P"+zaehler()+"-"+#,startofmover);
p.labelled=false;
p.size=10;
p.alpha=0;
p.color=movingpoint.color;
phi=random(2*π);
dir=(sin(phi),cos(phi));
c=movingpoint.xy+(random(dd)+.5)*dir;
while(!inpart(endpartition,c),
phi=random(2*π);
dir=(sin(phi),cos(phi));
c=movingpoint.xy+(random(dd)+.5)*dir;
);
(p, c);
););
fadein(newpoints,movingpoint.xy);
ppp =select(1..anz,contains(partition_#,movingpoint));
if(and(length(ppp)>0, !isundefined(startpartition)),
endpartition = ppp_1;
//err("moved from "+startpartition+" to "+endpartition);
if (startpartition < endpartition,
// do we have enough points in startpartition?
need = pot_endpartition/pot_startpartition - 1;
avail = length(partition_startpartition);
//err("we need " + need + " points");
//err("we have " + avail + " points");
if (need > avail,
moveback(movingpoint,startofmover),
movers = (partition_startpartition)_(1..need);
movepartition(movers,startpartition,endpartition,movingpoint.xy);
);
,
// we have to create lots of new points
tocreate = pot_startpartition/pot_endpartition -1;
//err("creating "+tocreate+" points");
dd=(startpartition-endpartition);
newpoints = apply(1..tocreate,(
p = createpoint("P"+zaehler()+"-"+#,startofmover);
p.labelled=false;
p.size=10;
p.alpha=0;
p.color=movingpoint.color;
phi=random(2*π);
dir=(sin(phi),cos(phi));
c=movingpoint.xy+(random(dd)+.5)*dir;
while(!inpart(endpartition,c),
phi=random(2*π);
dir=(sin(phi),cos(phi));
c=movingpoint.xy+(random(dd)+.5)*dir;
);
(p, c);
););
fadein(newpoints,movingpoint.xy);
);
,
partition=partition(); lastpartition=partition;
);
,
partition=partition(); lastpartition=partition;
);
, partition=partition(); lastpartition=partition;

);


















;
</script>
<script id="csdraw" type="text/x-cindyscript">
x=0;
Expand Down Expand Up @@ -332,7 +311,7 @@
startpos=0;
movingpoint=0;
if (length(moving)==0,
err("create point");
//err("create point");
repeat(anz,x,
if(inpart(x,mouse()),
new = createpoint("P"+zaehler(),mouse());
Expand Down
56 changes: 56 additions & 0 deletions examples/166_coords_in_text.html
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>Konstruktion.cdy</title>
<style type="text/css">
* {
margin: 0px;
padding: 0px;
}

#CSConsole {
background-color: #FAFAFA;
border-top: 1px solid #333333;
bottom: 0px;
height: 200px;
overflow-y: scroll;
position: fixed;
width: 100%;
}
</style>
<link rel="stylesheet" href="../build/js/CindyJS.css" />
<script type="text/javascript" src="../build/js/Cindy.js"></script>
<script type="text/javascript">
var cdy = CindyJS({
scripts: "cs*",
defaultAppearance: {
dimDependent: 0.7,
fontFamily: "sans-serif",
lineSize: 1,
pointSize: 5.0,
textsize: 12.0
},
angleUnit: "°",
geometry: [
{name: "A", type: "Free", pos: [-2.522522522522522, -4.0, -0.9009009009009008], color: [1.0, 0.0, 0.0], labeled: true},
{name: "Text0", type: "Text", pos: [4.88, 3.68, 1.0], color: [0.0, 0.0, 0.0], args: ["A"], text: "The coordinates of @$\"A\" are @#\"A\""}
],
ports: [{
id: "CSCanvas",
width: 680,
height: 336,
transform: [{visibleRect: [-9.06, 9.34, 18.14, -4.1]}],
background: "rgb(168,176,192)"
}],
csconsole: false,
use: ["katex"],
cinderella: {build: 2008, version: [3, 0, 2008]}
});
</script>
</head>
<body>
<div id="CSCanvas"></div>
</body>
</html>
10 changes: 6 additions & 4 deletions src/js/libgeo/GeoRender.js
Expand Up @@ -3,6 +3,7 @@ import { CSNumber } from "libcs/CSNumber";
import { List } from "libcs/List";
import { General } from "libcs/General";
import { eval_helper, evaluator, niceprint } from "libcs/Essentials";
import { Accessor } from "libcs/Accessors";
import { textRendererHtml } from "libcs/OpDrawing";
import { Render2D } from "libcs/Render2D";
import { csport } from "libgeo/GeoState";
Expand Down Expand Up @@ -245,17 +246,18 @@ function drawgeotext(el) {
let name, el2;
try {
name = JSON.parse(match.substring(2));
el2 = csgeo.csnames[name];
el2 = csgeo.csnames[name]; // this does not deliver the ctype of el2, as ctype is separate from elements.
if (!el2) return "?";
} catch (err) {
return "?";
}
switch (match.charAt(1)) {
case "$":
return el2.printname || name;
case "#":
if (el2.kind !== "V") return "?";
return niceprint(el2.value);
case "#": // I do not like this. I would prefer an oo-approach.
if (el2.kind === "P") return niceprint(Accessor.getField(el2, "xy"));
if (el2.kind == "V") return niceprint(el2.value);
return el2.value;
}
});
let htmlCallback = null;
Expand Down

0 comments on commit b02fcf2

Please sign in to comment.