access version;
if(version.VERSION != VERSION) {
warning("version","using possibly incompatible version "+
version.VERSION+" of plain.asy"+'\n');
nowarn("version");
}
include plain_strings;
include plain_pens;
include plain_paths;
include plain_filldraw;
include plain_margins;
include plain_picture;
include plain_Label;
include plain_arcs;
include plain_boxes;
include plain_shipout;
include plain_markers;
include plain_arrows;
include plain_debugger;
// A restore thunk is a function, that when called, restores the graphics state
// to what it was when the restore thunk was created.
using restoreThunk=void();
using saveFunction=restoreThunk();
saveFunction[] saveFunctions={};
// When save is called, this will be redefined to do the corresponding restore.
void restore()
{
warning("nomatchingsave","restore called with no matching save");
}
restoreThunk buildRestoreThunk()
{
// Call the save functions in reverse order, storing their restore thunks.
restoreThunk[] thunks={};
for(int i=saveFunctions.length-1; i >= 0; --i)
thunks.push(saveFunctions[i]());
return new void() {
// Call the restore thunks in an order matching the saves.
for(int i=thunks.length-1; i >= 0; --i)
thunks[i]();
};
}
// Add the default save function.
addSaveFunction(new restoreThunk() {
pen defaultpen=defaultpen();
pen p=currentpen;
picture pic=currentpicture.copy();
restoreThunk r=restore;
return new void() {
defaultpen(defaultpen);
currentpen=p;
currentpicture=pic;
currentpicture.uptodate=false;
restore=r;
};
});
// Save the current state, so that restore will put things back in that state.
restoreThunk save()
{
return restore=buildRestoreThunk();
}
void restoredefaults()
{
warning("nomatchingsavedefaults",
"restoredefaults called with no matching savedefaults");
}
// Save the current state, so that restore will put things back in that state.
restoreThunk savedefaults()
{
return restoredefaults=buildRestoreDefaults();
}
// Return the sequence n,...,m
int[] sequence(int n, int m)
{
return n+sequence(m-n+1);
}
// Return the sequence n,...,m skipping by skip
int[] sequence(int n, int m, int skip)
{
return n+skip*sequence((m-n)#skip+1);
}
int[] reverse(int n) {return sequence(new int(int x){return n-1-x;},n);}
bool[] reverse(bool[] a) {return a[reverse(a.length)];}
int[] reverse(int[] a) {return a[reverse(a.length)];}
real[] reverse(real[] a) {return a[reverse(a.length)];}
pair[] reverse(pair[] a) {return a[reverse(a.length)];}
triple[] reverse(triple[] a) {return a[reverse(a.length)];}
string[] reverse(string[] a) {return a[reverse(a.length)];}
// Return a uniform partition dividing [a,b] into n subintervals.
real[] uniform(real a, real b, int n)
{
if(n <= 0) return new real[];
return a+sequence(n+1)/n*(b-a);
}
// This function is deprecated: use
// from mapArray(Src=T1, Dst=T2) access map;
void mapArray(string From, string To)
{
eval(mapArrayString(From,To),true);
}
// Evaluate user command line option.
void usersetting()
{
eval(settings.user,true);
}