int comps() {
if (a < 0) {
real x=sqrt(-a/3);
return y2(x) < 0 ? 2 : 1;
}
return 1;
}
void locus(picture pic=currentpicture, real m, real M, int n=100,
pen p=currentpen) {
path flip(path p, bool close) {
path pp=reverse(yscale(-1)*p)..p;
return close ? pp..cycle : pp;
}
path section(real m, real M, int n) {
guide g;
real width=(M-m)/n;
for(int i=0; i <= n; ++i) {
real x=m+width*i;
real yy=y2(x);
if (yy > 0)
g=g..(x,sqrt(yy));
}
return g;
}
if (comps() == 1) {
draw(pic,flip(section(m,M,n),false),p);
}
else {
real x=lowx(); // The minimum on x^3+ax+b
if (m < x)
draw(pic,flip(section(m,min(x,M),n),true),p);
if (x < M)
draw(pic,flip(section(max(x,m),M,n),false),p);
}
}