Added more label positioning arguments to Distance.draw().
authorW. Trevor King <wking@drexel.edu>
Tue, 4 Aug 2009 19:20:18 +0000 (15:20 -0400)
committerW. Trevor King <wking@drexel.edu>
Thu, 17 Sep 2009 16:48:46 +0000 (12:48 -0400)
asymptote/Mechanics.asy

index 907eac7d8314eb800df25a0ba4995522b74fa976..3eeb86a597abb276b60d46068b19237525d43ac4 100644 (file)
@@ -132,12 +132,16 @@ struct Distance {
     this.L = L;
   }
   
-  void draw(picture pic=currentpicture, bool rotateLabel=true) {
+  void draw(picture pic=currentpicture, bool rotateLabel=true,
+           real labelangle=90, real labeloffset=-1) {
     picture picF;
-    picture picL;
-    label(picL, L);
-    pair pLabelSize = 1.2 * (max(picL)-min(picL));
     pair pDiff = pTo - pFrom;
+    if (labeloffset == -1) {
+      picture picL;
+      label(picL, L);
+      pair pLabelSize = 1.2 * (max(picL)-min(picL));
+      labeloffset = pLabelSize.y/2;
+    }
     path p = (0,0)--pDiff;
     pair label_rotate=pDiff;
     if (rotateLabel == false)
@@ -146,7 +150,7 @@ struct Distance {
     label(pic = picF,
          L = rotate(degrees(label_rotate)) * L,
          position =  pDiff/2
-           + unit(rotate(90)*pDiff) * pLabelSize.y / 2);
+           + unit(rotate(labelangle)*pDiff) * labeloffset);
     //label(pic=picF, L = rotate(degrees(label_rotate)) format("%g", pDiff/scale), position = TODO);
     add(pic, picF, pFrom+offset*unit(rotate(-90)*pDiff));
   }