Simplify Surface labeling to respect Label attributes in Mechanics.asy.
authorW. Trevor King <wking@drexel.edu>
Wed, 11 Apr 2012 20:59:48 +0000 (16:59 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 11 Apr 2012 21:08:46 +0000 (17:08 -0400)
asymptote/Mechanics-test.asy
asymptote/Mechanics.asy

index 97aa31d3c72903b8d587998c2ccba3f602915821..69ec1b037521cdb25f026fac38012e2e3226dd30 100644 (file)
@@ -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));
index 9eacce6e6261ba570bc171642de16233329b0d21..3aa7bcf1949b6e60ab02f6df70543de562121ecb 100644 (file)
@@ -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;
   }
 }