From 2d9d2ca80ee289aec7a9c9e812c81f36693c56a8 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 11 Apr 2012 16:59:48 -0400 Subject: [PATCH] Simplify Surface labeling to respect Label attributes in Mechanics.asy. --- asymptote/Mechanics-test.asy | 3 ++- asymptote/Mechanics.asy | 34 ++++++++++++++++------------------ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/asymptote/Mechanics-test.asy b/asymptote/Mechanics-test.asy index 97aa31d..69ec1b0 100644 --- a/asymptote/Mechanics-test.asy +++ b/asymptote/Mechanics-test.asy @@ -89,7 +89,8 @@ s.draw(); p.draw(drawVertical=true); -Surface s = Surface(pFrom=(0,-7u), pTo=(3.5u, -7u), L="Table"); +Surface s = Surface(pFrom=(0,-7u), pTo=(3.5u, -7u), + L=Label("Table", align=Center, embed=Shift)); s.draw(); Vector v1 = Vector((-2u, -7u), Label("$v_1$", align=E, position=EndPoint)); diff --git a/asymptote/Mechanics.asy b/asymptote/Mechanics.asy index 9eacce6..3aa7bcf 100644 --- a/asymptote/Mechanics.asy +++ b/asymptote/Mechanics.asy @@ -448,7 +448,7 @@ struct Surface { pen outline; pen filla; pen fillb; - Label L; + Label label; void operator init(pair pFrom=(0,0), pair pTo=(5mm,0), real thickness=5mm, pen outline=currentpen, pen filla=rgb(.5,.5,.5), pen fillb=rgb(.7,.7,.7), Label L="") { this.pFrom = pFrom; @@ -457,27 +457,25 @@ struct Surface { this.outline = outline; this.filla = filla; this.fillb = fillb; - this.L = L; + this.label = L; } - void draw(picture pic=currentpicture, bool rotateLabel=true) { - picture picF; - picture picL; - label(picL, L); - pair pLabelSize = 1.2 * (max(picL)-min(picL)); + void draw(picture pic=currentpicture) { pair pDiff = pTo - pFrom; pair pDepth = rotate(-90)*unit(pDiff)*thickness; - path p = (0,0) -- pDiff -- (pDiff+pDepth) -- pDepth -- cycle; - pair label_rotate=pDiff; - if (rotateLabel == false) - label_rotate=(1,0); - axialshade(pic=picF, g=p, pena=filla, a=(0,0), penb=fillb, - b=pDepth); - draw(picF, p, outline); - label(pic = picF, - L = rotate(degrees(label_rotate)) * L, - position = (pDiff+pDepth)/2); - add(pic, picF, pFrom); + path p = (0, 0) -- pDiff -- (pDiff + pDepth) -- pDepth -- cycle; + p = shift(this.pFrom) * p; + axialshade( + pic=pic, g=p, pena=filla, a=this.pFrom, + penb=fillb, b=this.pFrom+pDepth); + draw(pic, p, outline); + embed e = this.label.embed; + if (this.label.embed == Rotate) { + this.label.embed = Rotate(this.pFrom - this.pTo); + } + label(pic=pic, L=this.label, + g=(this.pFrom+pDepth/2) -- (this.pTo+pDepth/2)); + this.label.embed = e; } } -- 2.26.2