summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/base
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2009-06-03 23:38:09 +0000
committerKarl Berry <karl@freefriends.org>2009-06-03 23:38:09 +0000
commit62e3ddd373e2bd1e5adbc7e45af95ba7150c03e6 (patch)
treebe497aba8d1c52ad428bf5649c53abb9fa59f8ff /Build/source/utils/asymptote/base
parent37f7f3460f7d20564974e440e873a84ca4570529 (diff)
asymptote 1.75
git-svn-id: svn://tug.org/texlive/trunk@13620 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/base')
-rw-r--r--Build/source/utils/asymptote/base/bezulate.asy13
-rw-r--r--Build/source/utils/asymptote/base/plain_pens.asy12
-rw-r--r--Build/source/utils/asymptote/base/three.asy55
-rw-r--r--Build/source/utils/asymptote/base/three_surface.asy14
4 files changed, 54 insertions, 40 deletions
diff --git a/Build/source/utils/asymptote/base/bezulate.asy b/Build/source/utils/asymptote/base/bezulate.asy
index 2710996b322..01b3024f7b6 100644
--- a/Build/source/utils/asymptote/base/bezulate.asy
+++ b/Build/source/utils/asymptote/base/bezulate.asy
@@ -1,6 +1,6 @@
// Bezier triangulation routines written by Orest Shardt, 2008.
-private real fuzz=sqrtEpsilon;
+private real fuzz=1e-6;
real duplicateFuzz=1e-3; // Work around font errors.
int countIntersections(path[] p, pair start, pair end)
@@ -95,19 +95,22 @@ void connect(path[] paths, path[] result, path[] patch)
real d=2*abs(max(outer)-min(outer));
while(inners.length > 0) {
int curveIndex = 0;
- real starttime = 0; // starttime is time on inners[curveIndex]
- pair direction=I*dir(inners[curveIndex],starttime);
- pair start=point(inners[curveIndex],starttime);
+ pair direction=I*dir(inners[curveIndex],0,1); // Use outgoing direction
+ if(direction == 0) // Try a random direction
+ direction=expi(2pi*unitrand());
+ pair start=point(inners[curveIndex],0);
// find first intersection of line segment with outer curve
path line = start--start+d*direction;
real[][] ints=intersections(line,outer,fuzz);
- real endtime=ints.length > 0 ? ints[0][1] : 0; // endtime is time on outer
+ assert(ints.length != 0);
+ real endtime=ints[0][1]; // endtime is time on outer
pair end = point(outer,endtime);
line = start--end;
path rline = reverse(line);
// find first intersection of rline segment with any inner curve
+ real starttime=0; // starttime is time on inners[curveIndex]
real earliestTime=1;
for(int j=0; j < inners.length; ++j) {
real[][] ints=intersections(rline,inners[j],fuzz);
diff --git a/Build/source/utils/asymptote/base/plain_pens.asy b/Build/source/utils/asymptote/base/plain_pens.asy
index 5dba51dbda4..003c79149c7 100644
--- a/Build/source/utils/asymptote/base/plain_pens.asy
+++ b/Build/source/utils/asymptote/base/plain_pens.asy
@@ -176,16 +176,18 @@ void write(file file=stdout, string s="", pen[] p)
void usetypescript(string s, string encoding="")
{
- texpreamble("\usetypescript["+s+"]["+encoding+"]");
+ string s="\usetypescript["+s+"]";
+ if(encoding != "") s +="["+encoding+"]";
+ texpreamble(s);
}
pen font(string name, string options="")
{
- // Protect context switchtobodyfont with gsave/grestore to prevent
- // misalignment if font is not found.
+ // Work around misalignment in ConTeXt switchtobodyfont if font is not found.
return fontcommand(settings.tex == "context" ?
- "\special{pdf:q}\switchtobodyfont["+name+
- (options == "" ? "" : ","+options)+"]\special{pdf:Q}%" :
+ "\switchtobodyfont["+name+
+ (options == "" ? "" : ","+options)+
+ "]\removeunwantedspaces" :
"\font\ASYfont="+name+"\ASYfont");
}
diff --git a/Build/source/utils/asymptote/base/three.asy b/Build/source/utils/asymptote/base/three.asy
index a5a78a77b2a..8e0fab6e8d0 100644
--- a/Build/source/utils/asymptote/base/three.asy
+++ b/Build/source/utils/asymptote/base/three.asy
@@ -16,8 +16,9 @@ real tubegranularity=0.003;
real dotgranularity=0.0001;
pair viewportmargin=0; // Horizontal and vertical viewport margins.
real viewportfactor=1.005; // Factor used to expand orthographic viewport.
+
real angleprecision=1e-3; // Precision for centering perspective projections.
-real anglefactor=max(1.015,1+angleprecision);
+real anglefactor=max(1.005,1+angleprecision);
// Factor used to expand perspective viewport.
string defaultembed3Doptions;
@@ -2258,9 +2259,7 @@ pair viewportmargin(projection P, real width, real height)
real ymargin=viewportmargin.y;
if(xmargin <= 0) xmargin=max(0.5*(viewportsize.x-width),0);
if(ymargin <= 0) ymargin=max(0.5*(viewportsize.y-height),0);
- viewportmargin=(xmargin,ymargin);
- if(P.infinity) return viewportmargin;
- return (max(viewportmargin.x,viewportmargin.y),viewportmargin.y);
+ return (xmargin,ymargin);
}
string embed3D(string label="", string text=label, string prefix,
@@ -2279,9 +2278,13 @@ string embed3D(string label="", string text=label, string prefix,
// Adobe Reader doesn't appear to support user-specified viewport lights.
string lightscript=light.on() && !light.viewport ? lightscript(light) : "";
- triple lambda=max3(f)-min3(f);
- pair viewportmargin=viewportmargin(P,lambda.x,lambda.y);
- real viewplanesize=(viewportfactor*lambda.y+2*viewportmargin.y)/cm;
+ real viewplanesize;
+ if(P.infinity) {
+ triple lambda=max3(f)-min3(f);
+ real margin=(viewportfactor-1.0)*lambda.y+
+ viewportmargin(P,lambda.x,lambda.y).y;
+ viewplanesize=(lambda.y+2*margin)/cm;
+ }
string name=prefix+".js";
writeJavaScript(name,lightscript+projection(P.infinity,viewplanesize),script);
@@ -2316,8 +2319,7 @@ string embed3D(string label="", string text=label, string prefix,
if(options != "") options3 += ","+options;
if(name != "") options3 += ",3Djscript="+stripdirectory(name);
- return Embed(stripdirectory(prefix),options3,width+2*viewportmargin.x,
- height+2*viewportmargin.y);
+ return Embed(stripdirectory(prefix),options3,width,height);
}
object embed(string label="", string text=label,
@@ -2400,10 +2402,10 @@ object embed(string label="", string text=label,
pair m2=pic2.min(s);
pair M2=pic2.max(s);
pair lambda=M2-m2;
- real width=lambda.x;
- real height=lambda.y;
+ pair viewportmargin=viewportmargin(P,lambda.x,lambda.y);
+ real width=ceil(lambda.x+2*viewportmargin.x);
+ real height=ceil(lambda.y+2*viewportmargin.y);
- pair viewportmargin=viewportmargin(P,width,height);
projection Q;
if(!P.absolute) {
if(scale) {
@@ -2452,10 +2454,12 @@ object embed(string label="", string text=label,
pair lasts=s;
if(P.autoadjust) {
s=r+R;
- transform3 t=shift(h*s.x,h*s.y,0);
- f=t*f;
- T=t*T;
- adjusted=true;
+ if(s != 0) {
+ transform3 t=shift(h*s.x,h*s.y,0);
+ f=t*f;
+ T=t*T;
+ adjusted=true;
+ }
}
diff=abs(s-lasts);
++i;
@@ -2525,17 +2529,16 @@ object embed(string label="", string text=label,
m=(m.x,m.y,zcenter-d);
}
- real factor=viewportfactor-1.0;
- triple margin=(factor*abs(M.x-m.x),factor*abs(M.y-m.y),0);
- if(P.infinity)
- margin += (0,viewportmargin.y,0);
- M += margin;
- m -= margin;
- if(!P.infinity && M.z >= 0) abort("camera too close");
-
+ if(P.infinity) {
+ triple margin=(viewportfactor-1.0)*(abs(M.x-m.x),
+ abs(M.y-m.y),0)+
+ viewportfactor*(0,viewportmargin.y,0);
+ M += margin;
+ m -= margin;
+ } else if(M.z >= 0) abort("camera too close");
+
shipout3(prefix,f,preview ? nativeformat() : format,
- width+2*viewportmargin.x,height+2*viewportmargin.y,
- P.infinity ? 0 : angle,m,M,
+ width,height,P.infinity ? 0 : angle,m,M,
tinv*inverse(modelview)*shift(0,0,zcenter),light.background(),
P.absolute ? (modelview*light).position : light.position,
light.diffuse,light.ambient,light.specular,
diff --git a/Build/source/utils/asymptote/base/three_surface.asy b/Build/source/utils/asymptote/base/three_surface.asy
index f1303d2e973..55060cb516d 100644
--- a/Build/source/utils/asymptote/base/three_surface.asy
+++ b/Build/source/utils/asymptote/base/three_surface.asy
@@ -892,21 +892,27 @@ real[][] intersections(path3 p, surface s, real fuzz=-1)
for(real[] s: intersections(p,s.s[i].P,fuzz))
T.push(s);
- sort(T);
-
static real fuzzFactor=10.0;
static real Fuzz=1000.0*realEpsilon;
real fuzz=max(fuzzFactor*fuzz,Fuzz)*abs(max(s)-min(s));
// Remove intrapatch duplicate points.
for(int i=0; i < T.length; ++i) {
+ triple v=point(p,T[i][0]);
for(int j=i+1; j < T.length;) {
- if(abs(point(p,i)-point(p,j)) < fuzz)
+ if(abs(v-point(p,T[j][0])) < fuzz)
T.delete(j);
else ++j;
}
}
- return T;
+ return sort(T);
+}
+
+// return an array containing all intersection points of path p and surface s.
+triple[] intersectionpoints(path3 p, patch s, real fuzz=-1)
+{
+ real[][] t=intersections(p,s,fuzz);
+ return sequence(new triple(int i) {return point(p,t[i][0]);},t.length);
}
// return an array containing all intersection points of path p and surface s.