vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
533 stars 89 forks source link

Bug: unitsize() does not work to set unitsize of other pictures #446

Closed user202729 closed 2 weeks ago

user202729 commented 2 months ago
unitsize(1cm);
draw(scale(3)*unitcircle); // radius 3cm. for reference

picture p;
unitsize(p, 5cm); // try unsuccessfully to set unitsize of picture p
picture backup=currentpicture;
currentpicture=p;
unitsize(p, 5cm);
unitsize(5cm);

draw(unitcircle);
currentpicture=backup;
add(p);

Expected behavior: the last draw(unitcircle) draws one with radius 5cm in the final image.

Actual behavior: that circle is drawn with radius 1.

johncbowman commented 2 weeks ago

You forgot to fit picture p to a fixed sized frame before adding it to currentpicture (that will freeze it's scaling, instead of using the scaling of currentpicture). Here's a minimal example:

unitsize(1cm);
draw(scale(3)*unitcircle,red); // radius 3cm. for reference

picture p;
unitsize(p,5cm);

draw(p,unitcircle);
add(p.fit());
user202729 commented 1 week ago

In retrospect this looks like the same issue as https://github.com/vectorgraphics/asymptote/issues/450 .