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

Feature suggestion: Remove `add(picture dest, picture src, pair position)` variant as it's dangerous #450

Closed user202729 closed 2 weeks ago

user202729 commented 2 months ago

... because it automatically interprets 1 user coordinate in src to be 1pt, which does not make much sense.

There is already add(picture dest, frame src, pair position) variant. The user could explicitly set unitsize(1pt) then call picture.fit() on it, which is not very difficult. Or even better, use frame data type from the start.

This is backwards incompatible, however.

charlesstaats commented 2 months ago

This could explain some very weird results I got years ago when I was trying to imitate the tikz spy library in asymptote. Either way, this at least sounds like a good reason to deprecate the function. (I doubt it would ever be deleted, but using it could case a warning to be printed out.)

johncbowman commented 2 weeks ago

We need a functionality like this since some functions have only been implemented for pictures (which are more general than frames).

But we could replace it with a version that behaves the same as currently if src has no size (or unitsize) specification, which is really the intended use case elsewhere in the plain_*.asy files. Otherwise if src has a size (or unitsize) specification, we could perhaps accept the backwards incompatibility (which likely has been rarely used; ignoring a specified size isn't an expected behaviour, as you point out):

// Fit the picture src and add it about the point position to picture dest.
void add(picture dest, picture src, pair position, bool group=true,
         filltype filltype=NoFill, bool above=true)
{
  add(dest,src.fit(),position,group,filltype,true);
  //  add(dest,src.fit(identity()),position,group,filltype,above);
}
charlesstaats commented 2 weeks ago

If the main use case is in other plain_*.asy files... Should we consider making this function private?

johncbowman commented 2 weeks ago

This function is useful whenever the user wants to add a fixed-size object at a certain location. See for example this function in plain_picture.asy:

void fill(pair origin, picture pic=currentpicture, path[] g, pen p=currentpen)
{
  picture opic;
  fill(opic,g,p);
  add(pic,opic,origin);
}