summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/base
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-04-03 22:35:04 +0000
committerKarl Berry <karl@freefriends.org>2018-04-03 22:35:04 +0000
commit36b8d1341af4a7ab1f5759d75ad1eecfc375c1f4 (patch)
tree12d09b686d2c18f245dc6fd492c09cdcd4c02ebc /Build/source/utils/asymptote/base
parentd73e029b665b866fe734e44508746a2cba513fd7 (diff)
asy 2.42 sources
git-svn-id: svn://tug.org/texlive/trunk@47274 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/base')
-rw-r--r--Build/source/utils/asymptote/base/geometry.asy2
-rw-r--r--Build/source/utils/asymptote/base/ode.asy3
-rw-r--r--Build/source/utils/asymptote/base/plain_Label.asy2
-rw-r--r--Build/source/utils/asymptote/base/plain_strings.asy38
-rw-r--r--Build/source/utils/asymptote/base/rational.asy223
-rw-r--r--Build/source/utils/asymptote/base/slide.asy24
6 files changed, 268 insertions, 24 deletions
diff --git a/Build/source/utils/asymptote/base/geometry.asy b/Build/source/utils/asymptote/base/geometry.asy
index 2bc062f3560..245c59ec084 100644
--- a/Build/source/utils/asymptote/base/geometry.asy
+++ b/Build/source/utils/asymptote/base/geometry.asy
@@ -1296,7 +1296,7 @@ void perpendicularmark(picture pic = currentpicture, point z,
relative to the path z--z + dir.
dir(45 + n * 90), where n in N*, are common values for 'align'.</documentation></function></asyxml>*/
p = squarecap + miterjoin + p;
- if(size == 0) size = perpfactor * 3mm + sqrt(1 + linewidth(p)) - 1;
+ if(size == 0) size = perpfactor * 3mm + linewidth(p) / 2;
frame apic;
pair d1 = size * align * unit(dir) * dir(-45);
pair d2 = I * d1;
diff --git a/Build/source/utils/asymptote/base/ode.asy b/Build/source/utils/asymptote/base/ode.asy
index 51941844fc4..7104a8d1532 100644
--- a/Build/source/utils/asymptote/base/ode.asy
+++ b/Build/source/utils/asymptote/base/ode.asy
@@ -264,7 +264,7 @@ solution integrate(real y, real c=0, real f(real t, real y), real a, real b=a,
{
solution S;
S.t=new real[] {a};
- S.y=new real[]{y};
+ S.y=new real[] {y};
if(h == 0) {
if(b == a) return S;
@@ -323,6 +323,7 @@ solution integrate(real y, real c=0, real f(real t, real y), real a, real b=a,
} else {
t += h;
y=y0+highOrder;
+ S.t.push(t);
S.y.push(y);
}
}
diff --git a/Build/source/utils/asymptote/base/plain_Label.asy b/Build/source/utils/asymptote/base/plain_Label.asy
index 1e424ab1c0a..516ed4be711 100644
--- a/Build/source/utils/asymptote/base/plain_Label.asy
+++ b/Build/source/utils/asymptote/base/plain_Label.asy
@@ -1,7 +1,7 @@
real angle(transform t)
{
pair z=(2t.xx*t.yy,t.yx*t.yy-t.xx*t.xy);
- if(t.xx < 0) z=-z;
+ if(t.xx < 0 || t.yy < 0) z=-z;
return degrees(z,warn=false);
}
diff --git a/Build/source/utils/asymptote/base/plain_strings.asy b/Build/source/utils/asymptote/base/plain_strings.asy
index a88e3863416..c109fc491f7 100644
--- a/Build/source/utils/asymptote/base/plain_strings.asy
+++ b/Build/source/utils/asymptote/base/plain_strings.asy
@@ -85,7 +85,7 @@ string verbatim(string s)
// Split a string into an array of substrings delimited by delimiter
// If delimiter is an empty string, use space delimiter but discard empty
-// substrings.
+// substrings. TODO: Move to C++ code.
string[] split(string s, string delimiter="")
{
bool prune=false;
@@ -109,6 +109,27 @@ string[] split(string s, string delimiter="")
return S;
}
+// Returns an array of strings obtained by splitting s into individual
+// characters. TODO: Move to C++ code.
+string[] array(string s)
+{
+ int len=length(s);
+ string[] S=new string[len];
+ for(int i=0; i < len; ++i)
+ S[i]=substr(s,i,1);
+ return S;
+}
+
+// Concatenate an array of strings into a single string.
+// TODO: Move to C++ code.
+string operator +(...string[] a)
+{
+ string S;
+ for(string s : a)
+ S += s;
+ return S;
+}
+
int system(string s)
{
return system(split(s));
@@ -208,19 +229,10 @@ void pause(string w="Hit enter to continue")
w=stdin;
}
-string math(real x)
-{
- return math((string) x);
-}
-
-string format(string format, real x, string locale="")
-{
- return format(format,defaultseparator,x,locale);
-}
-
-string format(real x, string locale="")
+string format(string format=defaultformat, bool forcemath=false, real x,
+ string locale="")
{
- return format(defaultformat,defaultseparator,x,locale);
+ return format(format,forcemath,defaultseparator,x,locale);
}
string phantom(string s)
diff --git a/Build/source/utils/asymptote/base/rational.asy b/Build/source/utils/asymptote/base/rational.asy
new file mode 100644
index 00000000000..0fa4ee36afa
--- /dev/null
+++ b/Build/source/utils/asymptote/base/rational.asy
@@ -0,0 +1,223 @@
+// Asymptote module implementing rational arithmetic.
+
+int gcd(int m, int n)
+{
+ if(m < n) {
+ int temp=m;
+ m=n;
+ n=temp;
+ }
+ while(n != 0) {
+ int r=m % n;
+ m=n;
+ n=r;
+ }
+ return m;
+}
+
+int lcm(int m, int n)
+{
+ return m#gcd(m,n)*n;
+}
+
+struct rational {
+ int p=0,q=1;
+ void reduce() {
+ int d=gcd(p,q);
+ if(abs(d) > 1) {
+ p #= d;
+ q #= d;
+ }
+ if(q <= 0) {
+ if(q == 0) abort("Division by zero");
+ p=-p;
+ q=-q;
+ }
+ }
+ void operator init(int p=0, int q=1, bool reduce=true) {
+ this.p=p;
+ this.q=q;
+ if(reduce) reduce();
+ }
+}
+
+rational operator cast(int p) {
+ return rational(p,false);
+}
+
+rational[] operator cast(int[] a) {
+ return sequence(new rational(int i) {return a[i];},a.length);
+}
+
+rational[][] operator cast(int[][] a) {
+ return sequence(new rational[](int i) {return a[i];},a.length);
+}
+
+real operator ecast(rational r) {
+ return r.p/r.q;
+}
+
+rational operator -(rational r)
+{
+ return rational(-r.p,r.q,false);
+}
+
+rational operator +(rational r, rational s)
+{
+ return rational(r.p*s.q+s.p*r.q,r.q*s.q);
+}
+
+rational operator -(rational r, rational s)
+{
+ return rational(r.p*s.q-s.p*r.q,r.q*s.q);
+}
+
+rational operator *(rational r, rational s)
+{
+ return rational(r.p*s.p,r.q*s.q);
+}
+
+rational operator /(rational r, rational s)
+{
+ return rational(r.p*s.q,r.q*s.p);
+}
+
+bool operator ==(rational r, rational s)
+{
+ return r.p == s.p && r.q == s.q;
+}
+
+bool operator <(rational r, rational s)
+{
+ return r.p*s.q-s.p*r.q < 0;
+}
+
+bool operator >(rational r, rational s)
+{
+ return r.p*s.q-s.p*r.q > 0;
+}
+
+bool operator <=(rational r, rational s)
+{
+ return r.p*s.q-s.p*r.q <= 0;
+}
+
+bool operator >=(rational r, rational s)
+{
+ return r.p*s.q-s.p*r.q >= 0;
+}
+
+bool[] operator ==(rational[] r, rational s)
+{
+ return sequence(new bool(int i) {return r[i] == s;},r.length);
+}
+
+bool operator ==(rational[] r, rational[] s)
+{
+ if(r.length != s.length)
+ abort(" operation attempted on arrays of different lengths: "+
+ string(r.length)+" != "+string(s.length));
+ return all(sequence(new bool(int i) {return r[i] == s[i];},r.length));
+}
+
+bool operator ==(rational[][] r, rational[][] s)
+{
+ if(r.length != s.length)
+ abort(" operation attempted on arrays of different lengths: "+
+ string(r.length)+" != "+string(s.length));
+ return all(sequence(new bool(int i) {return r[i] == s[i];},r.length));
+}
+
+rational min(rational a, rational b)
+{
+ return a <= b ? a : b;
+}
+
+rational max(rational a, rational b)
+{
+ return a >= b ? a : b;
+}
+
+
+void write(string s="", rational r, suffix suffix=endl) {
+ if(r.q == 1)
+ write(s+string(r.p),suffix);
+ else
+ write(s+string(r.p)+"/"+string(r.q),suffix);
+}
+
+void write(string s="", rational[] a, suffix suffix=endl) {
+ if(s != "")
+ write(s);
+ for(int i=0; i < a.length; ++i) {
+ write(i,none);
+ write(':\t',a[i]);
+ }
+ write(suffix);
+}
+
+void write(string s="", rational[][] a, suffix suffix=endl) {
+ if(s != "")
+ write(s);
+ for(int i=0; i < a.length; ++i) {
+ rational[] ai=a[i];
+ for(int j=0; j < ai.length; ++j) {
+ write(ai[j],tab);
+ }
+ write();
+ }
+ write(suffix);
+}
+
+bool rectangular(rational[][] m)
+{
+ int n=m.length;
+ if(n > 0) {
+ int m0=m[0].length;
+ for(int i=1; i < n; ++i)
+ if(m[i].length != m0) return false;
+ }
+ return true;
+}
+
+rational sum(rational[] a)
+{
+ rational sum;
+ for(rational r:a)
+ sum += r;
+ return sum;
+}
+
+rational max(rational[] a)
+{
+ rational M=a[0];
+ for(rational r:a)
+ M=max(M,r);
+ return M;
+}
+
+rational abs(rational r)
+{
+ return rational(abs(r.p),r.q,false);
+}
+
+
+/*
+rational r=rational(1,3)+rational(1,4);
+write(r == rational(1,12));
+write(r);
+real x=r;
+write(x);
+
+rational r=3;
+write(r);
+
+write(gcd(-8,12));
+write(rational(-36,-14));
+
+int[][] a=new int[][] {{1,2},{3,4}};
+rational[][] r=a;
+write(r);
+
+*/
+
diff --git a/Build/source/utils/asymptote/base/slide.asy b/Build/source/utils/asymptote/base/slide.asy
index 433426c2f37..6195a97ec01 100644
--- a/Build/source/utils/asymptote/base/slide.asy
+++ b/Build/source/utils/asymptote/base/slide.asy
@@ -43,6 +43,8 @@ pen urlpen=datepen;
real itemskip=0.5;
real codeskip=0.25;
+real aboveequationskip=-1.25;
+
pair dateskip=(0,0.1);
pair urlskip=(0,0.2);
@@ -165,6 +167,7 @@ normalvideo();
texpreamble(bulletcolor(newbulletcolor));
texpreamble("\hyphenpenalty=10000\tolerance=1000");
+texpreamble("\usepackage{amsmath}");
// Evaluate user command line option.
void usersetting()
@@ -309,24 +312,29 @@ void center(string s, pen p=itempen)
remark("\center "+s,p);
}
-void equation(string s, pen p=itempen)
+void vbox(string s, pen p=itempen)
{
- remark(center=true,"\vbox{$$"+s+"$$}",p,minipage=false,skip=0);
+ remark(center=true,"\vbox{"+s+"}",p,minipage=false,skip=0);
}
-void vbox(string s, pen p=itempen)
+void skip(real n=1)
{
- remark(center=true,"\vbox{"+s+"}",p,minipage=false,skip=0);
+ incrementposition((0,(tinv*(-n*itemskip*I*lineskip(itempen)*pt)).y));
}
-void equations(string s, pen p=itempen)
+void equation(string s, pen p=itempen)
{
- vbox("\begin{eqnarray*}"+s+"\end{eqnarray*}",p);
+ skip(aboveequationskip);
+ vbox("\begin{gather*}"+s+"\end{gather*}",p);
}
-void skip(real n=1)
+void equations(string s, pen p=itempen)
{
- incrementposition((0,(tinv*(-n*itemskip*I*lineskip(itempen)*pt)).y));
+ skip(aboveequationskip);
+ if(find(s,"&") >= 0)
+ vbox("\begin{align*}"+s+"\end{align*}",p);
+ else
+ vbox("\begin{gather*}"+s+"\end{gather*}",p);
}
void display(frame[] f, real margin=0, pair align=S, pen p=itempen,